blob: a877f470a0c2f2fb9ffa21eb9e421468ef269fb7 [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 {
49 objFiles android.Paths
50 tidyFiles android.Paths
51 kytheFiles android.Paths
52}
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 {
76 Whole_static_libs proptools.Configurable[[]string]
77 // list of modules that should be statically linked into this module.
78 Static_libs proptools.Configurable[[]string]
79 // list of modules that should be dynamically linked into this module.
80 Shared_libs proptools.Configurable[[]string]
81 // list of modules that should only provide headers for this module.
82 Header_libs proptools.Configurable[[]string]
83
84 BinaryDecoratorInfo *BinaryDecoratorInfo
85 LibraryDecoratorInfo *LibraryDecoratorInfo
86 TestBinaryInfo *TestBinaryInfo
87 BenchmarkDecoratorInfo *BenchmarkDecoratorInfo
88 ObjectLinkerInfo *ObjectLinkerInfo
89}
90
91type BinaryDecoratorInfo struct{}
92type LibraryDecoratorInfo struct {
93 Export_include_dirs proptools.Configurable[[]string]
94}
95type TestBinaryInfo struct {
96 Gtest bool
97}
98type BenchmarkDecoratorInfo struct{}
99type ObjectLinkerInfo struct{}
100
Yu Liub1bfa9d2024-12-05 18:57:51 +0000101// Common info about the cc module.
102type CcInfo struct {
Yu Liu323d77a2024-12-16 23:13:57 +0000103 HasStubsVariants bool
104 IsPrebuilt bool
105 CmakeSnapshotSupported bool
106 CompilerInfo *CompilerInfo
107 LinkerInfo *LinkerInfo
Yu Liub1bfa9d2024-12-05 18:57:51 +0000108}
109
110var CcInfoProvider = blueprint.NewProvider[CcInfo]()
111
Yu Liu986d98c2024-11-12 00:28:11 +0000112type LinkableInfo struct {
113 // StaticExecutable returns true if this is a binary module with "static_executable: true".
114 StaticExecutable bool
115}
116
117var LinkableInfoKey = blueprint.NewProvider[LinkableInfo]()
118
Colin Cross463a90e2015-06-17 14:20:06 -0700119func init() {
Paul Duffin036e7002019-12-19 19:16:28 +0000120 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -0700121
Inseob Kim3b244062023-07-11 13:31:36 +0900122 pctx.Import("android/soong/android")
Paul Duffin036e7002019-12-19 19:16:28 +0000123 pctx.Import("android/soong/cc/config")
124}
125
126func RegisterCCBuildComponents(ctx android.RegistrationContext) {
127 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
128
129 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossac57a6c2024-06-26 13:09:53 -0700130 ctx.Transition("sdk", &sdkTransitionMutator{})
Colin Cross8a962802024-10-09 15:29:27 -0700131 ctx.BottomUp("llndk", llndkMutator)
Colin Cross767819f2024-05-22 14:22:34 -0700132 ctx.Transition("link", &linkageTransitionMutator{})
Colin Crossadd04a82024-05-22 09:57:59 -0700133 ctx.Transition("version", &versionTransitionMutator{})
Colin Cross8a962802024-10-09 15:29:27 -0700134 ctx.BottomUp("begin", BeginMutator)
Colin Cross1e676be2016-10-12 14:38:15 -0700135 })
Colin Cross16b23492016-01-06 14:41:07 -0800136
Paul Duffin036e7002019-12-19 19:16:28 +0000137 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Liz Kammer75db9312021-07-07 16:41:50 -0400138 for _, san := range Sanitizers {
139 san.registerMutators(ctx)
140 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800141
Colin Cross8a962802024-10-09 15:29:27 -0700142 ctx.BottomUp("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
143 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -0800144
Colin Cross597bad62024-10-08 15:10:55 -0700145 ctx.Transition("fuzz", &fuzzTransitionMutator{})
Cory Barkera1da26f2022-06-07 20:12:06 +0000146
Colin Crossf5f4ad32024-01-19 15:41:48 -0800147 ctx.Transition("coverage", &coverageTransitionMutator{})
Stephen Craneba090d12017-05-09 15:44:35 -0700148
Colin Crossd38feb02024-01-23 16:38:06 -0800149 ctx.Transition("afdo", &afdoTransitionMutator{})
Yi Kongeb8efc92021-12-09 18:06:29 +0800150
Colin Cross33e0c812024-01-23 16:36:07 -0800151 ctx.Transition("orderfile", &orderfileTransitionMutator{})
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000152
Colin Cross6ac83a82024-01-23 11:23:10 -0800153 ctx.Transition("lto", &ltoTransitionMutator{})
Jooyung Hana70f0672019-01-18 15:20:43 +0900154
Colin Cross8a962802024-10-09 15:29:27 -0700155 ctx.BottomUp("check_linktype", checkLinkTypeMutator)
156 ctx.BottomUp("double_loadable", checkDoubleLoadableLibraries)
Colin Cross1e676be2016-10-12 14:38:15 -0700157 })
Colin Crossb98c8b02016-07-29 13:44:28 -0700158
Colin Cross91ae5ec2024-10-01 14:03:40 -0700159 ctx.PostApexMutators(func(ctx android.RegisterMutatorsContext) {
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800160 // sabi mutator needs to be run after apex mutator finishes.
Colin Cross91ae5ec2024-10-01 14:03:40 -0700161 ctx.Transition("sabi", &sabiTransitionMutator{})
Yo Chiang8aa4e3f2020-11-19 16:30:49 +0800162 })
163
LaMont Jones0c10e4d2023-05-16 00:58:37 +0000164 ctx.RegisterParallelSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -0700165}
166
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500167// Deps is a struct containing module names of dependencies, separated by the kind of dependency.
168// Mutators should use `AddVariationDependencies` or its sibling methods to add actual dependency
169// edges to these modules.
170// This object is constructed in DepsMutator, by calling to various module delegates to set
171// relevant fields. For example, `module.compiler.compilerDeps()` may append type-specific
172// dependencies.
173// This is then consumed by the same DepsMutator, which will call `ctx.AddVariationDependencies()`
174// (or its sibling methods) to set real dependencies on the given modules.
Colin Crossca860ac2016-01-04 14:34:37 -0800175type Deps struct {
176 SharedLibs, LateSharedLibs []string
177 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -0800178 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +0800179 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700180
Colin Cross3e5e7782022-06-17 22:17:05 +0000181 // UnexportedStaticLibs are static libraries that are also passed to -Wl,--exclude-libs= to
182 // prevent automatically exporting symbols.
183 UnexportedStaticLibs []string
184
Chris Parsons79d66a52020-06-05 17:26:16 -0400185 // Used for data dependencies adjacent to tests
186 DataLibs []string
Colin Crossc8caa062021-09-24 16:50:14 -0700187 DataBins []string
Chris Parsons79d66a52020-06-05 17:26:16 -0400188
Yo Chiang219968c2020-09-22 18:45:04 +0800189 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
190 SystemSharedLibs []string
191
Vinh Tran367d89d2023-04-28 11:21:25 -0400192 // Used by DepMutator to pass aidl_library modules to aidl compiler
193 AidlLibs []string
194
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500195 // If true, statically link the unwinder into native libraries/binaries.
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800196 StaticUnwinderIfLegacy bool
197
Colin Cross5950f382016-12-13 12:50:57 -0800198 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700199
Colin Cross81413472016-04-11 14:37:39 -0700200 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700201
Cole Faust65cb40a2024-10-21 15:41:42 -0700202 GeneratedSources []string
203 GeneratedHeaders []string
204 DeviceFirstGeneratedHeaders []string
205 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700206
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700207 ReexportGeneratedHeaders []string
208
Colin Crossc465efd2021-06-11 18:00:04 -0700209 CrtBegin, CrtEnd []string
Dan Willemsena0790e32018-10-12 00:24:23 -0700210
211 // Used for host bionic
Colin Cross9cfe6112021-06-11 18:02:22 -0700212 DynamicLinker string
Jiyong Parke3867542020-12-03 17:28:25 +0900213
214 // List of libs that need to be excluded for APEX variant
215 ExcludeLibsForApex []string
Jooyung Han9ffbe832023-11-28 22:31:35 +0900216 // List of libs that need to be excluded for non-APEX variant
217 ExcludeLibsForNonApex []string
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800218
219 // LLNDK headers for the ABI checker to check LLNDK implementation library.
220 // An LLNDK implementation is the core variant. LLNDK header libs are reexported by the vendor variant.
Colin Cross1e954b62024-09-13 13:50:00 -0700221 // The core variant cannot depend on the vendor variant because of the order of imageTransitionMutator.Split().
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800222 // Instead, the LLNDK implementation depends on the LLNDK header libs.
223 LlndkHeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700224}
225
Ivan Lozano0a468a42024-05-13 21:03:34 -0400226// A struct which to collect flags for rlib dependencies
227type RustRlibDep struct {
228 LibPath android.Path // path to the rlib
229 LinkDirs []string // flags required for dependency (e.g. -L flags)
230 CrateName string // crateNames associated with rlibDeps
231}
232
233func EqRustRlibDeps(a RustRlibDep, b RustRlibDep) bool {
234 return a.LibPath == b.LibPath
235}
236
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500237// PathDeps is a struct containing file paths to dependencies of a module.
238// It's constructed in depsToPath() by traversing the direct dependencies of the current module.
239// It's used to construct flags for various build statements (such as for compiling and linking).
240// It is then passed to module decorator functions responsible for registering build statements
241// (such as `module.compiler.compile()`).`
Colin Crossca860ac2016-01-04 14:34:37 -0800242type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700243 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900244 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700245 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900246 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700247 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700248 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400249 // Paths and crateNames for RustStaticLib dependencies
250 RustRlibDeps []RustRlibDep
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700251
Colin Cross0de8a1e2020-09-18 14:15:30 -0700252 // Transitive static library dependencies of static libraries for use in ordering.
Colin Crossa14fb6a2024-10-23 16:57:06 -0700253 TranstiveStaticLibrariesForOrdering depset.DepSet[android.Path]
Colin Cross0de8a1e2020-09-18 14:15:30 -0700254
Colin Cross26c34ed2016-09-30 17:10:16 -0700255 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100256 Objs Objects
257 // Paths to .o files in dependencies that provide them. Note that these lists
258 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800259 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700260 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700261
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100262 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
263 // the libs from all whole_static_lib dependencies.
264 WholeStaticLibsFromPrebuilts android.Paths
265
Colin Cross26c34ed2016-09-30 17:10:16 -0700266 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700267 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900268 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700269
Inseob Kimd110f872019-12-06 13:15:38 +0900270 Flags []string
Colin Cross3e5e7782022-06-17 22:17:05 +0000271 LdFlags []string
Inseob Kimd110f872019-12-06 13:15:38 +0900272 IncludeDirs android.Paths
273 SystemIncludeDirs android.Paths
274 ReexportedDirs android.Paths
275 ReexportedSystemDirs android.Paths
276 ReexportedFlags []string
277 ReexportedGeneratedHeaders android.Paths
278 ReexportedDeps android.Paths
Ivan Lozano0a468a42024-05-13 21:03:34 -0400279 ReexportedRustRlibDeps []RustRlibDep
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700280
Colin Cross26c34ed2016-09-30 17:10:16 -0700281 // Paths to crt*.o files
Colin Crossc465efd2021-06-11 18:00:04 -0700282 CrtBegin, CrtEnd android.Paths
Dan Willemsena0790e32018-10-12 00:24:23 -0700283
Dan Willemsena0790e32018-10-12 00:24:23 -0700284 // Path to the dynamic linker binary
285 DynamicLinker android.OptionalPath
Dan Willemsen47450072021-10-19 20:24:49 -0700286
287 // For Darwin builds, the path to the second architecture's output that should
288 // be combined with this architectures's output into a FAT MachO file.
289 DarwinSecondArchOutput android.OptionalPath
Vinh Tran367d89d2023-04-28 11:21:25 -0400290
291 // Paths to direct srcs and transitive include dirs from direct aidl_library deps
292 AidlLibraryInfos []aidl_library.AidlLibraryInfo
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800293
294 // LLNDK headers for the ABI checker to check LLNDK implementation library.
295 LlndkIncludeDirs android.Paths
296 LlndkSystemIncludeDirs android.Paths
Colin Crossb614cd42024-10-11 12:52:21 -0700297
298 directImplementationDeps android.Paths
299 transitiveImplementationDeps []depset.DepSet[android.Path]
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700300}
301
Colin Cross4af21ed2019-11-04 09:37:55 -0800302// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
303// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
304// command line so they can be overridden by the local module flags).
305type LocalOrGlobalFlags struct {
306 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700307 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800308 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700309 CFlags []string // Flags that apply to C and C++ source files
310 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
311 ConlyFlags []string // Flags that apply to C source files
312 CppFlags []string // Flags that apply to C++ source files
313 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700314 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800315}
316
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500317// Flags contains various types of command line flags (and settings) for use in building build
318// statements related to C++.
Colin Cross4af21ed2019-11-04 09:37:55 -0800319type Flags struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500320 // Local flags (which individual modules are responsible for). These may override global flags.
321 Local LocalOrGlobalFlags
322 // Global flags (which build system or toolchain is responsible for).
Luis Useche342fa6b2024-04-01 19:33:18 -0700323 Global LocalOrGlobalFlags
324 NoOverrideFlags []string // Flags applied to the end of list of flags so they are not overridden
Colin Cross4af21ed2019-11-04 09:37:55 -0800325
326 aidlFlags []string // Flags that apply to aidl source files
327 rsFlags []string // Flags that apply to renderscript source files
328 libFlags []string // Flags to add libraries early to the link order
329 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
330 TidyFlags []string // Flags that apply to clang-tidy
331 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700332
Colin Crossc3199482017-03-30 15:03:04 -0700333 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800334 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700335 SystemIncludeFlags []string
336
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800337 Toolchain config.Toolchain
338 Tidy bool // True if ninja .tidy rules should be generated.
339 NeedTidyFiles bool // True if module link should depend on .tidy files
340 GcovCoverage bool // True if coverage files should be generated.
341 SAbiDump bool // True if header abi dumps should be generated.
342 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
kellyhungd62ea302024-05-19 21:16:07 +0800343 ClangVerify bool // If true, append cflags "-Xclang -verify" and append "&& touch $out" to the clang command line.
Colin Crossca860ac2016-01-04 14:34:37 -0800344
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500345 // The instruction set required for clang ("arm" or "thumb").
Colin Crossca860ac2016-01-04 14:34:37 -0800346 RequiredInstructionSet string
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500347 // The target-device system path to the dynamic linker.
348 DynamicLinker string
Colin Cross16b23492016-01-06 14:41:07 -0800349
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700350 CFlagsDeps android.Paths // Files depended on by compiler flags
351 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800352
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500353 // True if .s files should be processed with the c preprocessor.
Dan Willemsen98ab3112019-08-27 21:20:40 -0700354 AssemblerWithCpp bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800355
Colin Cross19878da2019-03-28 14:45:07 -0700356 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700357 protoC bool // Whether to use C instead of C++
358 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700359
360 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200361 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700362}
363
Colin Crossca860ac2016-01-04 14:34:37 -0800364// Properties used to compile all C or C++ modules
365type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700366 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800367 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700368
Yi Kong5786f5c2024-05-28 02:22:34 +0900369 // Aggresively trade performance for smaller binary size.
370 // This should only be used for on-device binaries that are rarely executed and not
371 // performance critical.
372 Optimize_for_size *bool `android:"arch_variant"`
373
Jiyong Parkb35a8192020-08-10 15:59:36 +0900374 // The API level that this module is built against. The APIs of this API level will be
375 // visible at build time, but use of any APIs newer than min_sdk_version will render the
376 // module unloadable on older devices. In the future it will be possible to weakly-link new
377 // APIs, making the behavior match Java: such modules will load on older devices, but
378 // calling new APIs on devices that do not support them will result in a crash.
379 //
380 // This property has the same behavior as sdk_version does for Java modules. For those
381 // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion
382 // does for Java code.
383 //
384 // In addition, setting this property causes two variants to be built, one for the platform
385 // and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800386 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700387
Jiyong Parkb35a8192020-08-10 15:59:36 +0900388 // Minimum OS API level supported by this C or C++ module. This property becomes the value
389 // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK,
390 // this property is also used to ensure that the min_sdk_version of the containing module is
391 // not older (i.e. less) than this module's min_sdk_version. When not set, this property
392 // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks
393 // min_sdk_version of the containing APEX. When the module
394 // is not built for an APEX, "apex_inherit" defaults to sdk_version.
Jooyung Han379660c2020-04-21 15:24:00 +0900395 Min_sdk_version *string
396
Colin Crossc511bc52020-04-07 16:50:32 +0000397 // If true, always create an sdk variant and don't create a platform variant.
398 Sdk_variant_only *bool
399
Colin Cross4297f402024-11-20 15:20:09 -0800400 AndroidMkSharedLibs []string `blueprint:"mutated"`
401 AndroidMkStaticLibs []string `blueprint:"mutated"`
402 AndroidMkRlibs []string `blueprint:"mutated"`
403 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
404 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
405 AndroidMkHeaderLibs []string `blueprint:"mutated"`
406 HideFromMake bool `blueprint:"mutated"`
407 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700408
Yo Chiang219968c2020-09-22 18:45:04 +0800409 // Set by DepsMutator.
410 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
411
Kiyoung Kimb5fdb2e2024-01-03 14:24:34 +0900412 // The name of the image this module is built for
413 ImageVariation string `blueprint:"mutated"`
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200414
415 // The VNDK version this module is built against. If empty, the module is not
416 // build against the VNDK.
417 VndkVersion string `blueprint:"mutated"`
418
419 // Suffix for the name of Android.mk entries generated by this module
420 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800421
422 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
423 // file
Inseob Kim37e0bb02024-04-29 15:54:44 +0900424 Logtags []string `android:"path"`
Jiyong Parkf9332f12018-02-01 00:54:12 +0900425
Yifan Hong39143a92020-10-26 12:43:12 -0700426 // Make this module available when building for ramdisk.
427 // On device without a dedicated recovery partition, the module is only
428 // available after switching root into
429 // /first_stage_ramdisk. To expose the module before switching root, install
430 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800431 Ramdisk_available *bool
432
Yifan Hong39143a92020-10-26 12:43:12 -0700433 // Make this module available when building for vendor ramdisk.
434 // On device without a dedicated recovery partition, the module is only
435 // available after switching root into
436 // /first_stage_ramdisk. To expose the module before switching root, install
437 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700438 Vendor_ramdisk_available *bool
439
Jiyong Parkf9332f12018-02-01 00:54:12 +0900440 // Make this module available when building for recovery
441 Recovery_available *bool
442
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200443 // Used by imageMutator, set by ImageMutatorBegin()
Jihoon Kang47e91842024-06-19 00:51:16 +0000444 VendorVariantNeeded bool `blueprint:"mutated"`
445 ProductVariantNeeded bool `blueprint:"mutated"`
Lukacs T. Berki2f5c3402021-06-15 11:27:56 +0200446 CoreVariantNeeded bool `blueprint:"mutated"`
447 RamdiskVariantNeeded bool `blueprint:"mutated"`
448 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
449 RecoveryVariantNeeded bool `blueprint:"mutated"`
450
451 // A list of variations for the "image" mutator of the form
452 //<image name> '.' <version char>, for example, 'vendor.S'
453 ExtraVersionedImageVariations []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900454
455 // Allows this module to use non-APEX version of libraries. Useful
456 // for building binaries that are started before APEXes are activated.
457 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900458
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000459 // Allows this module to be included in CMake release snapshots to be built outside of Android
460 // build system and source tree.
461 Cmake_snapshot_supported *bool
462
Colin Cross1bc94122021-10-28 13:25:54 -0700463 Installable *bool `android:"arch_variant"`
Colin Crossc511bc52020-04-07 16:50:32 +0000464
465 // Set by factories of module types that can only be referenced from variants compiled against
466 // the SDK.
467 AlwaysSdk bool `blueprint:"mutated"`
468
469 // Variant is an SDK variant created by sdkMutator
470 IsSdkVariant bool `blueprint:"mutated"`
471 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
472 // variant to have a ".sdk" suffix.
473 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700474
Yi-Yo Chiangc7e044f2021-06-18 19:44:24 +0800475 Target struct {
476 Platform struct {
477 // List of modules required by the core variant.
478 Required []string `android:"arch_variant"`
479
480 // List of modules not required by the core variant.
481 Exclude_required []string `android:"arch_variant"`
482 } `android:"arch_variant"`
483
484 Recovery struct {
485 // List of modules required by the recovery variant.
486 Required []string `android:"arch_variant"`
487
488 // List of modules not required by the recovery variant.
489 Exclude_required []string `android:"arch_variant"`
490 } `android:"arch_variant"`
491 } `android:"arch_variant"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700492}
493
494type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900495 // whether this module should be allowed to be directly depended by other
496 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900497 // If set to true, two variants will be built separately, one like
498 // normal, and the other limited to the set of libraries and headers
499 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700500 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900501 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700502 // so it shouldn't have any unversioned runtime dependencies, or
503 // make assumptions about the system that may not be true in the
504 // future.
505 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900506 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900507 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900508 // The modules with vndk: {enabled: true} must define 'vendor_available'
Justin Yun0b1db6d2021-01-08 15:22:34 +0900509 // to 'true'.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900510 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700511 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
512 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900513
Justin Yunebcf0c52021-01-08 18:00:19 +0900514 // This is the same as the "vendor_available" except that the install path
515 // of the vendor variant is /odm or /vendor/odm.
516 // By replacing "vendor_available: true" with "odm_available: true", the
517 // module will install its vendor variant to the /odm partition or /vendor/odm.
518 // As the modules with "odm_available: true" still create the vendor variants,
519 // they can link to the other vendor modules as the vendor_available modules do.
520 // Also, the vendor modules can link to odm_available modules.
521 //
522 // It may not be used for VNDK modules.
523 Odm_available *bool
524
Justin Yun63e9ec72020-10-29 16:49:43 +0900525 // whether this module should be allowed to be directly depended by other
526 // modules with `product_specific: true` or `product_available: true`.
527 // If set to true, an additional product variant will be built separately
528 // that is limited to the set of libraries and headers that are exposed to
529 // /product modules.
530 //
531 // The product variant may be used with a different (newer) /system,
532 // so it shouldn't have any unversioned runtime dependencies, or
533 // make assumptions about the system that may not be true in the
534 // future.
535 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900536 // If set to false, this module becomes inaccessible from /product modules.
537 //
538 // Different from the 'vendor_available' property, the modules with
539 // vndk: {enabled: true} don't have to define 'product_available'. The VNDK
540 // library without 'product_available' may not be depended on by any other
541 // modules that has product variants including the product available VNDKs.
Justin Yun63e9ec72020-10-29 16:49:43 +0900542 //
543 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
544 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
545 Product_available *bool
546
Jiyong Park5fb8c102018-04-09 12:03:06 +0900547 // whether this module is capable of being loaded with other instance
548 // (possibly an older version) of the same module in the same process.
549 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
550 // can be double loaded in a vendor process if the library is also a
551 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
552 // explicitly marked as `double_loadable: true` by the owner, or the dependency
553 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
554 Double_loadable *bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800555
556 // IsLLNDK is set to true for the vendor variant of a cc_library module that has LLNDK stubs.
557 IsLLNDK bool `blueprint:"mutated"`
558
Colin Cross5271fea2021-04-27 13:06:04 -0700559 // IsVendorPublicLibrary is set for the core and product variants of a library that has
560 // vendor_public_library stubs.
561 IsVendorPublicLibrary bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800562}
563
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500564// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
565// to understanding details about the type of the current module.
566// For example, one might call these functions to determine whether the current module is a static
567// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800568type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800569 static() bool
570 staticBinary() bool
Colin Cross6a730042024-12-05 13:53:43 -0800571 staticLibrary() bool
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700572 testBinary() bool
Yi Kong56fc1b62022-09-06 16:24:00 +0800573 testLibrary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900574 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900575 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900576 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700577 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900578 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700579 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800580 sdkVersion() string
Jiyong Parkb35a8192020-08-10 15:59:36 +0900581 minSdkVersion() string
582 isSdkVariant() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700583 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700584 isNdk(config android.Config) bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800585 IsLlndk() bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800586 isImplementationForLLNDKPublic() bool
Colin Cross5271fea2021-04-27 13:06:04 -0700587 IsVendorPublicLibrary() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900588 inProduct() bool
589 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800590 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700591 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900592 inRecovery() bool
Kiyoung Kimaa394802024-01-08 12:55:45 +0900593 InVendorOrProduct() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700594 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700595 baseModuleName() string
Colin Cross3513fb12024-01-24 14:44:47 -0800596 isAfdoCompile(ctx ModuleContext) bool
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000597 isOrderfileCompile() bool
Yi Kongc702ebd2022-08-19 16:02:45 +0800598 isCfi() bool
Yi Konged79fa32023-06-04 17:15:42 +0900599 isFuzzer() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800600 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800601 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800602 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700603 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700604 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900605 bootstrap() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700606 nativeCoverage() bool
Colin Cross95b07f22020-12-16 11:06:50 -0800607 isPreventInstall() bool
Cindy Zhou5d5cfc12021-01-09 08:25:22 -0800608 isCfiAssemblySupportEnabled() bool
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800609 getSharedFlags() *SharedFlags
Colin Cross4a9e6ec2023-12-18 15:29:41 -0800610 notInPlatform() bool
Yi Kong5786f5c2024-05-28 02:22:34 +0900611 optimizeForSize() bool
Yu Liu76d94462024-10-31 23:32:36 +0000612 getOrCreateMakeVarsInfo() *CcMakeVarsInfo
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800613}
614
615type SharedFlags struct {
616 numSharedFlags int
617 flagsMap map[string]string
Colin Crossca860ac2016-01-04 14:34:37 -0800618}
619
620type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700621 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800622 ModuleContextIntf
623}
624
625type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700626 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800627 ModuleContextIntf
628}
629
Colin Cross37047f12016-12-13 17:06:13 -0800630type DepsContext interface {
631 android.BottomUpMutatorContext
632 ModuleContextIntf
633}
634
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500635// feature represents additional (optional) steps to building cc-related modules, such as invocation
636// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800637type feature interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800638 flags(ctx ModuleContext, flags Flags) Flags
639 props() []interface{}
640}
641
Joe Onorato37f900c2023-07-18 16:58:16 -0700642// Information returned from Generator about the source code it's generating
643type GeneratedSource struct {
644 IncludeDirs android.Paths
645 Sources android.Paths
646 Headers android.Paths
647 ReexportedDirs android.Paths
648}
649
650// generator allows injection of generated code
651type Generator interface {
652 GeneratorProps() []interface{}
653 GeneratorInit(ctx BaseModuleContext)
654 GeneratorDeps(ctx DepsContext, deps Deps) Deps
655 GeneratorFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
656 GeneratorSources(ctx ModuleContext) GeneratedSource
657 GeneratorBuildActions(ctx ModuleContext, flags Flags, deps PathDeps)
658}
659
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500660// compiler is the interface for a compiler helper object. Different module decorators may implement
Liz Kammer718eb272022-01-07 10:53:37 -0500661// this helper differently.
Colin Crossca860ac2016-01-04 14:34:37 -0800662type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700663 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800664 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800665 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700666 compilerProps() []interface{}
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000667 baseCompilerProps() BaseCompilerProperties
Colin Cross42742b82016-08-01 13:20:05 -0700668
Colin Cross76fada02016-07-27 10:31:13 -0700669 appendCflags([]string)
670 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700671 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800672}
673
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500674// linker is the interface for a linker decorator object. Individual module types can provide
675// their own implementation for this decorator, and thus specify custom logic regarding build
676// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800677type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700678 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800679 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700680 linkerFlags(ctx ModuleContext, flags Flags) Flags
681 linkerProps() []interface{}
Hao Chen1c8ea5b2023-10-20 23:03:45 +0000682 baseLinkerProps() BaseLinkerProperties
Ivan Lozanobd721262018-11-27 14:33:03 -0800683 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700684
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700685 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700686 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900687 unstrippedOutputFilePath() android.Path
Wei Li5f5d2712023-12-11 15:40:29 -0800688 strippedAllOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700689
690 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900691 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000692
693 // Get the deps that have been explicitly specified in the properties.
Cole Fauste8a87832024-09-11 11:35:46 -0700694 linkerSpecifiedDeps(ctx android.ConfigurableEvaluatorContext, module *Module, specifiedDeps specifiedDeps) specifiedDeps
Colin Cross4a9e6ec2023-12-18 15:29:41 -0800695
696 moduleInfoJSON(ctx ModuleContext, moduleInfoJSON *android.ModuleInfoJSON)
Paul Duffin13f02712020-03-06 12:30:43 +0000697}
698
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500699// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000700type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500701 sharedLibs []string
702 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
703 // libc, libm, etc.)
Colin Cross6b8f4252021-07-22 11:39:44 -0700704 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800705}
706
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500707// installer is the interface for an installer helper object. This helper is responsible for
708// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800709type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700710 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700711 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000712 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800713 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700714 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700715 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900716 relativeInstallPath() string
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +0000717 makeUninstallable(mod *Module)
Inseob Kim800d1142021-06-14 12:03:51 +0900718 installInRoot() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800719}
720
Inseob Kima1888ce2022-10-04 14:42:02 +0900721type overridable interface {
722 overriddenModules() []string
723}
724
Colin Cross6e511a92020-07-27 21:26:48 -0700725type libraryDependencyKind int
726
727const (
728 headerLibraryDependency = iota
729 sharedLibraryDependency
730 staticLibraryDependency
Ivan Lozano0a468a42024-05-13 21:03:34 -0400731 rlibLibraryDependency
Colin Cross6e511a92020-07-27 21:26:48 -0700732)
733
734func (k libraryDependencyKind) String() string {
735 switch k {
736 case headerLibraryDependency:
737 return "headerLibraryDependency"
738 case sharedLibraryDependency:
739 return "sharedLibraryDependency"
740 case staticLibraryDependency:
741 return "staticLibraryDependency"
Ivan Lozano0a468a42024-05-13 21:03:34 -0400742 case rlibLibraryDependency:
743 return "rlibLibraryDependency"
Colin Cross6e511a92020-07-27 21:26:48 -0700744 default:
745 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
746 }
747}
748
749type libraryDependencyOrder int
750
751const (
752 earlyLibraryDependency = -1
753 normalLibraryDependency = 0
754 lateLibraryDependency = 1
755)
756
757func (o libraryDependencyOrder) String() string {
758 switch o {
759 case earlyLibraryDependency:
760 return "earlyLibraryDependency"
761 case normalLibraryDependency:
762 return "normalLibraryDependency"
763 case lateLibraryDependency:
764 return "lateLibraryDependency"
765 default:
766 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
767 }
768}
769
770// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
771// tags that have a set of predefined tag objects that are reused for each dependency, a
772// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
773// That means that comparing a libraryDependencyTag for equality will only be equal if all
774// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
775// then check individual metadata fields instead.
776type libraryDependencyTag struct {
777 blueprint.BaseDependencyTag
778
779 // These are exported so that fmt.Printf("%#v") can call their String methods.
780 Kind libraryDependencyKind
781 Order libraryDependencyOrder
782
783 wholeStatic bool
784
785 reexportFlags bool
786 explicitlyVersioned bool
787 dataLib bool
788 ndk bool
789
790 staticUnwinder bool
791
792 makeSuffix string
Jiyong Parke3867542020-12-03 17:28:25 +0900793
Cindy Zhou18417cb2020-12-10 07:12:38 -0800794 // Whether or not this dependency should skip the apex dependency check
795 skipApexAllowedDependenciesCheck bool
796
Jiyong Parke3867542020-12-03 17:28:25 +0900797 // Whether or not this dependency has to be followed for the apex variants
798 excludeInApex bool
Jooyung Han9ffbe832023-11-28 22:31:35 +0900799 // Whether or not this dependency has to be followed for the non-apex variants
800 excludeInNonApex bool
Colin Cross3e5e7782022-06-17 22:17:05 +0000801
802 // If true, don't automatically export symbols from the static library into a shared library.
803 unexportedSymbols bool
Colin Cross6e511a92020-07-27 21:26:48 -0700804}
805
806// header returns true if the libraryDependencyTag is tagging a header lib dependency.
807func (d libraryDependencyTag) header() bool {
808 return d.Kind == headerLibraryDependency
809}
810
811// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
812func (d libraryDependencyTag) shared() bool {
813 return d.Kind == sharedLibraryDependency
814}
815
816// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
817func (d libraryDependencyTag) static() bool {
818 return d.Kind == staticLibraryDependency
819}
820
Colin Cross65cb3142021-12-10 23:05:02 +0000821func (d libraryDependencyTag) LicenseAnnotations() []android.LicenseAnnotation {
822 if d.shared() {
823 return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency}
824 }
825 return nil
826}
827
828var _ android.LicenseAnnotationsDependencyTag = libraryDependencyTag{}
829
Colin Crosse9fe2942020-11-10 18:12:15 -0800830// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
831// binaries or other shared libraries are installed as dependencies.
832func (d libraryDependencyTag) InstallDepNeeded() bool {
833 return d.shared()
834}
835
836var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
837
Yu Liu67a28422024-03-05 00:36:31 +0000838func (d libraryDependencyTag) PropagateAconfigValidation() bool {
839 return d.static()
840}
841
842var _ android.PropagateAconfigValidationDependencyTag = libraryDependencyTag{}
843
Colin Crosse9fe2942020-11-10 18:12:15 -0800844// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700845// libraryDependencyTag. Each tag object is created globally and reused for multiple
846// dependencies (although since the object contains no references, assigning a tag to a
847// variable and modifying it will not modify the original). Users can compare the tag
848// returned by ctx.OtherModuleDependencyTag against the global original
849type dependencyTag struct {
850 blueprint.BaseDependencyTag
851 name string
852}
853
Colin Crosse9fe2942020-11-10 18:12:15 -0800854// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
855// libraryDependencyTag, but where the dependency needs to be installed when the parent is
856// installed.
857type installDependencyTag struct {
858 blueprint.BaseDependencyTag
859 android.InstallAlwaysNeededDependencyTag
860 name string
861}
862
Colin Crossc99deeb2016-04-11 15:06:20 -0700863var (
Colin Cross6e511a92020-07-27 21:26:48 -0700864 genSourceDepTag = dependencyTag{name: "gen source"}
865 genHeaderDepTag = dependencyTag{name: "gen header"}
866 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
867 objDepTag = dependencyTag{name: "obj"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900868 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700869 reuseObjTag = dependencyTag{name: "reuse objects"}
870 staticVariantTag = dependencyTag{name: "static variant"}
871 vndkExtDepTag = dependencyTag{name: "vndk extends"}
872 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crossc8caa062021-09-24 16:50:14 -0700873 dataBinDepTag = dependencyTag{name: "data bin"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800874 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700875 stubImplDepTag = dependencyTag{name: "stub_impl"}
Muhammad Haseeb Ahmad7e744052022-03-25 22:50:53 +0000876 JniFuzzLibTag = dependencyTag{name: "jni_fuzz_lib_tag"}
Vinh Tran44cb78c2023-03-09 22:07:19 -0500877 FdoProfileTag = dependencyTag{name: "fdo_profile"}
Vinh Tran367d89d2023-04-28 11:21:25 -0400878 aidlLibraryTag = dependencyTag{name: "aidl_library"}
Hsin-Yi Chen715142a2024-03-27 16:31:16 +0800879 llndkHeaderLibTag = dependencyTag{name: "llndk_header_lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700880)
881
Roland Levillainf89cd092019-07-29 16:22:59 +0100882func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700883 ccLibDepTag, ok := depTag.(libraryDependencyTag)
884 return ok && ccLibDepTag.shared()
885}
886
887func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
888 ccLibDepTag, ok := depTag.(libraryDependencyTag)
889 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100890}
891
Zach Johnson3df4e632020-11-06 11:56:27 -0800892func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
893 ccLibDepTag, ok := depTag.(libraryDependencyTag)
894 return ok && ccLibDepTag.header()
895}
896
Roland Levillainf89cd092019-07-29 16:22:59 +0100897func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800898 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100899}
900
Colin Crossca860ac2016-01-04 14:34:37 -0800901// Module contains the properties and members used by all C/C++ module types, and implements
902// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500903// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
904// interface.
905//
906// To define a C/C++ related module, construct a new Module object and point its delegates to
907// type-specific structs. These delegates will be invoked to register module-specific build
908// statements which may be unique to the module type. For example, module.compiler.compile() should
909// be defined so as to register build statements which are responsible for compiling the module.
910//
911// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
912// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
913// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
914// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800915type Module struct {
hamzehc0a671f2021-07-22 12:05:08 -0700916 fuzz.FuzzModule
hamzeh41ad8812021-07-07 14:00:07 -0700917
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700918 VendorProperties VendorProperties
hamzeh41ad8812021-07-07 14:00:07 -0700919 Properties BaseProperties
Ronald Braunsteina115e262024-04-09 18:07:38 -0700920 sourceProperties android.SourceProperties
Colin Crossfa138792015-04-24 17:31:52 -0700921
Colin Crossca860ac2016-01-04 14:34:37 -0800922 // initialize before calling Init
Yu Liu76d94462024-10-31 23:32:36 +0000923 hod android.HostOrDeviceSupported
924 multilib android.Multilib
925 testModule bool
926 incremental bool
Colin Crossc472d572015-03-17 15:06:21 -0700927
Paul Duffina0843f62019-12-13 19:50:38 +0000928 // Allowable SdkMemberTypes of this module type.
929 sdkMemberTypes []android.SdkMemberType
930
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500931 // decorator delegates, initialize before calling Init
932 // these may contain module-specific implementations, and effectively allow for custom
933 // type-specific logic. These members may reference different objects or the same object.
934 // Functions of these decorators will be invoked to initialize and register type-specific
935 // build statements.
Colin Cross8ff10582023-12-07 13:10:56 -0800936 generators []Generator
937 compiler compiler
938 linker linker
939 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500940
Spandan Dase12d2522023-09-12 21:42:31 +0000941 features []feature
942 stl *stl
943 sanitize *sanitize
944 coverage *coverage
945 fuzzer *fuzzer
946 sabi *sabi
Spandan Dase12d2522023-09-12 21:42:31 +0000947 lto *lto
948 afdo *afdo
Sharjeel Khanc6a93d82023-07-18 21:01:11 +0000949 orderfile *orderfile
Colin Cross16b23492016-01-06 14:41:07 -0800950
Colin Cross31076b32020-10-23 17:22:06 -0700951 library libraryInterface
952
Colin Cross635c3b02016-05-18 15:37:25 -0700953 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800954
Colin Crossb98c8b02016-07-29 13:44:28 -0700955 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700956
Yu Liue70976d2024-10-15 20:45:35 +0000957 subAndroidMkOnce map[subAndroidMkProviderInfoProducer]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800958
959 // Flags used to compile this module
960 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700961
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -0800962 // Shared flags among build rules of this module
963 sharedFlags SharedFlags
964
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800965 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700966 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900967
968 makeLinkType string
Jooyung Han75568392020-03-20 04:29:24 +0900969
970 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700971 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700972
973 hideApexVariantFromMake bool
Yu Liueae7b362023-11-16 17:05:47 -0800974
Inseob Kim37e0bb02024-04-29 15:54:44 +0900975 logtagsPaths android.Paths
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400976
977 WholeRustStaticlib bool
Cole Faust96a692b2024-08-08 14:47:51 -0700978
979 hasAidl bool
980 hasLex bool
981 hasProto bool
982 hasRenderscript bool
983 hasSysprop bool
984 hasWinMsg bool
985 hasYacc bool
Yu Liu76d94462024-10-31 23:32:36 +0000986
987 makeVarsInfo *CcMakeVarsInfo
Colin Crossc472d572015-03-17 15:06:21 -0700988}
989
Yu Liu76d94462024-10-31 23:32:36 +0000990func (c *Module) IncrementalSupported() bool {
991 return c.incremental
992}
993
994var _ blueprint.Incremental = (*Module)(nil)
995
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +0200996func (c *Module) AddJSONData(d *map[string]interface{}) {
997 c.AndroidModuleBase().AddJSONData(d)
998 (*d)["Cc"] = map[string]interface{}{
999 "SdkVersion": c.SdkVersion(),
1000 "MinSdkVersion": c.MinSdkVersion(),
1001 "VndkVersion": c.VndkVersion(),
1002 "ProductSpecific": c.ProductSpecific(),
1003 "SocSpecific": c.SocSpecific(),
1004 "DeviceSpecific": c.DeviceSpecific(),
1005 "InProduct": c.InProduct(),
1006 "InVendor": c.InVendor(),
1007 "InRamdisk": c.InRamdisk(),
1008 "InVendorRamdisk": c.InVendorRamdisk(),
1009 "InRecovery": c.InRecovery(),
1010 "VendorAvailable": c.VendorAvailable(),
1011 "ProductAvailable": c.ProductAvailable(),
1012 "RamdiskAvailable": c.RamdiskAvailable(),
1013 "VendorRamdiskAvailable": c.VendorRamdiskAvailable(),
1014 "RecoveryAvailable": c.RecoveryAvailable(),
1015 "OdmAvailable": c.OdmAvailable(),
1016 "InstallInData": c.InstallInData(),
1017 "InstallInRamdisk": c.InstallInRamdisk(),
1018 "InstallInSanitizerDir": c.InstallInSanitizerDir(),
1019 "InstallInVendorRamdisk": c.InstallInVendorRamdisk(),
1020 "InstallInRecovery": c.InstallInRecovery(),
1021 "InstallInRoot": c.InstallInRoot(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001022 "IsLlndk": c.IsLlndk(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001023 "IsVendorPublicLibrary": c.IsVendorPublicLibrary(),
1024 "ApexSdkVersion": c.apexSdkVersion,
Cole Faust96a692b2024-08-08 14:47:51 -07001025 "AidlSrcs": c.hasAidl,
1026 "LexSrcs": c.hasLex,
1027 "ProtoSrcs": c.hasProto,
1028 "RenderscriptSrcs": c.hasRenderscript,
1029 "SyspropSrcs": c.hasSysprop,
1030 "WinMsgSrcs": c.hasWinMsg,
1031 "YaccSrsc": c.hasYacc,
1032 "OnlyCSrcs": !(c.hasAidl || c.hasLex || c.hasProto || c.hasRenderscript || c.hasSysprop || c.hasWinMsg || c.hasYacc),
Yi Kong5786f5c2024-05-28 02:22:34 +09001033 "OptimizeForSize": c.OptimizeForSize(),
Lukacs T. Berkid18d8ca2021-06-25 09:11:22 +02001034 }
1035}
1036
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001037func (c *Module) SetPreventInstall() {
1038 c.Properties.PreventInstall = true
1039}
1040
1041func (c *Module) SetHideFromMake() {
1042 c.Properties.HideFromMake = true
1043}
1044
Ivan Lozanod7586b62021-04-01 09:49:36 -04001045func (c *Module) HiddenFromMake() bool {
1046 return c.Properties.HideFromMake
1047}
1048
Cole Fauste8a87832024-09-11 11:35:46 -07001049func (c *Module) RequiredModuleNames(ctx android.ConfigurableEvaluatorContext) []string {
Cole Faust43ddd082024-06-17 12:32:40 -07001050 required := android.CopyOf(c.ModuleBase.RequiredModuleNames(ctx))
Yi-Yo Chiangc7e044f2021-06-18 19:44:24 +08001051 if c.ImageVariation().Variation == android.CoreVariation {
1052 required = append(required, c.Properties.Target.Platform.Required...)
1053 required = removeListFromList(required, c.Properties.Target.Platform.Exclude_required)
1054 } else if c.InRecovery() {
1055 required = append(required, c.Properties.Target.Recovery.Required...)
1056 required = removeListFromList(required, c.Properties.Target.Recovery.Exclude_required)
1057 }
1058 return android.FirstUniqueStrings(required)
1059}
1060
Ivan Lozano52767be2019-10-18 14:49:46 -07001061func (c *Module) Toc() android.OptionalPath {
1062 if c.linker != nil {
1063 if library, ok := c.linker.(libraryInterface); ok {
1064 return library.toc()
1065 }
1066 }
1067 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
1068}
1069
1070func (c *Module) ApiLevel() string {
1071 if c.linker != nil {
1072 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -07001073 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -07001074 }
1075 }
1076 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
1077}
1078
1079func (c *Module) Static() bool {
1080 if c.linker != nil {
1081 if library, ok := c.linker.(libraryInterface); ok {
1082 return library.static()
1083 }
1084 }
1085 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
1086}
1087
1088func (c *Module) Shared() bool {
1089 if c.linker != nil {
1090 if library, ok := c.linker.(libraryInterface); ok {
1091 return library.shared()
1092 }
1093 }
Lukacs T. Berki6c716762022-06-13 20:50:39 +02001094
Ivan Lozano52767be2019-10-18 14:49:46 -07001095 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
1096}
1097
1098func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +00001099 if c.stl != nil {
1100 return c.stl.Properties.SelectedStl
1101 }
1102 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -07001103}
1104
Ivan Lozano52767be2019-10-18 14:49:46 -07001105func (c *Module) StubDecorator() bool {
1106 if _, ok := c.linker.(*stubDecorator); ok {
1107 return true
1108 }
1109 return false
1110}
1111
Yi Kong5786f5c2024-05-28 02:22:34 +09001112func (c *Module) OptimizeForSize() bool {
1113 return Bool(c.Properties.Optimize_for_size)
1114}
1115
Ivan Lozano52767be2019-10-18 14:49:46 -07001116func (c *Module) SdkVersion() string {
1117 return String(c.Properties.Sdk_version)
1118}
1119
Artur Satayev480e25b2020-04-27 18:53:18 +01001120func (c *Module) MinSdkVersion() string {
1121 return String(c.Properties.Min_sdk_version)
1122}
1123
Jiyong Park5df7bd32021-08-25 16:18:46 +09001124func (c *Module) isCrt() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07001125 if linker, ok := c.linker.(*objectLinker); ok {
1126 return linker.isCrt()
1127 }
1128 return false
1129}
1130
Jiyong Park5df7bd32021-08-25 16:18:46 +09001131func (c *Module) SplitPerApiLevel() bool {
1132 return c.canUseSdk() && c.isCrt()
1133}
1134
Colin Crossc511bc52020-04-07 16:50:32 +00001135func (c *Module) AlwaysSdk() bool {
1136 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
1137}
1138
Ivan Lozano183a3212019-10-18 14:18:45 -07001139func (c *Module) CcLibrary() bool {
1140 if c.linker != nil {
1141 if _, ok := c.linker.(*libraryDecorator); ok {
1142 return true
1143 }
Colin Crossd48fe732020-09-23 20:37:24 -07001144 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
1145 return true
1146 }
Ivan Lozano183a3212019-10-18 14:18:45 -07001147 }
1148 return false
1149}
1150
1151func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001152 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001153 return true
1154 }
1155 return false
1156}
1157
Ivan Lozanoadd122a2023-07-13 11:01:41 -04001158func (c *Module) RlibStd() bool {
1159 panic(fmt.Errorf("RlibStd called on non-Rust module: %q", c.BaseModuleName()))
1160}
1161
Ivan Lozano61c02cc2023-06-09 14:06:44 -04001162func (c *Module) RustLibraryInterface() bool {
1163 return false
1164}
1165
Ivan Lozano0a468a42024-05-13 21:03:34 -04001166func (c *Module) CrateName() string {
1167 panic(fmt.Errorf("CrateName called on non-Rust module: %q", c.BaseModuleName()))
1168}
1169
1170func (c *Module) ExportedCrateLinkDirs() []string {
1171 panic(fmt.Errorf("ExportedCrateLinkDirs called on non-Rust module: %q", c.BaseModuleName()))
1172}
1173
Ivan Lozano0f9963e2023-02-06 13:31:02 -05001174func (c *Module) IsFuzzModule() bool {
1175 if _, ok := c.compiler.(*fuzzBinary); ok {
1176 return true
1177 }
1178 return false
1179}
1180
1181func (c *Module) FuzzModuleStruct() fuzz.FuzzModule {
1182 return c.FuzzModule
1183}
1184
1185func (c *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule {
1186 if fuzzer, ok := c.compiler.(*fuzzBinary); ok {
1187 return fuzzer.fuzzPackagedModule
1188 }
1189 panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", c.BaseModuleName()))
1190}
1191
Hamzeh Zawawy38917492023-04-05 22:08:46 +00001192func (c *Module) FuzzSharedLibraries() android.RuleBuilderInstalls {
Ivan Lozano0f9963e2023-02-06 13:31:02 -05001193 if fuzzer, ok := c.compiler.(*fuzzBinary); ok {
1194 return fuzzer.sharedLibraries
1195 }
1196 panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", c.BaseModuleName()))
1197}
1198
Ivan Lozano2b262972019-11-21 12:30:50 -08001199func (c *Module) NonCcVariants() bool {
1200 return false
1201}
1202
Ivan Lozano183a3212019-10-18 14:18:45 -07001203func (c *Module) SetStatic() {
1204 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001205 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001206 library.setStatic()
1207 return
1208 }
1209 }
1210 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
1211}
1212
1213func (c *Module) SetShared() {
1214 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001215 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001216 library.setShared()
1217 return
1218 }
1219 }
1220 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
1221}
1222
1223func (c *Module) BuildStaticVariant() bool {
1224 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001225 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001226 return library.buildStatic()
1227 }
1228 }
1229 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
1230}
1231
1232func (c *Module) BuildSharedVariant() bool {
1233 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -07001234 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -07001235 return library.buildShared()
1236 }
1237 }
1238 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
1239}
1240
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04001241func (c *Module) BuildRlibVariant() bool {
1242 // cc modules can never build rlib variants
1243 return false
1244}
1245
Ivan Lozano183a3212019-10-18 14:18:45 -07001246func (c *Module) Module() android.Module {
1247 return c
1248}
1249
Jiyong Parkc20eee32018-09-05 22:36:17 +09001250func (c *Module) OutputFile() android.OptionalPath {
1251 return c.outputFile
1252}
1253
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04001254func (c *Module) CoverageFiles() android.Paths {
1255 if c.linker != nil {
1256 if library, ok := c.linker.(libraryInterface); ok {
1257 return library.objs().coverageFiles
1258 }
1259 }
1260 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
1261}
1262
Ivan Lozano183a3212019-10-18 14:18:45 -07001263var _ LinkableInterface = (*Module)(nil)
1264
Jiyong Park719b4462019-01-13 00:39:51 +09001265func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +09001266 if c.linker != nil {
1267 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +09001268 }
1269 return nil
1270}
1271
Jiyong Parkee9a98d2019-08-09 14:44:36 +09001272func (c *Module) CoverageOutputFile() android.OptionalPath {
1273 if c.linker != nil {
1274 return c.linker.coverageOutputFilePath()
1275 }
1276 return android.OptionalPath{}
1277}
1278
Jiyong Parkb7c24df2019-02-01 12:03:59 +09001279func (c *Module) RelativeInstallPath() string {
1280 if c.installer != nil {
1281 return c.installer.relativeInstallPath()
1282 }
1283 return ""
1284}
1285
Jooyung Han344d5432019-08-23 11:17:39 +09001286func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001287 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +09001288}
1289
Colin Cross36242852017-06-23 15:06:31 -07001290func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -07001291 c.AddProperties(&c.Properties, &c.VendorProperties)
Joe Onorato37f900c2023-07-18 16:58:16 -07001292 for _, generator := range c.generators {
1293 c.AddProperties(generator.GeneratorProps()...)
1294 }
Colin Crossca860ac2016-01-04 14:34:37 -08001295 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -07001296 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001297 }
1298 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -07001299 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001300 }
1301 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -07001302 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001303 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001304 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -07001305 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -07001306 }
Colin Cross16b23492016-01-06 14:41:07 -08001307 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -07001308 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -08001309 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001310 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -07001311 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001312 }
Cory Barkera1da26f2022-06-07 20:12:06 +00001313 if c.fuzzer != nil {
1314 c.AddProperties(c.fuzzer.props()...)
1315 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001316 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -07001317 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001318 }
Stephen Craneba090d12017-05-09 15:44:35 -07001319 if c.lto != nil {
1320 c.AddProperties(c.lto.props()...)
1321 }
Yi Kongeb8efc92021-12-09 18:06:29 +08001322 if c.afdo != nil {
1323 c.AddProperties(c.afdo.props()...)
1324 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001325 if c.orderfile != nil {
1326 c.AddProperties(c.orderfile.props()...)
1327 }
Colin Crossca860ac2016-01-04 14:34:37 -08001328 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -07001329 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001330 }
Ronald Braunsteina115e262024-04-09 18:07:38 -07001331 // Allow test-only on libraries that are not cc_test_library
1332 if c.library != nil && !c.testLibrary() {
1333 c.AddProperties(&c.sourceProperties)
1334 }
Colin Crossc472d572015-03-17 15:06:21 -07001335
Colin Cross36242852017-06-23 15:06:31 -07001336 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +09001337 android.InitApexModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001338 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001339
Colin Cross36242852017-06-23 15:06:31 -07001340 return c
Colin Crossc472d572015-03-17 15:06:21 -07001341}
1342
Yi-Yo Chiang1080f0c2022-11-22 18:24:14 +08001343// UseVndk() returns true if this module is built against VNDK.
1344// This means the vendor and product variants of a module.
Ivan Lozano52767be2019-10-18 14:49:46 -07001345func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001346 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001347}
1348
Colin Crossc511bc52020-04-07 16:50:32 +00001349func (c *Module) canUseSdk() bool {
Colin Cross94e347e2021-01-19 14:56:07 -08001350 return c.Os() == android.Android && c.Target().NativeBridge == android.NativeBridgeDisabled &&
Kiyoung Kimaa394802024-01-08 12:55:45 +09001351 !c.InVendorOrProduct() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001352}
1353
1354func (c *Module) UseSdk() bool {
1355 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001356 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001357 }
1358 return false
1359}
1360
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001361func (c *Module) isCoverageVariant() bool {
1362 return c.coverage.Properties.IsCoverageVariant
1363}
1364
Colin Cross95f1ca02020-10-29 20:47:22 -07001365func (c *Module) IsNdk(config android.Config) bool {
1366 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001367}
1368
Colin Cross127bb8b2020-12-16 16:46:01 -08001369func (c *Module) IsLlndk() bool {
1370 return c.VendorProperties.IsLLNDK
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001371}
1372
Colin Cross1f3f1302021-04-26 18:37:44 -07001373func (m *Module) NeedsLlndkVariants() bool {
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001374 lib := moduleLibraryInterface(m)
Colin Cross1f3f1302021-04-26 18:37:44 -07001375 return lib != nil && (lib.hasLLNDKStubs() || lib.hasLLNDKHeaders())
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001376}
1377
Colin Cross5271fea2021-04-27 13:06:04 -07001378func (m *Module) NeedsVendorPublicLibraryVariants() bool {
1379 lib := moduleLibraryInterface(m)
1380 return lib != nil && (lib.hasVendorPublicLibrary())
1381}
1382
1383// IsVendorPublicLibrary returns true for vendor public libraries.
1384func (c *Module) IsVendorPublicLibrary() bool {
1385 return c.VendorProperties.IsVendorPublicLibrary
1386}
1387
Ivan Lozanof1868af2022-04-12 13:08:36 -04001388func (c *Module) IsVndkPrebuiltLibrary() bool {
1389 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1390 return true
1391 }
1392 return false
1393}
1394
1395func (c *Module) SdkAndPlatformVariantVisibleToMake() bool {
1396 return c.Properties.SdkAndPlatformVariantVisibleToMake
1397}
1398
Ivan Lozanod7586b62021-04-01 09:49:36 -04001399func (c *Module) HasLlndkStubs() bool {
1400 lib := moduleLibraryInterface(c)
1401 return lib != nil && lib.hasLLNDKStubs()
1402}
1403
1404func (c *Module) StubsVersion() string {
1405 if lib, ok := c.linker.(versionedInterface); ok {
1406 return lib.stubsVersion()
1407 }
1408 panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", c.BaseModuleName()))
1409}
1410
Colin Cross127bb8b2020-12-16 16:46:01 -08001411// isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
1412// and does not set llndk.vendor_available: false.
1413func (c *Module) isImplementationForLLNDKPublic() bool {
1414 library, _ := c.library.(*libraryDecorator)
1415 return library != nil && library.hasLLNDKStubs() &&
Colin Cross0fb7fcd2021-03-02 11:00:07 -08001416 !Bool(library.Properties.Llndk.Private)
Colin Cross127bb8b2020-12-16 16:46:01 -08001417}
1418
Colin Cross3513fb12024-01-24 14:44:47 -08001419func (c *Module) isAfdoCompile(ctx ModuleContext) bool {
Yi Kong4ef54592022-02-14 20:00:10 +08001420 if afdo := c.afdo; afdo != nil {
Colin Cross3513fb12024-01-24 14:44:47 -08001421 return afdo.isAfdoCompile(ctx)
Yi Kong4ef54592022-02-14 20:00:10 +08001422 }
1423 return false
1424}
1425
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001426func (c *Module) isOrderfileCompile() bool {
1427 if orderfile := c.orderfile; orderfile != nil {
1428 return orderfile.Properties.OrderfileLoad
1429 }
1430 return false
1431}
1432
Yi Kongc702ebd2022-08-19 16:02:45 +08001433func (c *Module) isCfi() bool {
Colin Cross694fced2024-06-25 14:56:42 -07001434 return c.sanitize.isSanitizerEnabled(cfi)
Yi Kongc702ebd2022-08-19 16:02:45 +08001435}
1436
Yi Konged79fa32023-06-04 17:15:42 +09001437func (c *Module) isFuzzer() bool {
Colin Cross694fced2024-06-25 14:56:42 -07001438 return c.sanitize.isSanitizerEnabled(Fuzzer)
Yi Konged79fa32023-06-04 17:15:42 +09001439}
1440
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001441func (c *Module) isNDKStubLibrary() bool {
1442 if _, ok := c.compiler.(*stubDecorator); ok {
1443 return true
1444 }
1445 return false
1446}
1447
Ivan Lozanoc08897c2021-04-02 12:41:32 -04001448func (c *Module) SubName() string {
1449 return c.Properties.SubName
1450}
1451
Jiyong Park25fc6a92018-11-18 18:02:45 +09001452func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001453 if lib := c.library; lib != nil {
1454 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001455 }
1456 return false
1457}
1458
1459func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001460 if lib := c.library; lib != nil {
1461 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001462 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001463 return false
1464}
1465
Alan Stokes73feba32022-11-14 12:21:24 +00001466func (c *Module) IsStubsImplementationRequired() bool {
1467 if lib := c.library; lib != nil {
1468 return lib.isStubsImplementationRequired()
1469 }
1470 return false
1471}
1472
Colin Cross0477b422020-10-13 18:43:54 -07001473// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1474// the implementation. If it is an implementation library it returns its own name.
1475func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1476 name := ctx.OtherModuleName(c)
1477 if versioned, ok := c.linker.(versionedInterface); ok {
1478 name = versioned.implementationModuleName(name)
1479 }
1480 return name
1481}
1482
Martin Stjernholm2856c662020-12-02 15:03:42 +00001483// Similar to ImplementationModuleName, but uses the Make variant of the module
1484// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1485// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1486// under the premise that the prebuilt module overrides its source counterpart
1487// if it is exposed to Make).
1488func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1489 name := c.BaseModuleName()
1490 if versioned, ok := c.linker.(versionedInterface); ok {
1491 name = versioned.implementationModuleName(name)
1492 }
1493 return name
1494}
1495
Jiyong Park7d55b612021-06-11 17:22:09 +09001496func (c *Module) Bootstrap() bool {
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001497 return Bool(c.Properties.Bootstrap)
1498}
1499
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001500func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001501 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1502 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1503 return false
1504 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001505 return c.linker != nil && c.linker.nativeCoverage()
1506}
1507
Ivan Lozano3a7d0002021-03-30 12:19:36 -04001508func (c *Module) IsSnapshotPrebuilt() bool {
Ivan Lozanod1dec542021-05-26 15:33:11 -04001509 if p, ok := c.linker.(SnapshotInterface); ok {
1510 return p.IsSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001511 }
1512 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001513}
1514
Jiyong Parkf1194352019-02-25 11:05:47 +09001515func isBionic(name string) bool {
1516 switch name {
Jooyung Hanbff73352022-12-13 18:29:44 +09001517 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001518 return true
1519 }
1520 return false
1521}
1522
Martin Stjernholm279de572019-09-10 23:18:20 +01001523func InstallToBootstrap(name string, config android.Config) bool {
Florian Mayer95cd6db2023-03-23 17:48:07 -07001524 if name == "libclang_rt.hwasan" || name == "libc_hwasan" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001525 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001526 }
1527 return isBionic(name)
1528}
1529
Cindy Zhou5d5cfc12021-01-09 08:25:22 -08001530func (c *Module) isCfiAssemblySupportEnabled() bool {
1531 return c.sanitize != nil &&
1532 Bool(c.sanitize.Properties.Sanitize.Config.Cfi_assembly_support)
1533}
1534
Inseob Kim800d1142021-06-14 12:03:51 +09001535func (c *Module) InstallInRoot() bool {
1536 return c.installer != nil && c.installer.installInRoot()
1537}
1538
Colin Crossca860ac2016-01-04 14:34:37 -08001539type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001540 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001541 moduleContextImpl
1542}
1543
Colin Cross37047f12016-12-13 17:06:13 -08001544type depsContext struct {
1545 android.BottomUpMutatorContext
1546 moduleContextImpl
1547}
1548
Colin Crossca860ac2016-01-04 14:34:37 -08001549type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001550 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001551 moduleContextImpl
1552}
1553
1554type moduleContextImpl struct {
1555 mod *Module
1556 ctx BaseModuleContext
1557}
1558
Colin Crossb98c8b02016-07-29 13:44:28 -07001559func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001560 return ctx.mod.toolchain(ctx.ctx)
1561}
1562
1563func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001564 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001565}
1566
1567func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001568 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001569}
1570
Colin Cross6a730042024-12-05 13:53:43 -08001571func (ctx *moduleContextImpl) staticLibrary() bool {
1572 return ctx.mod.staticLibrary()
1573}
1574
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07001575func (ctx *moduleContextImpl) testBinary() bool {
1576 return ctx.mod.testBinary()
1577}
1578
Yi Kong56fc1b62022-09-06 16:24:00 +08001579func (ctx *moduleContextImpl) testLibrary() bool {
1580 return ctx.mod.testLibrary()
1581}
1582
Jiyong Park1d1119f2019-07-29 21:27:18 +09001583func (ctx *moduleContextImpl) header() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001584 return ctx.mod.Header()
Jiyong Park1d1119f2019-07-29 21:27:18 +09001585}
1586
Inseob Kim7f283f42020-06-01 21:53:49 +09001587func (ctx *moduleContextImpl) binary() bool {
Ivan Lozanod7586b62021-04-01 09:49:36 -04001588 return ctx.mod.Binary()
Inseob Kim7f283f42020-06-01 21:53:49 +09001589}
1590
Inseob Kim1042d292020-06-01 23:23:05 +09001591func (ctx *moduleContextImpl) object() bool {
Ivan Lozanod7586b62021-04-01 09:49:36 -04001592 return ctx.mod.Object()
Inseob Kim1042d292020-06-01 23:23:05 +09001593}
1594
Yi Kong5786f5c2024-05-28 02:22:34 +09001595func (ctx *moduleContextImpl) optimizeForSize() bool {
1596 return ctx.mod.OptimizeForSize()
1597}
1598
Jooyung Hanccce2f22020-03-07 03:45:53 +09001599func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001600 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001601}
1602
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001603func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001604 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001605}
1606
1607func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001608 if ctx.ctx.Device() {
Justin Yun732aa6a2018-03-23 17:43:47 +09001609 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001610 }
1611 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001612}
1613
Jiyong Parkb35a8192020-08-10 15:59:36 +09001614func (ctx *moduleContextImpl) minSdkVersion() string {
1615 ver := ctx.mod.MinSdkVersion()
1616 if ver == "apex_inherit" && !ctx.isForPlatform() {
1617 ver = ctx.apexSdkVersion().String()
1618 }
1619 if ver == "apex_inherit" || ver == "" {
1620 ver = ctx.sdkVersion()
1621 }
Yi-Yo Chiang88960aa2024-01-19 15:02:29 +08001622
1623 if ctx.ctx.Device() {
Jooyung Hanaa2d3f52024-11-09 02:41:06 +00001624 // When building for vendor/product, use the latest _stable_ API as "current".
1625 // This is passed to clang/aidl compilers so that compiled/generated code works
1626 // with the system.
1627 if (ctx.inVendor() || ctx.inProduct()) && (ver == "" || ver == "current") {
1628 ver = ctx.ctx.Config().PlatformSdkVersion().String()
Yi-Yo Chiang88960aa2024-01-19 15:02:29 +08001629 }
1630 }
1631
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09001632 // For crt objects, the meaning of min_sdk_version is very different from other types of
1633 // module. For them, min_sdk_version defines the oldest version that the build system will
1634 // create versioned variants for. For example, if min_sdk_version is 16, then sdk variant of
1635 // the crt object has local variants of 16, 17, ..., up to the latest version. sdk_version
1636 // and min_sdk_version properties of the variants are set to the corresponding version
Jiyong Park5df7bd32021-08-25 16:18:46 +09001637 // numbers. However, the non-sdk variant (for apex or platform) of the crt object is left
1638 // untouched. min_sdk_version: 16 doesn't actually mean that the non-sdk variant has to
1639 // support such an old version. The version is set to the later version in case when the
1640 // non-sdk variant is for the platform, or the min_sdk_version of the containing APEX if
1641 // it's for an APEX.
1642 if ctx.mod.isCrt() && !ctx.isSdkVariant() {
1643 if ctx.isForPlatform() {
1644 ver = strconv.Itoa(android.FutureApiLevelInt)
1645 } else { // for apex
1646 ver = ctx.apexSdkVersion().String()
1647 if ver == "" { // in case when min_sdk_version was not set by the APEX
1648 ver = ctx.sdkVersion()
1649 }
1650 }
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09001651 }
1652
Jiyong Parkb35a8192020-08-10 15:59:36 +09001653 // Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
1654 sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
1655 minSdkVersionInt, err2 := strconv.Atoi(ver)
1656 if err == nil && err2 == nil {
1657 if sdkVersionInt < minSdkVersionInt {
1658 return strconv.Itoa(sdkVersionInt)
1659 }
1660 }
1661 return ver
1662}
1663
1664func (ctx *moduleContextImpl) isSdkVariant() bool {
1665 return ctx.mod.IsSdkVariant()
1666}
1667
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001668func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001669 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001670}
Justin Yun8effde42017-06-23 19:24:43 +09001671
Kiyoung Kimaa394802024-01-08 12:55:45 +09001672func (ctx *moduleContextImpl) InVendorOrProduct() bool {
1673 return ctx.mod.InVendorOrProduct()
1674}
1675
Colin Cross95f1ca02020-10-29 20:47:22 -07001676func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1677 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001678}
1679
Colin Cross127bb8b2020-12-16 16:46:01 -08001680func (ctx *moduleContextImpl) IsLlndk() bool {
1681 return ctx.mod.IsLlndk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001682}
1683
Colin Cross127bb8b2020-12-16 16:46:01 -08001684func (ctx *moduleContextImpl) isImplementationForLLNDKPublic() bool {
1685 return ctx.mod.isImplementationForLLNDKPublic()
1686}
1687
Colin Cross3513fb12024-01-24 14:44:47 -08001688func (ctx *moduleContextImpl) isAfdoCompile(mctx ModuleContext) bool {
1689 return ctx.mod.isAfdoCompile(mctx)
Yi Kong4ef54592022-02-14 20:00:10 +08001690}
1691
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001692func (ctx *moduleContextImpl) isOrderfileCompile() bool {
1693 return ctx.mod.isOrderfileCompile()
1694}
1695
Yi Kongc702ebd2022-08-19 16:02:45 +08001696func (ctx *moduleContextImpl) isCfi() bool {
1697 return ctx.mod.isCfi()
1698}
1699
Yi Konged79fa32023-06-04 17:15:42 +09001700func (ctx *moduleContextImpl) isFuzzer() bool {
1701 return ctx.mod.isFuzzer()
1702}
1703
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001704func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1705 return ctx.mod.isNDKStubLibrary()
1706}
1707
Colin Cross5271fea2021-04-27 13:06:04 -07001708func (ctx *moduleContextImpl) IsVendorPublicLibrary() bool {
1709 return ctx.mod.IsVendorPublicLibrary()
1710}
1711
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001712func (ctx *moduleContextImpl) selectedStl() string {
1713 if stl := ctx.mod.stl; stl != nil {
1714 return stl.Properties.SelectedStl
1715 }
1716 return ""
1717}
1718
Ivan Lozanobd721262018-11-27 14:33:03 -08001719func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1720 return ctx.mod.linker.useClangLld(actx)
1721}
1722
Colin Crossce75d2c2016-10-06 16:12:58 -07001723func (ctx *moduleContextImpl) baseModuleName() string {
Spandan Das2b6dfb52024-01-19 00:22:22 +00001724 return ctx.mod.BaseModuleName()
Colin Crossce75d2c2016-10-06 16:12:58 -07001725}
1726
Logan Chiene274fc92019-12-03 11:18:32 -08001727func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Crossff694a82023-12-13 15:54:49 -08001728 apexInfo, _ := android.ModuleProvider(ctx.ctx, android.ApexInfoProvider)
1729 return apexInfo.IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001730}
1731
Colin Crosse07f2312020-08-13 11:24:56 -07001732func (ctx *moduleContextImpl) apexVariationName() string {
Colin Crossff694a82023-12-13 15:54:49 -08001733 apexInfo, _ := android.ModuleProvider(ctx.ctx, android.ApexInfoProvider)
1734 return apexInfo.ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001735}
1736
Dan Albertc8060532020-07-22 22:32:17 -07001737func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001738 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001739}
1740
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001741func (ctx *moduleContextImpl) bootstrap() bool {
Jiyong Park7d55b612021-06-11 17:22:09 +09001742 return ctx.mod.Bootstrap()
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001743}
1744
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001745func (ctx *moduleContextImpl) nativeCoverage() bool {
1746 return ctx.mod.nativeCoverage()
1747}
1748
Colin Cross95b07f22020-12-16 11:06:50 -08001749func (ctx *moduleContextImpl) isPreventInstall() bool {
1750 return ctx.mod.Properties.PreventInstall
1751}
1752
Chih-Hung Hsieh7540a782022-01-08 19:56:09 -08001753func (ctx *moduleContextImpl) getSharedFlags() *SharedFlags {
1754 shared := &ctx.mod.sharedFlags
1755 if shared.flagsMap == nil {
1756 shared.numSharedFlags = 0
1757 shared.flagsMap = make(map[string]string)
1758 }
1759 return shared
1760}
1761
Cindy Zhou5d5cfc12021-01-09 08:25:22 -08001762func (ctx *moduleContextImpl) isCfiAssemblySupportEnabled() bool {
1763 return ctx.mod.isCfiAssemblySupportEnabled()
1764}
1765
Colin Cross4a9e6ec2023-12-18 15:29:41 -08001766func (ctx *moduleContextImpl) notInPlatform() bool {
1767 return ctx.mod.NotInPlatform()
1768}
1769
Yu Liu76d94462024-10-31 23:32:36 +00001770func (ctx *moduleContextImpl) getOrCreateMakeVarsInfo() *CcMakeVarsInfo {
1771 if ctx.mod.makeVarsInfo == nil {
1772 ctx.mod.makeVarsInfo = &CcMakeVarsInfo{}
1773 }
1774 return ctx.mod.makeVarsInfo
1775}
1776
Colin Cross635c3b02016-05-18 15:37:25 -07001777func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001778 return &Module{
1779 hod: hod,
1780 multilib: multilib,
1781 }
1782}
1783
Colin Cross635c3b02016-05-18 15:37:25 -07001784func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001785 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001786 module.features = []feature{
1787 &tidyFeature{},
1788 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001789 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001790 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001791 module.coverage = &coverage{}
Cory Barkera1da26f2022-06-07 20:12:06 +00001792 module.fuzzer = &fuzzer{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001793 module.sabi = &sabi{}
Stephen Craneba090d12017-05-09 15:44:35 -07001794 module.lto = &lto{}
Yi Kongeb8efc92021-12-09 18:06:29 +08001795 module.afdo = &afdo{}
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00001796 module.orderfile = &orderfile{}
Colin Crossca860ac2016-01-04 14:34:37 -08001797 return module
1798}
1799
Colin Crossce75d2c2016-10-06 16:12:58 -07001800func (c *Module) Prebuilt() *android.Prebuilt {
1801 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1802 return p.prebuilt()
1803 }
1804 return nil
1805}
1806
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001807func (c *Module) IsPrebuilt() bool {
1808 return c.Prebuilt() != nil
1809}
1810
Colin Crossce75d2c2016-10-06 16:12:58 -07001811func (c *Module) Name() string {
1812 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001813 if p, ok := c.linker.(interface {
1814 Name(string) string
1815 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001816 name = p.Name(name)
1817 }
1818 return name
1819}
1820
Alex Light3d673592019-01-18 14:37:31 -08001821func (c *Module) Symlinks() []string {
1822 if p, ok := c.installer.(interface {
1823 symlinkList() []string
1824 }); ok {
1825 return p.symlinkList()
1826 }
1827 return nil
1828}
1829
Chris Parsons216e10a2020-07-09 17:12:52 -04001830func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001831 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001832 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001833 }); ok {
1834 return p.dataPaths()
1835 }
1836 return nil
1837}
1838
Ivan Lozanof1868af2022-04-12 13:08:36 -04001839func getNameSuffixWithVndkVersion(ctx android.ModuleContext, c LinkableInterface) string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001840 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1841 // "current", it will append the VNDK version to the name suffix.
Justin Yun5f7f7e82019-11-18 19:52:14 +09001842 var nameSuffix string
Ivan Lozanof9e21722020-12-02 09:00:51 -05001843 if c.InProduct() {
Justin Yund00f5ca2021-02-03 19:43:02 +09001844 if c.ProductSpecific() {
1845 // If the module is product specific with 'product_specific: true',
1846 // do not add a name suffix because it is a base module.
1847 return ""
1848 }
Justin Yunaf1fde42023-09-27 16:22:10 +09001849 return ProductSuffix
Justin Yun5f7f7e82019-11-18 19:52:14 +09001850 } else {
Ivan Lozanoe6d30982021-02-05 10:57:43 -05001851 nameSuffix = VendorSuffix
Justin Yun5f7f7e82019-11-18 19:52:14 +09001852 }
Kiyoung Kim4e765b12024-04-04 17:33:42 +09001853 if c.VndkVersion() != "" {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001854 // add version suffix only if the module is using different vndk version than the
1855 // version in product or vendor partition.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001856 nameSuffix += "." + c.VndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09001857 }
1858 return nameSuffix
1859}
1860
Ivan Lozanof1868af2022-04-12 13:08:36 -04001861func GetSubnameProperty(actx android.ModuleContext, c LinkableInterface) string {
1862 var subName = ""
Inseob Kim64c43952019-08-26 16:52:35 +09001863
1864 if c.Target().NativeBridge == android.NativeBridgeEnabled {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001865 subName += NativeBridgeSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001866 }
1867
Colin Cross127bb8b2020-12-16 16:46:01 -08001868 llndk := c.IsLlndk()
Kiyoung Kimaa394802024-01-08 12:55:45 +09001869 if llndk || (c.InVendorOrProduct() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001870 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1871 // added for product variant only when we have vendor and product variants with core
1872 // variant. The suffix is not added for vendor-only or product-only module.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001873 subName += getNameSuffixWithVndkVersion(actx, c)
Colin Cross5271fea2021-04-27 13:06:04 -07001874 } else if c.IsVendorPublicLibrary() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001875 subName += vendorPublicLibrarySuffix
1876 } else if c.IsVndkPrebuiltLibrary() {
Inseob Kim64c43952019-08-26 16:52:35 +09001877 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1878 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
Ivan Lozanof1868af2022-04-12 13:08:36 -04001879 subName += VendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001880 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001881 subName += RamdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001882 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001883 subName += VendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001884 } else if c.InRecovery() && !c.OnlyInRecovery() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001885 subName += RecoverySuffix
1886 } else if c.IsSdkVariant() && (c.SdkAndPlatformVariantVisibleToMake() || c.SplitPerApiLevel()) {
1887 subName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001888 if c.SplitPerApiLevel() {
Ivan Lozanof1868af2022-04-12 13:08:36 -04001889 subName += "." + c.SdkVersion()
Dan Albert92fe7402020-07-15 13:33:30 -07001890 }
Spandan Dasb2b41d52023-04-13 18:15:05 +00001891 } else if c.IsStubs() && c.IsSdkVariant() {
1892 // Public API surface (NDK)
1893 // Add a suffix to this stub variant to distinguish it from the module-lib stub variant.
1894 subName = sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001895 }
Ivan Lozanof1868af2022-04-12 13:08:36 -04001896
1897 return subName
Chris Parsons8d6e4332021-02-22 16:13:50 -05001898}
1899
Sam Delmerico75dbca22023-04-20 13:13:25 +00001900func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext {
1901 ctx := &moduleContext{
1902 ModuleContext: actx,
1903 moduleContextImpl: moduleContextImpl{
1904 mod: c,
1905 },
1906 }
1907 ctx.ctx = ctx
1908 return ctx
1909}
1910
Spandan Das20fce2d2023-04-12 17:21:39 +00001911// TODO (b/277651159): Remove this allowlist
1912var (
1913 skipStubLibraryMultipleApexViolation = map[string]bool{
1914 "libclang_rt.asan": true,
1915 "libclang_rt.hwasan": true,
1916 // runtime apex
1917 "libc": true,
1918 "libc_hwasan": true,
1919 "libdl_android": true,
1920 "libm": true,
1921 "libdl": true,
Spandan Das1a0c6e12024-01-04 01:44:17 +00001922 "libz": true,
Spandan Das20fce2d2023-04-12 17:21:39 +00001923 // art apex
Martin Stjernholm75598032024-07-12 18:47:26 +01001924 // TODO(b/234351700): Remove this when com.android.art.debug is gone.
Spandan Das20fce2d2023-04-12 17:21:39 +00001925 "libandroidio": true,
1926 "libdexfile": true,
Martin Stjernholm75598032024-07-12 18:47:26 +01001927 "libdexfiled": true, // com.android.art.debug only
Spandan Das20fce2d2023-04-12 17:21:39 +00001928 "libnativebridge": true,
1929 "libnativehelper": true,
1930 "libnativeloader": true,
1931 "libsigchain": true,
1932 }
1933)
1934
1935// Returns true if a stub library could be installed in multiple apexes
1936func (c *Module) stubLibraryMultipleApexViolation(ctx android.ModuleContext) bool {
1937 // If this is not an apex variant, no check necessary
Colin Cross2dcbca62024-11-20 14:55:14 -08001938 if info, ok := android.ModuleProvider(ctx, android.ApexInfoProvider); !ok || info.IsForPlatform() {
Spandan Das20fce2d2023-04-12 17:21:39 +00001939 return false
1940 }
1941 // If this is not a stub library, no check necessary
1942 if !c.HasStubsVariants() {
1943 return false
1944 }
1945 // Skip the allowlist
1946 // Use BaseModuleName so that this matches prebuilts.
1947 if _, exists := skipStubLibraryMultipleApexViolation[c.BaseModuleName()]; exists {
1948 return false
1949 }
1950
1951 _, aaWithoutTestApexes, _ := android.ListSetDifference(c.ApexAvailable(), c.TestApexes())
1952 // Stub libraries should not have more than one apex_available
1953 if len(aaWithoutTestApexes) > 1 {
1954 return true
1955 }
1956 // Stub libraries should not use the wildcard
1957 if aaWithoutTestApexes[0] == android.AvailableToAnyApex {
1958 return true
1959 }
1960 // Default: no violation
1961 return false
1962}
1963
Chris Parsons8d6e4332021-02-22 16:13:50 -05001964func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Ronald Braunstein6a08d492024-04-15 12:55:30 -07001965 ctx := moduleContextFromAndroidModuleContext(actx, c)
1966
Inseob Kim37e0bb02024-04-29 15:54:44 +09001967 c.logtagsPaths = android.PathsForModuleSrc(actx, c.Properties.Logtags)
1968 android.SetProvider(ctx, android.LogtagsProviderKey, &android.LogtagsInfo{
1969 Logtags: c.logtagsPaths,
1970 })
1971
Ronald Braunstein6a08d492024-04-15 12:55:30 -07001972 // If Test_only is set on a module in bp file, respect the setting, otherwise
1973 // see if is a known test module type.
1974 testOnly := c.testModule || c.testLibrary()
1975 if c.sourceProperties.Test_only != nil {
1976 testOnly = Bool(c.sourceProperties.Test_only)
1977 }
1978 // Keep before any early returns.
1979 android.SetProvider(ctx, android.TestOnlyProviderKey, android.TestModuleInformation{
1980 TestOnly: testOnly,
1981 TopLevelTarget: c.testModule,
1982 })
1983
Ivan Lozanof1868af2022-04-12 13:08:36 -04001984 c.Properties.SubName = GetSubnameProperty(actx, c)
Colin Crossff694a82023-12-13 15:54:49 -08001985 apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
Chris Parsons8d6e4332021-02-22 16:13:50 -05001986 if !apexInfo.IsForPlatform() {
1987 c.hideApexVariantFromMake = true
1988 }
1989
Chris Parsonseefc9e62021-04-02 17:36:47 -04001990 c.makeLinkType = GetMakeLinkType(actx, c)
1991
Colin Crossf18e1102017-11-16 14:33:08 -08001992 deps := c.depsToPaths(ctx)
1993 if ctx.Failed() {
1994 return
1995 }
1996
Joe Onorato37f900c2023-07-18 16:58:16 -07001997 for _, generator := range c.generators {
1998 gen := generator.GeneratorSources(ctx)
1999 deps.IncludeDirs = append(deps.IncludeDirs, gen.IncludeDirs...)
2000 deps.ReexportedDirs = append(deps.ReexportedDirs, gen.ReexportedDirs...)
2001 deps.GeneratedDeps = append(deps.GeneratedDeps, gen.Headers...)
2002 deps.ReexportedGeneratedHeaders = append(deps.ReexportedGeneratedHeaders, gen.Headers...)
2003 deps.ReexportedDeps = append(deps.ReexportedDeps, gen.Headers...)
2004 if len(deps.Objs.objFiles) == 0 {
2005 // If we are reusuing object files (which happens when we're a shared library and we're
2006 // reusing our static variant's object files), then skip adding the actual source files,
2007 // because we already have the object for it.
2008 deps.GeneratedSources = append(deps.GeneratedSources, gen.Sources...)
2009 }
2010 }
2011
2012 if ctx.Failed() {
2013 return
2014 }
2015
Spandan Das20fce2d2023-04-12 17:21:39 +00002016 if c.stubLibraryMultipleApexViolation(actx) {
2017 actx.PropertyErrorf("apex_available",
2018 "Stub libraries should have a single apex_available (test apexes excluded). Got %v", c.ApexAvailable())
2019 }
Dan Willemsen8536d6b2018-10-07 20:54:34 -07002020 if c.Properties.Clang != nil && *c.Properties.Clang == false {
2021 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
Alixb5f6d9e2022-04-20 23:00:58 +00002022 } else if c.Properties.Clang != nil && !ctx.DeviceConfig().BuildBrokenClangProperty() {
2023 ctx.PropertyErrorf("clang", "property is deprecated, see Changes.md file")
Dan Willemsen8536d6b2018-10-07 20:54:34 -07002024 }
2025
Colin Crossca860ac2016-01-04 14:34:37 -08002026 flags := Flags{
2027 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002028 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08002029 }
Joe Onorato37f900c2023-07-18 16:58:16 -07002030 for _, generator := range c.generators {
2031 flags = generator.GeneratorFlags(ctx, flags, deps)
2032 }
Colin Crossca860ac2016-01-04 14:34:37 -08002033 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08002034 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08002035 }
2036 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002037 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08002038 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002039 if c.stl != nil {
2040 flags = c.stl.flags(ctx, flags)
2041 }
Colin Cross16b23492016-01-06 14:41:07 -08002042 if c.sanitize != nil {
2043 flags = c.sanitize.flags(ctx, flags)
2044 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002045 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07002046 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08002047 }
Cory Barkera1da26f2022-06-07 20:12:06 +00002048 if c.fuzzer != nil {
2049 flags = c.fuzzer.flags(ctx, flags)
2050 }
Stephen Craneba090d12017-05-09 15:44:35 -07002051 if c.lto != nil {
2052 flags = c.lto.flags(ctx, flags)
2053 }
Yi Kongeb8efc92021-12-09 18:06:29 +08002054 if c.afdo != nil {
2055 flags = c.afdo.flags(ctx, flags)
2056 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00002057 if c.orderfile != nil {
2058 flags = c.orderfile.flags(ctx, flags)
2059 }
Colin Crossca860ac2016-01-04 14:34:37 -08002060 for _, feature := range c.features {
2061 flags = feature.flags(ctx, flags)
2062 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002063 if ctx.Failed() {
2064 return
2065 }
2066
Colin Cross4af21ed2019-11-04 09:37:55 -08002067 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
2068 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
2069 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08002070
Colin Cross4af21ed2019-11-04 09:37:55 -08002071 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09002072
2073 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08002074 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09002075 }
2076 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08002077 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09002078 }
2079
Colin Cross3e5e7782022-06-17 22:17:05 +00002080 flags.Local.LdFlags = append(flags.Local.LdFlags, deps.LdFlags...)
2081
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08002082 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07002083 // We need access to all the flags seen by a source file.
2084 if c.sabi != nil {
2085 flags = c.sabi.flags(ctx, flags)
2086 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07002087
Colin Cross4af21ed2019-11-04 09:37:55 -08002088 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07002089
Joe Onorato37f900c2023-07-18 16:58:16 -07002090 for _, generator := range c.generators {
2091 generator.GeneratorBuildActions(ctx, flags, deps)
2092 }
2093
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002094 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08002095 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002096 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08002097 if ctx.Failed() {
2098 return
2099 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002100 }
2101
Colin Crossca860ac2016-01-04 14:34:37 -08002102 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002103 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08002104 if ctx.Failed() {
2105 return
2106 }
Colin Cross635c3b02016-05-18 15:37:25 -07002107 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09002108
Chris Parsons94a0bba2021-06-04 15:03:47 -04002109 c.maybeUnhideFromMake()
Colin Crossb614cd42024-10-11 12:52:21 -07002110
2111 android.SetProvider(ctx, ImplementationDepInfoProvider, &ImplementationDepInfo{
2112 ImplementationDeps: depset.New(depset.PREORDER, deps.directImplementationDeps, deps.transitiveImplementationDeps),
2113 })
Colin Crossce75d2c2016-10-06 16:12:58 -07002114 }
Ronald Braunsteina115e262024-04-09 18:07:38 -07002115
Colin Cross40213022023-12-13 15:19:49 -08002116 android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: deps.GeneratedSources.Strings()})
Colin Cross5049f022015-03-18 13:28:46 -07002117
Hao Chen1c8ea5b2023-10-20 23:03:45 +00002118 if Bool(c.Properties.Cmake_snapshot_supported) {
2119 android.SetProvider(ctx, cmakeSnapshotSourcesProvider, android.GlobFiles(ctx, ctx.ModuleDir()+"/**/*", nil))
2120 }
2121
Chris Parsons94a0bba2021-06-04 15:03:47 -04002122 c.maybeInstall(ctx, apexInfo)
Colin Cross4a9e6ec2023-12-18 15:29:41 -08002123
2124 if c.linker != nil {
2125 moduleInfoJSON := ctx.ModuleInfoJSON()
2126 c.linker.moduleInfoJSON(ctx, moduleInfoJSON)
2127 moduleInfoJSON.SharedLibs = c.Properties.AndroidMkSharedLibs
2128 moduleInfoJSON.StaticLibs = c.Properties.AndroidMkStaticLibs
2129 moduleInfoJSON.SystemSharedLibs = c.Properties.AndroidMkSystemSharedLibs
2130 moduleInfoJSON.RuntimeDependencies = c.Properties.AndroidMkRuntimeLibs
2131
2132 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkSharedLibs...)
2133 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkStaticLibs...)
2134 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkHeaderLibs...)
2135 moduleInfoJSON.Dependencies = append(moduleInfoJSON.Dependencies, c.Properties.AndroidMkWholeStaticLibs...)
2136
2137 if c.sanitize != nil && len(moduleInfoJSON.Class) > 0 &&
2138 (moduleInfoJSON.Class[0] == "STATIC_LIBRARIES" || moduleInfoJSON.Class[0] == "HEADER_LIBRARIES") {
2139 if Bool(c.sanitize.Properties.SanitizeMutated.Cfi) {
2140 moduleInfoJSON.SubName += ".cfi"
2141 }
2142 if Bool(c.sanitize.Properties.SanitizeMutated.Hwaddress) {
2143 moduleInfoJSON.SubName += ".hwasan"
2144 }
2145 if Bool(c.sanitize.Properties.SanitizeMutated.Scs) {
2146 moduleInfoJSON.SubName += ".scs"
2147 }
2148 }
2149 moduleInfoJSON.SubName += c.Properties.SubName
2150
2151 if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
2152 moduleInfoJSON.Uninstallable = true
2153 }
Colin Cross4a9e6ec2023-12-18 15:29:41 -08002154 }
Wei Lia1aa2972024-06-21 13:08:51 -07002155
2156 buildComplianceMetadataInfo(ctx, c, deps)
mrziwangabdb2932024-06-18 12:43:41 -07002157
Cole Faust96a692b2024-08-08 14:47:51 -07002158 if b, ok := c.compiler.(*baseCompiler); ok {
2159 c.hasAidl = b.hasSrcExt(ctx, ".aidl")
2160 c.hasLex = b.hasSrcExt(ctx, ".l") || b.hasSrcExt(ctx, ".ll")
2161 c.hasProto = b.hasSrcExt(ctx, ".proto")
2162 c.hasRenderscript = b.hasSrcExt(ctx, ".rscript") || b.hasSrcExt(ctx, ".fs")
2163 c.hasSysprop = b.hasSrcExt(ctx, ".sysprop")
2164 c.hasWinMsg = b.hasSrcExt(ctx, ".mc")
2165 c.hasYacc = b.hasSrcExt(ctx, ".y") || b.hasSrcExt(ctx, ".yy")
2166 }
2167
Yu Liuec7043d2024-11-05 18:22:20 +00002168 ccObjectInfo := CcObjectInfo{
2169 kytheFiles: objs.kytheFiles,
2170 }
2171 if !ctx.Config().KatiEnabled() || !android.ShouldSkipAndroidMkProcessing(ctx, c) {
2172 ccObjectInfo.objFiles = objs.objFiles
2173 ccObjectInfo.tidyFiles = objs.tidyFiles
2174 }
2175 if len(ccObjectInfo.kytheFiles)+len(ccObjectInfo.objFiles)+len(ccObjectInfo.tidyFiles) > 0 {
2176 android.SetProvider(ctx, CcObjectInfoProvider, ccObjectInfo)
2177 }
2178
Yu Liu986d98c2024-11-12 00:28:11 +00002179 android.SetProvider(ctx, LinkableInfoKey, LinkableInfo{
2180 StaticExecutable: c.StaticExecutable(),
2181 })
2182
Yu Liu323d77a2024-12-16 23:13:57 +00002183 ccInfo := CcInfo{
2184 HasStubsVariants: c.HasStubsVariants(),
2185 IsPrebuilt: c.IsPrebuilt(),
2186 CmakeSnapshotSupported: proptools.Bool(c.Properties.Cmake_snapshot_supported),
2187 }
2188 if c.compiler != nil {
2189 ccInfo.CompilerInfo = &CompilerInfo{
2190 Srcs: c.compiler.(CompiledInterface).Srcs(),
2191 Cflags: c.compiler.baseCompilerProps().Cflags,
2192 AidlInterfaceInfo: AidlInterfaceInfo{
2193 Sources: c.compiler.baseCompilerProps().AidlInterface.Sources,
2194 AidlRoot: c.compiler.baseCompilerProps().AidlInterface.AidlRoot,
2195 Lang: c.compiler.baseCompilerProps().AidlInterface.Lang,
2196 Flags: c.compiler.baseCompilerProps().AidlInterface.Flags,
2197 },
2198 }
2199 switch decorator := c.compiler.(type) {
2200 case *libraryDecorator:
2201 ccInfo.CompilerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{
2202 Export_include_dirs: decorator.flagExporter.Properties.Export_include_dirs,
2203 }
2204 }
2205 }
2206 if c.linker != nil {
2207 ccInfo.LinkerInfo = &LinkerInfo{
2208 Whole_static_libs: c.linker.baseLinkerProps().Whole_static_libs,
2209 Static_libs: c.linker.baseLinkerProps().Static_libs,
2210 Shared_libs: c.linker.baseLinkerProps().Shared_libs,
2211 Header_libs: c.linker.baseLinkerProps().Header_libs,
2212 }
2213 switch decorator := c.linker.(type) {
2214 case *binaryDecorator:
2215 ccInfo.LinkerInfo.BinaryDecoratorInfo = &BinaryDecoratorInfo{}
2216 case *libraryDecorator:
2217 ccInfo.LinkerInfo.LibraryDecoratorInfo = &LibraryDecoratorInfo{}
2218 case *testBinary:
2219 ccInfo.LinkerInfo.TestBinaryInfo = &TestBinaryInfo{
2220 Gtest: decorator.testDecorator.gtest(),
2221 }
2222 case *benchmarkDecorator:
2223 ccInfo.LinkerInfo.BenchmarkDecoratorInfo = &BenchmarkDecoratorInfo{}
2224 case *objectLinker:
2225 ccInfo.LinkerInfo.ObjectLinkerInfo = &ObjectLinkerInfo{}
2226 }
2227 }
2228 android.SetProvider(ctx, CcInfoProvider, ccInfo)
Yu Liub1bfa9d2024-12-05 18:57:51 +00002229
mrziwangabdb2932024-06-18 12:43:41 -07002230 c.setOutputFiles(ctx)
Yu Liu76d94462024-10-31 23:32:36 +00002231
2232 if c.makeVarsInfo != nil {
2233 android.SetProvider(ctx, CcMakeVarsInfoProvider, c.makeVarsInfo)
2234 }
mrziwangabdb2932024-06-18 12:43:41 -07002235}
2236
Yu Liuec7043d2024-11-05 18:22:20 +00002237func setOutputFilesIfNotEmpty(ctx ModuleContext, files android.Paths, tag string) {
2238 if len(files) > 0 {
2239 ctx.SetOutputFiles(files, tag)
2240 }
2241}
2242
mrziwangabdb2932024-06-18 12:43:41 -07002243func (c *Module) setOutputFiles(ctx ModuleContext) {
2244 if c.outputFile.Valid() {
2245 ctx.SetOutputFiles(android.Paths{c.outputFile.Path()}, "")
2246 } else {
2247 ctx.SetOutputFiles(android.Paths{}, "")
2248 }
2249 if c.linker != nil {
2250 ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.unstrippedOutputFilePath()), "unstripped")
2251 ctx.SetOutputFiles(android.PathsIfNonNil(c.linker.strippedAllOutputFilePath()), "stripped_all")
2252 }
Wei Lia1aa2972024-06-21 13:08:51 -07002253}
2254
2255func buildComplianceMetadataInfo(ctx ModuleContext, c *Module, deps PathDeps) {
2256 // Dump metadata that can not be done in android/compliance-metadata.go
2257 complianceMetadataInfo := ctx.ComplianceMetadataInfo()
2258 complianceMetadataInfo.SetStringValue(android.ComplianceMetadataProp.IS_STATIC_LIB, strconv.FormatBool(ctx.static()))
2259 complianceMetadataInfo.SetStringValue(android.ComplianceMetadataProp.BUILT_FILES, c.outputFile.String())
2260
2261 // Static deps
Yu Liuf432c2e2024-12-17 00:09:15 +00002262 staticDeps := ctx.GetDirectDepsProxyWithTag(StaticDepTag(false))
Wei Lia1aa2972024-06-21 13:08:51 -07002263 staticDepNames := make([]string, 0, len(staticDeps))
2264 for _, dep := range staticDeps {
2265 staticDepNames = append(staticDepNames, dep.Name())
2266 }
2267
2268 staticDepPaths := make([]string, 0, len(deps.StaticLibs))
2269 for _, dep := range deps.StaticLibs {
2270 staticDepPaths = append(staticDepPaths, dep.String())
2271 }
2272 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames))
2273 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.FirstUniqueStrings(staticDepPaths))
2274
2275 // Whole static deps
Yu Liuf432c2e2024-12-17 00:09:15 +00002276 wholeStaticDeps := ctx.GetDirectDepsProxyWithTag(StaticDepTag(true))
Wei Lia1aa2972024-06-21 13:08:51 -07002277 wholeStaticDepNames := make([]string, 0, len(wholeStaticDeps))
2278 for _, dep := range wholeStaticDeps {
2279 wholeStaticDepNames = append(wholeStaticDepNames, dep.Name())
2280 }
2281
2282 wholeStaticDepPaths := make([]string, 0, len(deps.WholeStaticLibs))
2283 for _, dep := range deps.WholeStaticLibs {
2284 wholeStaticDepPaths = append(wholeStaticDepPaths, dep.String())
2285 }
2286 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.WHOLE_STATIC_DEPS, android.FirstUniqueStrings(wholeStaticDepNames))
2287 complianceMetadataInfo.SetListValue(android.ComplianceMetadataProp.WHOLE_STATIC_DEP_FILES, android.FirstUniqueStrings(wholeStaticDepPaths))
Chris Parsons94a0bba2021-06-04 15:03:47 -04002288}
2289
2290func (c *Module) maybeUnhideFromMake() {
2291 // If a lib is directly included in any of the APEXes or is not available to the
2292 // platform (which is often the case when the stub is provided as a prebuilt),
2293 // unhide the stubs variant having the latest version gets visible to make. In
2294 // addition, the non-stubs variant is renamed to <libname>.bootstrap. This is to
2295 // force anything in the make world to link against the stubs library. (unless it
2296 // is explicitly referenced via .bootstrap suffix or the module is marked with
2297 // 'bootstrap: true').
2298 if c.HasStubsVariants() && c.NotInPlatform() && !c.InRamdisk() &&
Kiyoung Kimaa394802024-01-08 12:55:45 +09002299 !c.InRecovery() && !c.InVendorOrProduct() && !c.static() && !c.isCoverageVariant() &&
Chris Parsons94a0bba2021-06-04 15:03:47 -04002300 c.IsStubs() && !c.InVendorRamdisk() {
2301 c.Properties.HideFromMake = false // unhide
2302 // Note: this is still non-installable
2303 }
2304}
2305
Colin Cross8ff10582023-12-07 13:10:56 -08002306// maybeInstall is called at the end of both GenerateAndroidBuildActions to run the
2307// install hooks for installable modules, like binaries and tests.
Chris Parsons94a0bba2021-06-04 15:03:47 -04002308func (c *Module) maybeInstall(ctx ModuleContext, apexInfo android.ApexInfo) {
Colin Cross1bc94122021-10-28 13:25:54 -07002309 if !proptools.BoolDefault(c.Installable(), true) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002310 // If the module has been specifically configure to not be installed then
2311 // hide from make as otherwise it will break when running inside make
2312 // as the output path to install will not be specified. Not all uninstallable
2313 // modules can be hidden from make as some are needed for resolving make side
2314 // dependencies.
2315 c.HideFromMake()
Spandan Das034af2c2024-10-30 21:45:09 +00002316 c.SkipInstall()
Ivan Lozanod7586b62021-04-01 09:49:36 -04002317 } else if !installable(c, apexInfo) {
Colin Crossa9c8c9f2020-12-16 10:20:23 -08002318 c.SkipInstall()
2319 }
2320
2321 // Still call c.installer.install though, the installs will be stored as PackageSpecs
2322 // to allow using the outputs in a genrule.
2323 if c.installer != nil && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07002324 c.installer.install(ctx, c.outputFile.Path())
2325 if ctx.Failed() {
2326 return
Colin Crossca860ac2016-01-04 14:34:37 -08002327 }
Dan Albertc403f7c2015-03-18 14:01:18 -07002328 }
Colin Cross3f40fa42015-01-30 17:27:36 -08002329}
2330
Colin Cross0ea8ba82019-06-06 14:33:29 -07002331func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08002332 if c.cachedToolchain == nil {
Liz Kammer356f7d42021-01-26 09:18:53 -05002333 c.cachedToolchain = config.FindToolchainWithContext(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -08002334 }
Colin Crossca860ac2016-01-04 14:34:37 -08002335 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08002336}
2337
Colin Crossca860ac2016-01-04 14:34:37 -08002338func (c *Module) begin(ctx BaseModuleContext) {
Joe Onorato37f900c2023-07-18 16:58:16 -07002339 for _, generator := range c.generators {
2340 generator.GeneratorInit(ctx)
2341 }
Colin Crossca860ac2016-01-04 14:34:37 -08002342 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002343 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07002344 }
Colin Crossca860ac2016-01-04 14:34:37 -08002345 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002346 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08002347 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002348 if c.stl != nil {
2349 c.stl.begin(ctx)
2350 }
Colin Cross16b23492016-01-06 14:41:07 -08002351 if c.sanitize != nil {
2352 c.sanitize.begin(ctx)
2353 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002354 if c.coverage != nil {
2355 c.coverage.begin(ctx)
2356 }
Yi Kong9723e332023-12-04 14:52:53 +09002357 if c.afdo != nil {
2358 c.afdo.begin(ctx)
2359 }
Stephen Craneba090d12017-05-09 15:44:35 -07002360 if c.lto != nil {
2361 c.lto.begin(ctx)
2362 }
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00002363 if c.orderfile != nil {
2364 c.orderfile.begin(ctx)
2365 }
Dan Albert92fe7402020-07-15 13:33:30 -07002366 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07002367 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002368 if err != nil {
2369 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07002370 c.Properties.Sdk_version = nil
2371 } else {
2372 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002373 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07002374 }
Colin Crossca860ac2016-01-04 14:34:37 -08002375}
2376
Colin Cross37047f12016-12-13 17:06:13 -08002377func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07002378 deps := Deps{}
2379
Joe Onorato37f900c2023-07-18 16:58:16 -07002380 for _, generator := range c.generators {
2381 deps = generator.GeneratorDeps(ctx, deps)
2382 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002383 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002384 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002385 }
2386 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07002387 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002388 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07002389 if c.stl != nil {
2390 deps = c.stl.deps(ctx, deps)
2391 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00002392 if c.coverage != nil {
2393 deps = c.coverage.deps(ctx, deps)
2394 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002395
Colin Crossb6715442017-10-24 11:13:31 -07002396 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
2397 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
2398 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
2399 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
2400 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
2401 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08002402 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002403 deps.LlndkHeaderLibs = android.LastUniqueStrings(deps.LlndkHeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07002404
Colin Cross516c5452024-10-28 13:45:21 -07002405 if err := checkConflictingExplicitVersions(deps.SharedLibs); err != nil {
2406 ctx.PropertyErrorf("shared_libs", "%s", err.Error())
2407 }
2408
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002409 for _, lib := range deps.ReexportSharedLibHeaders {
2410 if !inList(lib, deps.SharedLibs) {
2411 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
2412 }
2413 }
2414
2415 for _, lib := range deps.ReexportStaticLibHeaders {
Steven Morelandba407c82021-04-01 22:17:50 +00002416 if !inList(lib, deps.StaticLibs) && !inList(lib, deps.WholeStaticLibs) {
2417 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 -07002418 }
2419 }
2420
Colin Cross5950f382016-12-13 12:50:57 -08002421 for _, lib := range deps.ReexportHeaderLibHeaders {
2422 if !inList(lib, deps.HeaderLibs) {
2423 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
2424 }
2425 }
2426
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002427 for _, gen := range deps.ReexportGeneratedHeaders {
2428 if !inList(gen, deps.GeneratedHeaders) {
2429 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
2430 }
2431 }
2432
Colin Crossc99deeb2016-04-11 15:06:20 -07002433 return deps
2434}
2435
Colin Cross516c5452024-10-28 13:45:21 -07002436func checkConflictingExplicitVersions(libs []string) error {
2437 withoutVersion := func(s string) string {
2438 name, _ := StubsLibNameAndVersion(s)
2439 return name
2440 }
2441 var errs []error
2442 for i, lib := range libs {
2443 libName := withoutVersion(lib)
2444 libsToCompare := libs[i+1:]
2445 j := slices.IndexFunc(libsToCompare, func(s string) bool {
2446 return withoutVersion(s) == libName
2447 })
2448 if j >= 0 {
2449 errs = append(errs, fmt.Errorf("duplicate shared libraries with different explicit versions: %q and %q",
2450 lib, libsToCompare[j]))
2451 }
2452 }
2453 return errors.Join(errs...)
2454}
2455
Dan Albert7e9d2952016-08-04 13:02:36 -07002456func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08002457 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07002458 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08002459 moduleContextImpl: moduleContextImpl{
2460 mod: c,
2461 },
2462 }
2463 ctx.ctx = ctx
2464
Colin Crossca860ac2016-01-04 14:34:37 -08002465 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07002466}
2467
Jiyong Park7ed9de32018-10-15 22:25:07 +09002468// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09002469func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002470 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
2471 version := name[sharp+1:]
2472 libname := name[:sharp]
2473 return libname, version
2474 }
2475 return name, ""
2476}
2477
Dan Albert92fe7402020-07-15 13:33:30 -07002478func GetCrtVariations(ctx android.BottomUpMutatorContext,
2479 m LinkableInterface) []blueprint.Variation {
2480 if ctx.Os() != android.Android {
2481 return nil
2482 }
2483 if m.UseSdk() {
Jiyong Parkfdaa5f72021-03-19 22:18:04 +09002484 // Choose the CRT that best satisfies the min_sdk_version requirement of this module
2485 minSdkVersion := m.MinSdkVersion()
2486 if minSdkVersion == "" || minSdkVersion == "apex_inherit" {
2487 minSdkVersion = m.SdkVersion()
2488 }
Jooyung Han94a76ee2021-06-08 09:49:48 +09002489 apiLevel, err := android.ApiLevelFromUser(ctx, minSdkVersion)
2490 if err != nil {
2491 ctx.PropertyErrorf("min_sdk_version", err.Error())
2492 }
Colin Cross363ec762023-01-13 13:45:14 -08002493
2494 // Raise the minSdkVersion to the minimum supported for the architecture.
Colin Crossbb137a32023-01-26 09:54:42 -08002495 minApiForArch := MinApiForArch(ctx, m.Target().Arch.ArchType)
Colin Cross363ec762023-01-13 13:45:14 -08002496 if apiLevel.LessThan(minApiForArch) {
2497 apiLevel = minApiForArch
2498 }
2499
Dan Albert92fe7402020-07-15 13:33:30 -07002500 return []blueprint.Variation{
2501 {Mutator: "sdk", Variation: "sdk"},
Jooyung Han94a76ee2021-06-08 09:49:48 +09002502 {Mutator: "version", Variation: apiLevel.String()},
Dan Albert92fe7402020-07-15 13:33:30 -07002503 }
2504 }
2505 return []blueprint.Variation{
2506 {Mutator: "sdk", Variation: ""},
2507 }
2508}
2509
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002510func AddSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, mod LinkableInterface,
2511 variations []blueprint.Variation, depTag blueprint.DependencyTag, name, version string, far bool) {
Colin Crosse7257d22020-09-24 09:56:18 -07002512
2513 variations = append([]blueprint.Variation(nil), variations...)
2514
Liz Kammer23942242022-04-08 15:41:00 -04002515 if version != "" && canBeOrLinkAgainstVersionVariants(mod) {
Colin Crosse7257d22020-09-24 09:56:18 -07002516 // Version is explicitly specified. i.e. libFoo#30
Colin Crossb614cd42024-10-11 12:52:21 -07002517 if version == "impl" {
2518 version = ""
2519 }
Colin Crosse7257d22020-09-24 09:56:18 -07002520 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002521 if tag, ok := depTag.(libraryDependencyTag); ok {
2522 tag.explicitlyVersioned = true
Colin Crossafcdce82024-10-22 13:59:33 -07002523 // depTag is an interface that contains a concrete non-pointer struct. That makes the local
2524 // tag variable a copy of the contents of depTag, and updating it doesn't change depTag. Reassign
2525 // the modified copy to depTag.
2526 depTag = tag
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002527 } else {
2528 panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
2529 }
Colin Crosse7257d22020-09-24 09:56:18 -07002530 }
Colin Crosse7257d22020-09-24 09:56:18 -07002531
Colin Cross0de8a1e2020-09-18 14:15:30 -07002532 if far {
2533 ctx.AddFarVariationDependencies(variations, depTag, name)
2534 } else {
2535 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07002536 }
2537}
2538
Kiyoung Kim487689e2022-07-26 09:48:22 +09002539func GetReplaceModuleName(lib string, replaceMap map[string]string) string {
2540 if snapshot, ok := replaceMap[lib]; ok {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002541 return snapshot
2542 }
2543
2544 return lib
2545}
2546
Kiyoung Kim37693d02024-04-04 09:56:15 +09002547// FilterNdkLibs takes a list of names of shared libraries and scans it for two types
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002548// of names:
2549//
Kiyoung Kim37693d02024-04-04 09:56:15 +09002550// 1. Name of an NDK library that refers to an ndk_library module.
Kiyoung Kim487689e2022-07-26 09:48:22 +09002551//
2552// For each of these, it adds the name of the ndk_library module to the list of
2553// variant libs.
2554//
Kiyoung Kim37693d02024-04-04 09:56:15 +09002555// 2. Anything else (so anything that isn't an NDK library).
Kiyoung Kim487689e2022-07-26 09:48:22 +09002556//
2557// It adds these to the nonvariantLibs list.
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002558//
2559// The caller can then know to add the variantLibs dependencies differently from the
2560// nonvariantLibs
Kiyoung Kim37693d02024-04-04 09:56:15 +09002561func FilterNdkLibs(c LinkableInterface, config android.Config, list []string) (nonvariantLibs []string, variantLibs []string) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002562 variantLibs = []string{}
2563
2564 nonvariantLibs = []string{}
2565 for _, entry := range list {
2566 // strip #version suffix out
2567 name, _ := StubsLibNameAndVersion(entry)
Kiyoung Kim37693d02024-04-04 09:56:15 +09002568 if c.UseSdk() && inList(name, *getNDKKnownLibs(config)) {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002569 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002570 } else {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002571 nonvariantLibs = append(nonvariantLibs, entry)
2572 }
2573 }
2574 return nonvariantLibs, variantLibs
Kiyoung Kim37693d02024-04-04 09:56:15 +09002575
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002576}
2577
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002578func rewriteLibsForApiImports(c LinkableInterface, libs []string, replaceList map[string]string, config android.Config) ([]string, []string) {
2579 nonVariantLibs := []string{}
2580 variantLibs := []string{}
2581
2582 for _, lib := range libs {
2583 replaceLibName := GetReplaceModuleName(lib, replaceList)
2584 if replaceLibName == lib {
2585 // Do not handle any libs which are not in API imports
2586 nonVariantLibs = append(nonVariantLibs, replaceLibName)
2587 } else if c.UseSdk() && inList(replaceLibName, *getNDKKnownLibs(config)) {
2588 variantLibs = append(variantLibs, replaceLibName)
2589 } else {
2590 nonVariantLibs = append(nonVariantLibs, replaceLibName)
2591 }
Kiyoung Kim487689e2022-07-26 09:48:22 +09002592 }
2593
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002594 return nonVariantLibs, variantLibs
Kiyoung Kim487689e2022-07-26 09:48:22 +09002595}
2596
Kiyoung Kim76b06f32023-02-06 22:08:13 +09002597func (c *Module) shouldUseApiSurface() bool {
2598 if c.Os() == android.Android && c.Target().NativeBridge != android.NativeBridgeEnabled {
2599 if GetImageVariantType(c) == vendorImageVariant || GetImageVariantType(c) == productImageVariant {
2600 // LLNDK Variant
2601 return true
2602 }
2603
2604 if c.Properties.IsSdkVariant {
2605 // NDK Variant
2606 return true
2607 }
Kiyoung Kim76b06f32023-02-06 22:08:13 +09002608 }
2609
2610 return false
2611}
2612
Colin Cross1e676be2016-10-12 14:38:15 -07002613func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -07002614 if !c.Enabled(actx) {
Inseob Kimeec88e12020-01-22 11:11:29 +09002615 return
2616 }
2617
Colin Cross37047f12016-12-13 17:06:13 -08002618 ctx := &depsContext{
2619 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07002620 moduleContextImpl: moduleContextImpl{
2621 mod: c,
2622 },
2623 }
2624 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08002625
Colin Crossc99deeb2016-04-11 15:06:20 -07002626 deps := c.deps(ctx)
Kiyoung Kim11d91082022-10-19 19:20:57 +09002627
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002628 apiNdkLibs := []string{}
2629 apiLateNdkLibs := []string{}
2630
Yo Chiang219968c2020-09-22 18:45:04 +08002631 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
2632
Dan Albert914449f2016-06-17 16:45:24 -07002633 variantNdkLibs := []string{}
2634 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07002635 if ctx.Os() == android.Android {
Kiyoung Kim37693d02024-04-04 09:56:15 +09002636 deps.SharedLibs, variantNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.SharedLibs)
2637 deps.LateSharedLibs, variantLateNdkLibs = FilterNdkLibs(c, ctx.Config(), deps.LateSharedLibs)
2638 deps.ReexportSharedLibHeaders, _ = FilterNdkLibs(c, ctx.Config(), deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07002639 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002640
Colin Cross32ec36c2016-12-15 07:39:51 -08002641 for _, lib := range deps.HeaderLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002642 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002643 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002644 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002645 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002646
Spandan Das73bcafc2022-08-18 23:26:00 +00002647 if c.isNDKStubLibrary() {
Jiyong Parkf8fab9b2024-09-02 15:24:15 +09002648 variationExists := actx.OtherModuleDependencyVariantExists(nil, lib)
2649 if variationExists {
2650 actx.AddVariationDependencies(nil, depTag, lib)
2651 } else {
2652 // dependencies to ndk_headers fall here as ndk_headers do not have
2653 // any variants.
2654 actx.AddFarVariationDependencies([]blueprint.Variation{}, depTag, lib)
2655 }
Spandan Dasff665182024-09-11 18:48:44 +00002656 } else if c.IsStubs() {
Colin Cross7228ecd2019-11-18 16:00:16 -08002657 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002658 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002659 } else {
2660 actx.AddVariationDependencies(nil, depTag, lib)
2661 }
2662 }
2663
Dan Albertf1d14c72020-07-30 14:32:55 -07002664 if c.isNDKStubLibrary() {
2665 // NDK stubs depend on their implementation because the ABI dumps are
2666 // generated from the implementation library.
Kiyoung Kim487689e2022-07-26 09:48:22 +09002667
Spandan Das8b08aea2023-03-14 19:29:34 +00002668 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
2669 c.ImageVariation(),
2670 blueprint.Variation{Mutator: "link", Variation: "shared"},
2671 ), stubImplementation, c.BaseModuleName())
Dan Albertf1d14c72020-07-30 14:32:55 -07002672 }
2673
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002674 // If this module is an LLNDK implementation library, let it depend on LlndkHeaderLibs.
2675 if c.ImageVariation().Variation == android.CoreVariation && c.Device() &&
2676 c.Target().NativeBridge == android.NativeBridgeDisabled {
2677 actx.AddVariationDependencies(
Jihoon Kang47e91842024-06-19 00:51:16 +00002678 []blueprint.Variation{{Mutator: "image", Variation: android.VendorVariation}},
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08002679 llndkHeaderLibTag,
2680 deps.LlndkHeaderLibs...)
2681 }
2682
Jiyong Park5d1598f2019-02-25 22:14:17 +09002683 for _, lib := range deps.WholeStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002684 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Inseob Kimeec88e12020-01-22 11:11:29 +09002685
Jiyong Park5d1598f2019-02-25 22:14:17 +09002686 actx.AddVariationDependencies([]blueprint.Variation{
2687 {Mutator: "link", Variation: "static"},
2688 }, depTag, lib)
2689 }
2690
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002691 for _, lib := range deps.StaticLibs {
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04002692 // Some dependencies listed in static_libs might actually be rust_ffi rlib variants.
Colin Cross8acea3e2024-12-12 14:53:30 -08002693 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04002694
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002695 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002696 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002697 }
Jiyong Parke3867542020-12-03 17:28:25 +09002698 if inList(lib, deps.ExcludeLibsForApex) {
2699 depTag.excludeInApex = true
2700 }
Dan Willemsen59339a22018-07-22 21:18:45 -07002701 actx.AddVariationDependencies([]blueprint.Variation{
2702 {Mutator: "link", Variation: "static"},
2703 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002704 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002705
Jooyung Han75568392020-03-20 04:29:24 +09002706 // staticUnwinderDep is treated as staticDep for Q apexes
2707 // so that native libraries/binaries are linked with static unwinder
2708 // because Q libc doesn't have unwinder APIs
2709 if deps.StaticUnwinderIfLegacy {
Colin Cross8acea3e2024-12-12 14:53:30 -08002710 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002711 actx.AddVariationDependencies([]blueprint.Variation{
2712 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002713 }, depTag, staticUnwinder(actx))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002714 }
2715
Jiyong Park7ed9de32018-10-15 22:25:07 +09002716 // shared lib names without the #version suffix
2717 var sharedLibNames []string
2718
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002719 for _, lib := range deps.SharedLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002720 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002721 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002722 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002723 }
Jiyong Parke3867542020-12-03 17:28:25 +09002724 if inList(lib, deps.ExcludeLibsForApex) {
2725 depTag.excludeInApex = true
2726 }
Jooyung Han9ffbe832023-11-28 22:31:35 +09002727 if inList(lib, deps.ExcludeLibsForNonApex) {
2728 depTag.excludeInNonApex = true
2729 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002730
Jiyong Park73c54ee2019-10-22 20:31:18 +09002731 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002732 sharedLibNames = append(sharedLibNames, name)
2733
Colin Crosse7257d22020-09-24 09:56:18 -07002734 variations := []blueprint.Variation{
2735 {Mutator: "link", Variation: "shared"},
2736 }
Spandan Dasff665182024-09-11 18:48:44 +00002737 AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002738 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002739
Colin Crossfe9acfe2021-06-14 16:13:03 -07002740 for _, lib := range deps.LateStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002741 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Colin Crossfe9acfe2021-06-14 16:13:03 -07002742 actx.AddVariationDependencies([]blueprint.Variation{
2743 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002744 }, depTag, lib)
Colin Crossfe9acfe2021-06-14 16:13:03 -07002745 }
2746
Colin Cross3e5e7782022-06-17 22:17:05 +00002747 for _, lib := range deps.UnexportedStaticLibs {
Colin Cross8acea3e2024-12-12 14:53:30 -08002748 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency, unexportedSymbols: true}
Colin Cross3e5e7782022-06-17 22:17:05 +00002749 actx.AddVariationDependencies([]blueprint.Variation{
2750 {Mutator: "link", Variation: "static"},
Kiyoung Kim37693d02024-04-04 09:56:15 +09002751 }, depTag, lib)
Colin Cross3e5e7782022-06-17 22:17:05 +00002752 }
2753
Jiyong Park7ed9de32018-10-15 22:25:07 +09002754 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002755 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002756 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2757 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2758 // linking against both the stubs lib and the non-stubs lib at the same time.
2759 continue
2760 }
Colin Cross8acea3e2024-12-12 14:53:30 -08002761 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002762 variations := []blueprint.Variation{
2763 {Mutator: "link", Variation: "shared"},
2764 }
Ivan Lozanod67a6b02021-05-20 13:01:32 -04002765 AddSharedLibDependenciesWithVersions(ctx, c, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002766 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002767
Dan Willemsen59339a22018-07-22 21:18:45 -07002768 actx.AddVariationDependencies([]blueprint.Variation{
2769 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002770 }, dataLibDepTag, deps.DataLibs...)
2771
Colin Crossc8caa062021-09-24 16:50:14 -07002772 actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...)
2773
Chris Parsons79d66a52020-06-05 17:26:16 -04002774 actx.AddVariationDependencies([]blueprint.Variation{
2775 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002776 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002777
Colin Cross68861832016-07-08 10:41:41 -07002778 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002779
2780 for _, gen := range deps.GeneratedHeaders {
2781 depTag := genHeaderDepTag
2782 if inList(gen, deps.ReexportGeneratedHeaders) {
2783 depTag = genHeaderExportDepTag
2784 }
2785 actx.AddDependency(c, depTag, gen)
2786 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002787
Cole Faust65cb40a2024-10-21 15:41:42 -07002788 for _, gen := range deps.DeviceFirstGeneratedHeaders {
2789 depTag := genHeaderDepTag
2790 actx.AddVariationDependencies(ctx.Config().AndroidFirstDeviceTarget.Variations(), depTag, gen)
2791 }
2792
Dan Albert92fe7402020-07-15 13:33:30 -07002793 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002794 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc465efd2021-06-11 18:00:04 -07002795 for _, crt := range deps.CrtBegin {
Dan Albert92fe7402020-07-15 13:33:30 -07002796 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
Kiyoung Kim37693d02024-04-04 09:56:15 +09002797 crt)
Colin Crossca860ac2016-01-04 14:34:37 -08002798 }
Colin Crossc465efd2021-06-11 18:00:04 -07002799 for _, crt := range deps.CrtEnd {
Dan Albert92fe7402020-07-15 13:33:30 -07002800 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
Kiyoung Kim37693d02024-04-04 09:56:15 +09002801 crt)
Colin Cross21b9a242015-03-24 14:15:58 -07002802 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002803 if deps.DynamicLinker != "" {
2804 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002805 }
Dan Albert914449f2016-06-17 16:45:24 -07002806
2807 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002808
Colin Cross8acea3e2024-12-12 14:53:30 -08002809 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002810 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002811 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002812 {Mutator: "link", Variation: "shared"},
2813 }, ndkStubDepTag, variantNdkLibs...)
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002814 actx.AddVariationDependencies([]blueprint.Variation{
2815 {Mutator: "version", Variation: version},
2816 {Mutator: "link", Variation: "shared"},
2817 }, ndkStubDepTag, apiNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002818
Colin Cross8acea3e2024-12-12 14:53:30 -08002819 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002820 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002821 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002822 {Mutator: "link", Variation: "shared"},
2823 }, ndkLateStubDepTag, variantLateNdkLibs...)
Kiyoung Kimd5d1ab12022-11-28 16:47:10 +09002824 actx.AddVariationDependencies([]blueprint.Variation{
2825 {Mutator: "version", Variation: version},
2826 {Mutator: "link", Variation: "shared"},
2827 }, ndkLateStubDepTag, apiLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002828
Vinh Tran367d89d2023-04-28 11:21:25 -04002829 if len(deps.AidlLibs) > 0 {
2830 actx.AddDependency(
2831 c,
2832 aidlLibraryTag,
2833 deps.AidlLibs...,
2834 )
2835 }
2836
Colin Cross6362e272015-10-29 15:25:03 -07002837}
Colin Cross21b9a242015-03-24 14:15:58 -07002838
Colin Crosse40b4ea2018-10-02 22:25:58 -07002839func BeginMutator(ctx android.BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -07002840 if c, ok := ctx.Module().(*Module); ok && c.Enabled(ctx) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002841 c.beginMutator(ctx)
2842 }
2843}
2844
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002845// Whether a module can link to another module, taking into
2846// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002847func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002848 tag blueprint.DependencyTag) {
2849
2850 switch t := tag.(type) {
2851 case dependencyTag:
2852 if t != vndkExtDepTag {
2853 return
2854 }
2855 case libraryDependencyTag:
2856 default:
2857 return
2858 }
2859
Ivan Lozanof9e21722020-12-02 09:00:51 -05002860 if from.Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002861 // Host code is not restricted
2862 return
2863 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002864
Ivan Lozano52767be2019-10-18 14:49:46 -07002865 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002866 // Platform code can link to anything
2867 return
2868 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002869 if from.InRamdisk() {
2870 // Ramdisk code is not NDK
2871 return
2872 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002873 if from.InVendorRamdisk() {
2874 // Vendor ramdisk code is not NDK
2875 return
2876 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002877 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002878 // Recovery code is not NDK
2879 return
2880 }
Colin Cross31076b32020-10-23 17:22:06 -07002881 if c, ok := to.(*Module); ok {
Colin Cross31076b32020-10-23 17:22:06 -07002882 if c.StubDecorator() {
2883 // These aren't real libraries, but are the stub shared libraries that are included in
2884 // the NDK.
2885 return
2886 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002887 }
Logan Chien834b9a62019-01-14 15:39:03 +08002888
Ivan Lozano52767be2019-10-18 14:49:46 -07002889 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002890 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2891 // to link to libc++ (non-NDK and without sdk_version).
2892 return
2893 }
2894
Ivan Lozano52767be2019-10-18 14:49:46 -07002895 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002896 // NDK code linking to platform code is never okay.
2897 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002898 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002899 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002900 }
2901
2902 // At this point we know we have two NDK libraries, but we need to
2903 // check that we're not linking against anything built against a higher
2904 // API level, as it is only valid to link against older or equivalent
2905 // APIs.
2906
Inseob Kim01a28722018-04-11 09:48:45 +09002907 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002908 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002909 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002910 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002911 // Current can't be linked against by anything else.
2912 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002913 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002914 } else {
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002915 fromApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002916 if err != nil {
2917 ctx.PropertyErrorf("sdk_version",
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002918 "Invalid sdk_version value (must be int, preview or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002919 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002920 }
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002921 toApi, err := android.ApiLevelFromUserWithConfig(ctx.Config(), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002922 if err != nil {
2923 ctx.PropertyErrorf("sdk_version",
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002924 "Invalid sdk_version value (must be int, preview or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002925 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002926 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002927
Prashanth Swaminathan6dcbd9c2023-07-18 17:55:01 -07002928 if toApi.GreaterThan(fromApi) {
Inseob Kim01a28722018-04-11 09:48:45 +09002929 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002930 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002931 }
2932 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002933 }
Dan Albert202fe492017-12-15 13:56:59 -08002934
2935 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002936 fromStl := from.SelectedStl()
2937 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002938 if fromStl == "" || toStl == "" {
2939 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002940 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002941 // We can be permissive with the system "STL" since it is only the C++
2942 // ABI layer, but in the future we should make sure that everyone is
2943 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002944 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002945 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002946 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2947 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002948 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002949}
2950
Jooyung Han479ca172020-10-19 18:51:07 +09002951func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2952 if c, ok := ctx.Module().(*Module); ok {
2953 ctx.VisitDirectDeps(func(dep android.Module) {
2954 depTag := ctx.OtherModuleDependencyTag(dep)
2955 ccDep, ok := dep.(LinkableInterface)
2956 if ok {
2957 checkLinkType(ctx, c, ccDep, depTag)
2958 }
2959 })
2960 }
2961}
2962
Jiyong Park5fb8c102018-04-09 12:03:06 +09002963// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002964// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2965// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002966// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Colin Crossda279cf2024-09-17 14:25:45 -07002967func checkDoubleLoadableLibraries(ctx android.BottomUpMutatorContext) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002968 check := func(child, parent android.Module) bool {
2969 to, ok := child.(*Module)
2970 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002971 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002972 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002973
Jooyung Hana70f0672019-01-18 15:20:43 +09002974 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2975 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002976 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002977
Jiyong Park0474e1f2021-01-14 14:26:06 +09002978 // These dependencies are not excercised at runtime. Tracking these will give us
2979 // false negative, so skip.
Jiyong Park1ad8e162020-12-01 23:40:09 +09002980 depTag := ctx.OtherModuleDependencyTag(child)
2981 if IsHeaderDepTag(depTag) {
2982 return false
2983 }
Jiyong Park0474e1f2021-01-14 14:26:06 +09002984 if depTag == staticVariantTag {
2985 return false
2986 }
2987 if depTag == stubImplDepTag {
2988 return false
2989 }
Jiyong Park8bcf3c62024-03-18 18:37:10 +09002990 if depTag == android.RequiredDepTag {
2991 return false
2992 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002993
Justin Yun63e9ec72020-10-29 16:49:43 +09002994 // Even if target lib has no vendor variant, keep checking dependency
2995 // graph in case it depends on vendor_available or product_available
2996 // but not double_loadable transtively.
2997 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002998 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002999 }
Jooyung Hana70f0672019-01-18 15:20:43 +09003000
Jiyong Park0474e1f2021-01-14 14:26:06 +09003001 // The happy path. Keep tracking dependencies until we hit a non double-loadable
3002 // one.
3003 if Bool(to.VendorProperties.Double_loadable) {
3004 return true
3005 }
3006
Kiyoung Kim9f26fcf2024-05-27 17:25:52 +09003007 if to.IsLlndk() {
Jooyung Hana70f0672019-01-18 15:20:43 +09003008 return false
3009 }
3010
Jooyung Hana70f0672019-01-18 15:20:43 +09003011 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
3012 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
Jiyong Park0474e1f2021-01-14 14:26:06 +09003013 "Dependency list: %s", ctx.OtherModuleName(to), ctx.GetPathString(false))
Jooyung Hana70f0672019-01-18 15:20:43 +09003014 return false
3015 }
3016 if module, ok := ctx.Module().(*Module); ok {
3017 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jiyong Park0474e1f2021-01-14 14:26:06 +09003018 if lib.hasLLNDKStubs() {
Jooyung Hana70f0672019-01-18 15:20:43 +09003019 ctx.WalkDeps(check)
3020 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09003021 }
3022 }
3023}
3024
Yu Liue4312402023-01-18 09:15:31 -08003025func findApexSdkVersion(ctx android.BaseModuleContext, apexInfo android.ApexInfo) android.ApiLevel {
3026 // For the dependency from platform to apex, use the latest stubs
3027 apexSdkVersion := android.FutureApiLevel
3028 if !apexInfo.IsForPlatform() {
3029 apexSdkVersion = apexInfo.MinSdkVersion
3030 }
3031
3032 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
3033 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
3034 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
3035 // (b/144430859)
3036 apexSdkVersion = android.FutureApiLevel
3037 }
3038
3039 return apexSdkVersion
3040}
3041
Colin Crossc99deeb2016-04-11 15:06:20 -07003042// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07003043func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08003044 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08003045
Colin Cross0de8a1e2020-09-18 14:15:30 -07003046 var directStaticDeps []StaticLibraryInfo
3047 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07003048
Colin Cross0de8a1e2020-09-18 14:15:30 -07003049 reexportExporter := func(exporter FlagExporterInfo) {
3050 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
3051 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
3052 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
3053 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
3054 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09003055 }
3056
Colin Crossff694a82023-12-13 15:54:49 -08003057 apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
Yu Liue4312402023-01-18 09:15:31 -08003058 c.apexSdkVersion = findApexSdkVersion(ctx, apexInfo)
Jooyung Hande34d232020-07-23 13:04:15 +09003059
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003060 skipModuleList := map[string]bool{}
3061
Colin Crossd11fcda2017-10-23 17:59:01 -07003062 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003063 depName := ctx.OtherModuleName(dep)
3064 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07003065
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003066 if _, ok := skipModuleList[depName]; ok {
3067 // skip this module because original module or API imported module matching with this should be used instead.
3068 return
3069 }
3070
Dan Willemsen47450072021-10-19 20:24:49 -07003071 if depTag == android.DarwinUniversalVariantTag {
3072 depPaths.DarwinSecondArchOutput = dep.(*Module).OutputFile()
3073 return
3074 }
3075
Vinh Tran367d89d2023-04-28 11:21:25 -04003076 if depTag == aidlLibraryTag {
Colin Cross313aa542023-12-13 13:47:44 -08003077 if aidlLibraryInfo, ok := android.OtherModuleProvider(ctx, dep, aidl_library.AidlLibraryProvider); ok {
Vinh Tran367d89d2023-04-28 11:21:25 -04003078 depPaths.AidlLibraryInfos = append(
3079 depPaths.AidlLibraryInfos,
Colin Cross313aa542023-12-13 13:47:44 -08003080 aidlLibraryInfo,
Vinh Tran367d89d2023-04-28 11:21:25 -04003081 )
3082 }
3083 }
3084
Ivan Lozano52767be2019-10-18 14:49:46 -07003085 ccDep, ok := dep.(LinkableInterface)
3086 if !ok {
3087
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003088 // handling for a few module types that aren't cc Module but that are also supported
3089 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07003090 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003091 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07003092 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
3093 genRule.GeneratedSourceFiles()...)
3094 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003095 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07003096 }
Colin Crosse90bfd12017-04-26 16:59:26 -07003097 // Support exported headers from a generated_sources dependency
3098 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07003099 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003100 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09003101 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08003102 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09003103 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09003104 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003105 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09003106 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09003107 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
3108 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09003109 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07003110 // 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 +09003111 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07003112
Dan Willemsenb3454ab2016-09-28 17:34:58 -07003113 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07003114 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003115 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07003116 }
Colin Crosscef792e2021-06-11 18:01:26 -07003117 case CrtBeginDepTag:
3118 depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, ""))
3119 case CrtEndDepTag:
3120 depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, ""))
Colin Crossca860ac2016-01-04 14:34:37 -08003121 }
Colin Crossc99deeb2016-04-11 15:06:20 -07003122 return
3123 }
3124
Colin Crossfe17f6f2019-03-28 19:30:56 -07003125 if depTag == android.ProtoPluginDepTag {
3126 return
3127 }
3128
Jiyong Park8bcf3c62024-03-18 18:37:10 +09003129 if depTag == android.RequiredDepTag {
3130 return
3131 }
3132
Colin Crossd11fcda2017-10-23 17:59:01 -07003133 if dep.Target().Os != ctx.Os() {
Steven Morelandaaae81f2024-08-27 22:55:48 +00003134 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 -07003135 return
3136 }
Colin Crossd11fcda2017-10-23 17:59:01 -07003137 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00003138 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
3139 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07003140 return
3141 }
3142
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07003143 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07003144 // Skip reused objects for stub libraries, they use their own stub object file instead.
3145 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
3146 // version mutator, so the stubs variant is created from the shared variant that
3147 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07003148 if !c.library.buildStubs() {
Colin Cross313aa542023-12-13 13:47:44 -08003149 staticAnalogue, _ := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
Colin Crossa717db72020-10-23 14:53:06 -07003150 objs := staticAnalogue.ReuseObjects
3151 depPaths.Objs = depPaths.Objs.Append(objs)
Colin Cross313aa542023-12-13 13:47:44 -08003152 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
Colin Crossa717db72020-10-23 14:53:06 -07003153 reexportExporter(depExporterInfo)
3154 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003155 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09003156 }
3157
Hsin-Yi Chen715142a2024-03-27 16:31:16 +08003158 if depTag == llndkHeaderLibTag {
3159 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
3160 depPaths.LlndkIncludeDirs = append(depPaths.LlndkIncludeDirs, depExporterInfo.IncludeDirs...)
3161 depPaths.LlndkSystemIncludeDirs = append(depPaths.LlndkSystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
3162 }
3163
Colin Cross6e511a92020-07-27 21:26:48 -07003164 linkFile := ccDep.OutputFile()
3165
3166 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
3167 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07003168 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003169 return
3170 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08003171
Jiyong Parke3867542020-12-03 17:28:25 +09003172 if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
3173 return
3174 }
Jooyung Han9ffbe832023-11-28 22:31:35 +09003175 if apexInfo.IsForPlatform() && libDepTag.excludeInNonApex {
3176 return
3177 }
Jiyong Parke3867542020-12-03 17:28:25 +09003178
Colin Cross313aa542023-12-13 13:47:44 -08003179 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
Colin Crossc99deeb2016-04-11 15:06:20 -07003180
Colin Cross6e511a92020-07-27 21:26:48 -07003181 var ptr *android.Paths
3182 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07003183
Colin Cross6e511a92020-07-27 21:26:48 -07003184 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07003185
Colin Cross6e511a92020-07-27 21:26:48 -07003186 switch {
3187 case libDepTag.header():
Colin Cross313aa542023-12-13 13:47:44 -08003188 if _, isHeaderLib := android.OtherModuleProvider(ctx, dep, HeaderLibraryInfoProvider); !isHeaderLib {
Colin Cross649d8172020-12-10 12:30:21 -08003189 if !ctx.Config().AllowMissingDependencies() {
3190 ctx.ModuleErrorf("module %q is not a header library", depName)
3191 } else {
3192 ctx.AddMissingDependencies([]string{depName})
3193 }
3194 return
3195 }
Colin Cross6e511a92020-07-27 21:26:48 -07003196 case libDepTag.shared():
Colin Cross313aa542023-12-13 13:47:44 -08003197 if _, isSharedLib := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider); !isSharedLib {
Colin Cross0de8a1e2020-09-18 14:15:30 -07003198 if !ctx.Config().AllowMissingDependencies() {
3199 ctx.ModuleErrorf("module %q is not a shared library", depName)
3200 } else {
3201 ctx.AddMissingDependencies([]string{depName})
3202 }
3203 return
3204 }
Jiyong Parke3867542020-12-03 17:28:25 +09003205
Jiyong Park7d55b612021-06-11 17:22:09 +09003206 sharedLibraryInfo, returnedDepExporterInfo := ChooseStubOrImpl(ctx, dep)
3207 depExporterInfo = returnedDepExporterInfo
Colin Cross0de8a1e2020-09-18 14:15:30 -07003208
Jiyong Park1ad8e162020-12-01 23:40:09 +09003209 // Stubs lib doesn't link to the shared lib dependencies. Don't set
3210 // linkFile, depFile, and ptr.
3211 if c.IsStubs() {
3212 break
3213 }
3214
Colin Cross0de8a1e2020-09-18 14:15:30 -07003215 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
3216 depFile = sharedLibraryInfo.TableOfContents
3217
Colin Crossb614cd42024-10-11 12:52:21 -07003218 if !sharedLibraryInfo.IsStubs {
3219 depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, ""))
3220 if info, ok := android.OtherModuleProvider(ctx, dep, ImplementationDepInfoProvider); ok {
3221 depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps)
3222 }
3223 }
3224
Colin Cross6e511a92020-07-27 21:26:48 -07003225 ptr = &depPaths.SharedLibs
3226 switch libDepTag.Order {
3227 case earlyLibraryDependency:
3228 ptr = &depPaths.EarlySharedLibs
3229 depPtr = &depPaths.EarlySharedLibsDeps
3230 case normalLibraryDependency:
3231 ptr = &depPaths.SharedLibs
3232 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07003233 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07003234 case lateLibraryDependency:
3235 ptr = &depPaths.LateSharedLibs
3236 depPtr = &depPaths.LateSharedLibsDeps
3237 default:
3238 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07003239 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003240
Colin Cross6e511a92020-07-27 21:26:48 -07003241 case libDepTag.static():
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003242 if ccDep.RustLibraryInterface() {
3243 rlibDep := RustRlibDep{LibPath: linkFile.Path(), CrateName: ccDep.CrateName(), LinkDirs: ccDep.ExportedCrateLinkDirs()}
3244 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, rlibDep)
3245 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
3246 if libDepTag.wholeStatic {
3247 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, depExporterInfo.IncludeDirs...)
3248 depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, rlibDep)
Jiyong Park1ad8e162020-12-01 23:40:09 +09003249
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003250 // If whole_static, track this as we want to make sure that in a final linkage for a shared library,
3251 // exported functions from the rust generated staticlib still exported.
3252 if c.CcLibrary() && c.Shared() {
3253 c.WholeRustStaticlib = true
3254 }
Colin Cross6e511a92020-07-27 21:26:48 -07003255 }
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003256
Colin Cross6e511a92020-07-27 21:26:48 -07003257 } else {
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003258 staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
3259 if !isStaticLib {
3260 if !ctx.Config().AllowMissingDependencies() {
3261 ctx.ModuleErrorf("module %q is not a static library", depName)
3262 } else {
3263 ctx.AddMissingDependencies([]string{depName})
3264 }
3265 return
Inseob Kimeec88e12020-01-22 11:11:29 +09003266 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003267
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003268 // Stubs lib doesn't link to the static lib dependencies. Don't set
3269 // linkFile, depFile, and ptr.
3270 if c.IsStubs() {
3271 break
3272 }
Ivan Lozano0a468a42024-05-13 21:03:34 -04003273
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003274 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
3275 if libDepTag.wholeStatic {
3276 ptr = &depPaths.WholeStaticLibs
3277 if len(staticLibraryInfo.Objects.objFiles) > 0 {
3278 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
3279 } else {
3280 // This case normally catches prebuilt static
3281 // libraries, but it can also occur when
3282 // AllowMissingDependencies is on and the
3283 // dependencies has no sources of its own
3284 // but has a whole_static_libs dependency
3285 // on a missing library. We want to depend
3286 // on the .a file so that there is something
3287 // in the dependency tree that contains the
3288 // error rule for the missing transitive
3289 // dependency.
3290 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
3291 }
3292 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
3293 staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
3294 } else {
3295 switch libDepTag.Order {
3296 case earlyLibraryDependency:
3297 panic(fmt.Errorf("early static libs not supported"))
3298 case normalLibraryDependency:
3299 // static dependencies will be handled separately so they can be ordered
3300 // using transitive dependencies.
3301 ptr = nil
3302 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
3303 case lateLibraryDependency:
3304 ptr = &depPaths.LateStaticLibs
3305 default:
3306 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
3307 }
3308 }
3309
3310 // Collect any exported Rust rlib deps from static libraries which have been included as whole_static_libs
3311 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
3312
3313 if libDepTag.unexportedSymbols {
3314 depPaths.LdFlags = append(depPaths.LdFlags,
3315 "-Wl,--exclude-libs="+staticLibraryInfo.StaticLibrary.Base())
3316 }
Colin Cross3e5e7782022-06-17 22:17:05 +00003317 }
Inseob Kimeec88e12020-01-22 11:11:29 +09003318 }
3319
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003320 if libDepTag.static() && !libDepTag.wholeStatic && !ccDep.RustLibraryInterface() {
Colin Cross6e511a92020-07-27 21:26:48 -07003321 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
3322 ctx.ModuleErrorf("module %q not a static library", depName)
3323 return
3324 }
Logan Chien43d34c32017-12-20 01:17:32 +08003325
Colin Cross6e511a92020-07-27 21:26:48 -07003326 // When combining coverage files for shared libraries and executables, coverage files
3327 // in static libraries act as if they were whole static libraries. The same goes for
3328 // source based Abi dump files.
3329 if c, ok := ccDep.(*Module); ok {
3330 staticLib := c.linker.(libraryInterface)
3331 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
3332 staticLib.objs().coverageFiles...)
3333 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
3334 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003335 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07003336 // Handle non-CC modules here
3337 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07003338 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09003339 }
3340 }
3341
Colin Cross6e511a92020-07-27 21:26:48 -07003342 if ptr != nil {
3343 if !linkFile.Valid() {
3344 if !ctx.Config().AllowMissingDependencies() {
3345 ctx.ModuleErrorf("module %q missing output file", depName)
3346 } else {
3347 ctx.AddMissingDependencies([]string{depName})
3348 }
3349 return
3350 }
3351 *ptr = append(*ptr, linkFile.Path())
3352 }
3353
3354 if depPtr != nil {
3355 dep := depFile
3356 if !dep.Valid() {
3357 dep = linkFile
3358 }
3359 *depPtr = append(*depPtr, dep.Path())
3360 }
3361
Colin Cross0de8a1e2020-09-18 14:15:30 -07003362 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
3363 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
3364 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
3365 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003366 depPaths.RustRlibDeps = append(depPaths.RustRlibDeps, depExporterInfo.RustRlibDeps...)
3367
3368 // Only re-export RustRlibDeps for cc static libs
3369 if c.static() {
3370 depPaths.ReexportedRustRlibDeps = append(depPaths.ReexportedRustRlibDeps, depExporterInfo.RustRlibDeps...)
3371 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003372
3373 if libDepTag.reexportFlags {
3374 reexportExporter(depExporterInfo)
3375 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
3376 // Re-exported shared library headers must be included as well since they can help us with type information
3377 // about template instantiations (instantiated from their headers).
Colin Cross0de8a1e2020-09-18 14:15:30 -07003378 c.sabi.Properties.ReexportedIncludes = append(
3379 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
Hsin-Yi Chen5f228b02024-04-02 12:38:47 +08003380 c.sabi.Properties.ReexportedSystemIncludes = append(
3381 c.sabi.Properties.ReexportedSystemIncludes, depExporterInfo.SystemIncludeDirs.Strings()...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003382 }
3383
Spandan Das3faa7922024-02-26 19:42:32 +00003384 makeLibName := MakeLibName(ctx, c, ccDep, ccDep.BaseModuleName()) + libDepTag.makeSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003385 switch {
3386 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07003387 c.Properties.AndroidMkHeaderLibs = append(
3388 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07003389 case libDepTag.shared():
Colin Cross6e511a92020-07-27 21:26:48 -07003390 // Note: the order of libs in this list is not important because
3391 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07003392 c.Properties.AndroidMkSharedLibs = append(
3393 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07003394 case libDepTag.static():
Ivan Lozanofd47b1a2024-05-17 14:13:41 -04003395 if !ccDep.RustLibraryInterface() {
3396 if libDepTag.wholeStatic {
3397 c.Properties.AndroidMkWholeStaticLibs = append(
3398 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
3399 } else {
3400 c.Properties.AndroidMkStaticLibs = append(
3401 c.Properties.AndroidMkStaticLibs, makeLibName)
3402 }
Colin Cross6e511a92020-07-27 21:26:48 -07003403 }
3404 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09003405 } else if !c.IsStubs() {
3406 // Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
3407
Colin Cross6e511a92020-07-27 21:26:48 -07003408 switch depTag {
3409 case runtimeDepTag:
3410 c.Properties.AndroidMkRuntimeLibs = append(
Spandan Das3faa7922024-02-26 19:42:32 +00003411 c.Properties.AndroidMkRuntimeLibs, MakeLibName(ctx, c, ccDep, ccDep.BaseModuleName())+libDepTag.makeSuffix)
Colin Cross6e511a92020-07-27 21:26:48 -07003412 case objDepTag:
3413 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
3414 case CrtBeginDepTag:
Colin Crossc465efd2021-06-11 18:00:04 -07003415 depPaths.CrtBegin = append(depPaths.CrtBegin, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07003416 case CrtEndDepTag:
Colin Crossc465efd2021-06-11 18:00:04 -07003417 depPaths.CrtEnd = append(depPaths.CrtEnd, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07003418 case dynamicLinkerDepTag:
3419 depPaths.DynamicLinker = linkFile
3420 }
Jiyong Park27b188b2017-07-18 13:23:39 +09003421 }
Colin Crossca860ac2016-01-04 14:34:37 -08003422 })
3423
Jeff Gaston294356f2017-09-27 17:05:30 -07003424 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07003425 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
3426 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
3427 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07003428
Colin Crossdd84e052017-05-17 13:44:16 -07003429 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07003430 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09003431 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
3432 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09003433 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003434 depPaths.RustRlibDeps = android.FirstUniqueFunc(depPaths.RustRlibDeps, EqRustRlibDeps)
3435
Jiyong Park74955042019-10-22 20:19:51 +09003436 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
3437 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07003438 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09003439 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09003440 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Ivan Lozano0a468a42024-05-13 21:03:34 -04003441 depPaths.ReexportedRustRlibDeps = android.FirstUniqueFunc(depPaths.ReexportedRustRlibDeps, EqRustRlibDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07003442
3443 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09003444 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Hsin-Yi Chen5f228b02024-04-02 12:38:47 +08003445 c.sabi.Properties.ReexportedSystemIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedSystemIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07003446 }
Colin Crossdd84e052017-05-17 13:44:16 -07003447
Colin Crossca860ac2016-01-04 14:34:37 -08003448 return depPaths
3449}
3450
Spandan Das10c41362024-12-03 01:33:09 +00003451func ShouldUseStubForApex(ctx android.ModuleContext, parent, dep android.Module) bool {
Kiyoung Kimaa394802024-01-08 12:55:45 +09003452 inVendorOrProduct := false
Jiyong Park7d55b612021-06-11 17:22:09 +09003453 bootstrap := false
Spandan Das10c41362024-12-03 01:33:09 +00003454 if linkable, ok := parent.(LinkableInterface); !ok {
3455 ctx.ModuleErrorf("Not a Linkable module: %q", ctx.ModuleName())
Jiyong Park7d55b612021-06-11 17:22:09 +09003456 } else {
Kiyoung Kimaa394802024-01-08 12:55:45 +09003457 inVendorOrProduct = linkable.InVendorOrProduct()
Jiyong Park7d55b612021-06-11 17:22:09 +09003458 bootstrap = linkable.Bootstrap()
3459 }
3460
Spandan Das10c41362024-12-03 01:33:09 +00003461 apexInfo, _ := android.OtherModuleProvider(ctx, parent, android.ApexInfoProvider)
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003462
3463 useStubs := false
3464
Kiyoung Kimaa394802024-01-08 12:55:45 +09003465 if lib := moduleLibraryInterface(dep); lib.buildStubs() && inVendorOrProduct { // LLNDK
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003466 if !apexInfo.IsForPlatform() {
3467 // For platform libraries, use current version of LLNDK
3468 // If this is for use_vendor apex we will apply the same rules
3469 // of apex sdk enforcement below to choose right version.
3470 useStubs = true
3471 }
3472 } else if apexInfo.IsForPlatform() || apexInfo.UsePlatformApis {
3473 // If not building for APEX or the containing APEX allows the use of
3474 // platform APIs, use stubs only when it is from an APEX (and not from
3475 // platform) However, for host, ramdisk, vendor_ramdisk, recovery or
3476 // bootstrap modules, always link to non-stub variant
3477 isNotInPlatform := dep.(android.ApexModule).NotInPlatform()
3478
Spandan Dasff665182024-09-11 18:48:44 +00003479 useStubs = isNotInPlatform && !bootstrap
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003480 } else {
Colin Crossea91a172024-11-05 16:14:05 -08003481 // If building for APEX, always use stubs (can be bypassed by depending on <dep>#impl)
3482 useStubs = true
Kiyoung Kim76b06f32023-02-06 22:08:13 +09003483 }
3484
3485 return useStubs
3486}
3487
3488// ChooseStubOrImpl determines whether a given dependency should be redirected to the stub variant
3489// of the dependency or not, and returns the SharedLibraryInfo and FlagExporterInfo for the right
3490// dependency. The stub variant is selected when the dependency crosses a boundary where each side
3491// has different level of updatability. For example, if a library foo in an APEX depends on a
3492// library bar which provides stable interface and exists in the platform, foo uses the stub variant
3493// of bar. If bar doesn't provide a stable interface (i.e. buildStubs() == false) or is in the
3494// same APEX as foo, the non-stub variant of bar is used.
3495func ChooseStubOrImpl(ctx android.ModuleContext, dep android.Module) (SharedLibraryInfo, FlagExporterInfo) {
3496 depTag := ctx.OtherModuleDependencyTag(dep)
3497 libDepTag, ok := depTag.(libraryDependencyTag)
3498 if !ok || !libDepTag.shared() {
3499 panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
3500 }
3501
Colin Cross313aa542023-12-13 13:47:44 -08003502 sharedLibraryInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider)
3503 depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
3504 sharedLibraryStubsInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryStubsProvider)
Jiyong Park7d55b612021-06-11 17:22:09 +09003505
3506 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
Jiyong Park7d55b612021-06-11 17:22:09 +09003507 // when to use (unspecified) stubs, use the latest one.
Spandan Das10c41362024-12-03 01:33:09 +00003508 if ShouldUseStubForApex(ctx, ctx.Module(), dep) {
Jiyong Park7d55b612021-06-11 17:22:09 +09003509 stubs := sharedLibraryStubsInfo.SharedStubLibraries
3510 toUse := stubs[len(stubs)-1]
3511 sharedLibraryInfo = toUse.SharedLibraryInfo
3512 depExporterInfo = toUse.FlagExporterInfo
3513 }
3514 }
3515 return sharedLibraryInfo, depExporterInfo
3516}
3517
Colin Cross0de8a1e2020-09-18 14:15:30 -07003518// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
3519// to match the topological order of the dependency tree, including any static analogues of
Colin Crossa14fb6a2024-10-23 16:57:06 -07003520// direct shared libraries. It returns the ordered static dependencies, and a depset.DepSet
Colin Cross0de8a1e2020-09-18 14:15:30 -07003521// of the transitive dependencies.
Colin Crossa14fb6a2024-10-23 16:57:06 -07003522func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive depset.DepSet[android.Path]) {
3523 transitiveStaticLibsBuilder := depset.NewBuilder[android.Path](depset.TOPOLOGICAL)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003524 var staticPaths android.Paths
3525 for _, staticDep := range staticDeps {
3526 staticPaths = append(staticPaths, staticDep.StaticLibrary)
3527 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
3528 }
3529 for _, sharedDep := range sharedDeps {
Colin Crossa14fb6a2024-10-23 16:57:06 -07003530 transitiveStaticLibsBuilder.Transitive(sharedDep.TransitiveStaticLibrariesForOrdering)
Colin Cross0de8a1e2020-09-18 14:15:30 -07003531 }
3532 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
3533
3534 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
3535
3536 // reorder the dependencies based on transitive dependencies
3537 staticPaths = android.FirstUniquePaths(staticPaths)
3538 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
3539
3540 if len(orderedStaticPaths) != len(staticPaths) {
3541 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
3542 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
3543 }
3544
3545 return orderedStaticPaths, transitiveStaticLibs
3546}
3547
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003548// BaseLibName trims known prefixes and suffixes
3549func BaseLibName(depName string) string {
Colin Cross6e511a92020-07-27 21:26:48 -07003550 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
3551 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Paul Duffind23c7262020-12-11 18:13:08 +00003552 libName = android.RemoveOptionalPrebuiltPrefix(libName)
Colin Cross6e511a92020-07-27 21:26:48 -07003553 return libName
3554}
3555
Ivan Lozanoc08897c2021-04-02 12:41:32 -04003556func MakeLibName(ctx android.ModuleContext, c LinkableInterface, ccDep LinkableInterface, depName string) string {
Ivan Lozanod67a6b02021-05-20 13:01:32 -04003557 libName := BaseLibName(depName)
Colin Cross127bb8b2020-12-16 16:46:01 -08003558 ccDepModule, _ := ccDep.(*Module)
3559 isLLndk := ccDepModule != nil && ccDepModule.IsLlndk()
Justin Yuncbca3732021-02-03 19:24:13 +09003560 nonSystemVariantsExist := ccDep.HasNonSystemVariants() || isLLndk
Colin Cross6e511a92020-07-27 21:26:48 -07003561
Justin Yuncbca3732021-02-03 19:24:13 +09003562 if ccDepModule != nil {
Colin Cross6e511a92020-07-27 21:26:48 -07003563 // Use base module name for snapshots when exporting to Makefile.
Ivan Lozanod1dec542021-05-26 15:33:11 -04003564 if snapshotPrebuilt, ok := ccDepModule.linker.(SnapshotInterface); ok {
Justin Yuncbca3732021-02-03 19:24:13 +09003565 baseName := ccDepModule.BaseModuleName()
Colin Cross6e511a92020-07-27 21:26:48 -07003566
Ivan Lozanod1dec542021-05-26 15:33:11 -04003567 return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix()
Colin Cross6e511a92020-07-27 21:26:48 -07003568 }
3569 }
3570
Kiyoung Kim22152f62024-05-24 10:45:28 +09003571 if ccDep.InVendorOrProduct() && nonSystemVariantsExist {
Justin Yuncbca3732021-02-03 19:24:13 +09003572 // The vendor and product modules in Make will have been renamed to not conflict with the
3573 // core module, so update the dependency name here accordingly.
Ivan Lozanoc08897c2021-04-02 12:41:32 -04003574 return libName + ccDep.SubName()
Colin Cross6e511a92020-07-27 21:26:48 -07003575 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
Matthew Maurerc6868382021-07-13 14:12:37 -07003576 return libName + RamdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003577 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
Ivan Lozanoe6d30982021-02-05 10:57:43 -05003578 return libName + VendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003579 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Matthew Maurer460ee942021-02-11 12:31:46 -08003580 return libName + RecoverySuffix
Ivan Lozanof9e21722020-12-02 09:00:51 -05003581 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
Matthew Maurera61e31f2021-05-27 11:09:11 -07003582 return libName + NativeBridgeSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07003583 } else {
3584 return libName
3585 }
3586}
3587
Colin Crossca860ac2016-01-04 14:34:37 -08003588func (c *Module) InstallInData() bool {
3589 if c.installer == nil {
3590 return false
3591 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07003592 return c.installer.inData()
3593}
3594
3595func (c *Module) InstallInSanitizerDir() bool {
3596 if c.installer == nil {
3597 return false
3598 }
3599 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07003600 return true
3601 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07003602 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08003603}
3604
Yifan Hong1b3348d2020-01-21 15:53:22 -08003605func (c *Module) InstallInRamdisk() bool {
3606 return c.InRamdisk()
3607}
3608
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003609func (c *Module) InstallInVendorRamdisk() bool {
3610 return c.InVendorRamdisk()
3611}
3612
Jiyong Parkf9332f12018-02-01 00:54:12 +09003613func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07003614 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09003615}
3616
Jingwen Chen8ac7d7d2023-03-20 11:05:16 +00003617func (c *Module) MakeUninstallable() {
3618 if c.installer == nil {
3619 c.ModuleBase.MakeUninstallable()
3620 return
3621 }
3622 c.installer.makeUninstallable(c)
3623}
3624
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07003625func (c *Module) HostToolPath() android.OptionalPath {
3626 if c.installer == nil {
3627 return android.OptionalPath{}
3628 }
3629 return c.installer.hostToolPath()
3630}
3631
Nan Zhangd4e641b2017-07-12 12:55:28 -07003632func (c *Module) IntermPathForModuleOut() android.OptionalPath {
3633 return c.outputFile
3634}
3635
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00003636func (c *Module) static() bool {
3637 if static, ok := c.linker.(interface {
3638 static() bool
3639 }); ok {
3640 return static.static()
3641 }
3642 return false
3643}
3644
Colin Cross6a730042024-12-05 13:53:43 -08003645func (c *Module) staticLibrary() bool {
3646 if static, ok := c.linker.(interface {
3647 staticLibrary() bool
3648 }); ok {
3649 return static.staticLibrary()
3650 }
3651 return false
3652}
3653
Jiyong Park379de2f2018-12-19 02:47:14 +09003654func (c *Module) staticBinary() bool {
3655 if static, ok := c.linker.(interface {
3656 staticBinary() bool
3657 }); ok {
3658 return static.staticBinary()
3659 }
3660 return false
3661}
3662
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003663func (c *Module) testBinary() bool {
3664 if test, ok := c.linker.(interface {
3665 testBinary() bool
3666 }); ok {
3667 return test.testBinary()
3668 }
3669 return false
3670}
3671
Jingwen Chen537242c2022-08-24 11:53:27 +00003672func (c *Module) testLibrary() bool {
3673 if test, ok := c.linker.(interface {
3674 testLibrary() bool
3675 }); ok {
3676 return test.testLibrary()
3677 }
3678 return false
3679}
3680
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003681func (c *Module) benchmarkBinary() bool {
3682 if b, ok := c.linker.(interface {
3683 benchmarkBinary() bool
3684 }); ok {
3685 return b.benchmarkBinary()
3686 }
3687 return false
3688}
3689
3690func (c *Module) fuzzBinary() bool {
3691 if f, ok := c.linker.(interface {
3692 fuzzBinary() bool
3693 }); ok {
3694 return f.fuzzBinary()
3695 }
3696 return false
3697}
3698
Ivan Lozano3968d8f2020-12-14 11:27:52 -05003699// Header returns true if the module is a header-only variant. (See cc/library.go header()).
3700func (c *Module) Header() bool {
Jiyong Park1d1119f2019-07-29 21:27:18 +09003701 if h, ok := c.linker.(interface {
3702 header() bool
3703 }); ok {
3704 return h.header()
3705 }
3706 return false
3707}
3708
Ivan Lozanod7586b62021-04-01 09:49:36 -04003709func (c *Module) Binary() bool {
Inseob Kim7f283f42020-06-01 21:53:49 +09003710 if b, ok := c.linker.(interface {
3711 binary() bool
3712 }); ok {
3713 return b.binary()
3714 }
3715 return false
3716}
3717
Justin Yun5e035862021-06-29 20:50:37 +09003718func (c *Module) StaticExecutable() bool {
3719 if b, ok := c.linker.(*binaryDecorator); ok {
3720 return b.static()
3721 }
3722 return false
3723}
3724
Ivan Lozanod7586b62021-04-01 09:49:36 -04003725func (c *Module) Object() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09003726 if o, ok := c.linker.(interface {
3727 object() bool
3728 }); ok {
3729 return o.object()
3730 }
3731 return false
3732}
3733
Kiyoung Kim37693d02024-04-04 09:56:15 +09003734func (m *Module) Dylib() bool {
3735 return false
3736}
3737
3738func (m *Module) Rlib() bool {
3739 return false
3740}
3741
Ivan Lozanof9e21722020-12-02 09:00:51 -05003742func GetMakeLinkType(actx android.ModuleContext, c LinkableInterface) string {
Kiyoung Kim8487c0b2024-01-11 16:03:13 +09003743 if c.InVendorOrProduct() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003744 if c.IsLlndk() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003745 return "native:vndk"
Jooyung Han38002912019-05-16 04:01:54 +09003746 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003747 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003748 return "native:product"
3749 }
Jooyung Han38002912019-05-16 04:01:54 +09003750 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08003751 } else if c.InRamdisk() {
3752 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003753 } else if c.InVendorRamdisk() {
3754 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07003755 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07003756 return "native:recovery"
Ivan Lozanof9e21722020-12-02 09:00:51 -05003757 } else if c.Target().Os == android.Android && c.SdkVersion() != "" {
Colin Crossb60190a2018-09-04 16:28:17 -07003758 return "native:ndk:none:none"
3759 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
3760 //family, link := getNdkStlFamilyAndLinkType(c)
3761 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
3762 } else {
3763 return "native:platform"
3764 }
3765}
3766
Jiyong Park9d452992018-10-03 00:38:19 +09003767// Overrides ApexModule.IsInstallabeToApex()
Colin Cross3a02c7b2024-05-21 13:46:22 -07003768// Only shared/runtime libraries .
Jiyong Park9d452992018-10-03 00:38:19 +09003769func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07003770 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09003771 // Stub libs and prebuilt libs in a versioned SDK are not
3772 // installable to APEX even though they are shared libs.
Paul Duffin458a15b2022-11-25 12:18:24 +00003773 return lib.shared() && !lib.buildStubs()
Jiyong Park9d452992018-10-03 00:38:19 +09003774 }
3775 return false
3776}
3777
Jiyong Parka90ca002019-10-07 15:47:24 +09003778func (c *Module) AvailableFor(what string) bool {
Yu Liub73c3a62024-12-10 00:58:06 +00003779 return android.CheckAvailableForApex(what, c.ApexAvailableFor())
3780}
3781
3782func (c *Module) ApexAvailableFor() []string {
3783 list := c.ApexModuleBase.ApexAvailable()
Jiyong Parka90ca002019-10-07 15:47:24 +09003784 if linker, ok := c.linker.(interface {
Yu Liub73c3a62024-12-10 00:58:06 +00003785 apexAvailable() []string
Jiyong Parka90ca002019-10-07 15:47:24 +09003786 }); ok {
Yu Liub73c3a62024-12-10 00:58:06 +00003787 list = append(list, linker.apexAvailable()...)
Jiyong Parka90ca002019-10-07 15:47:24 +09003788 }
Yu Liub73c3a62024-12-10 00:58:06 +00003789
3790 return android.FirstUniqueStrings(list)
Jiyong Parka90ca002019-10-07 15:47:24 +09003791}
3792
Paul Duffin0cb37b92020-03-04 14:52:46 +00003793func (c *Module) EverInstallable() bool {
3794 return c.installer != nil &&
3795 // Check to see whether the module is actually ever installable.
3796 c.installer.everInstallable()
3797}
3798
Ivan Lozanod7586b62021-04-01 09:49:36 -04003799func (c *Module) PreventInstall() bool {
3800 return c.Properties.PreventInstall
3801}
3802
3803func (c *Module) Installable() *bool {
Colin Cross1bc94122021-10-28 13:25:54 -07003804 if c.library != nil {
3805 if i := c.library.installable(); i != nil {
3806 return i
3807 }
3808 }
Ivan Lozanod7586b62021-04-01 09:49:36 -04003809 return c.Properties.Installable
3810}
3811
3812func installable(c LinkableInterface, apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003813 ret := c.EverInstallable() &&
3814 // Check to see whether the module has been configured to not be installed.
Ivan Lozanod7586b62021-04-01 09:49:36 -04003815 proptools.BoolDefault(c.Installable(), true) &&
3816 !c.PreventInstall() && c.OutputFile().Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003817
3818 // The platform variant doesn't need further condition. Apex variants however might not
3819 // be installable because it will likely to be included in the APEX and won't appear
3820 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07003821 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003822 return ret
3823 }
3824
3825 // Special case for modules that are configured to be installed to /data, which includes
3826 // test modules. For these modules, both APEX and non-APEX variants are considered as
3827 // installable. This is because even the APEX variants won't be included in the APEX, but
3828 // will anyway be installed to /data/*.
3829 // See b/146995717
3830 if c.InstallInData() {
3831 return ret
3832 }
3833
3834 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003835}
3836
Logan Chien41eabe62019-04-10 13:33:58 +08003837func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3838 if c.linker != nil {
3839 if library, ok := c.linker.(*libraryDecorator); ok {
3840 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3841 }
3842 }
3843}
3844
Jiyong Park45bf82e2020-12-15 22:29:02 +09003845var _ android.ApexModule = (*Module)(nil)
3846
3847// Implements android.ApexModule
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003848func (c *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
Colin Crossc1b36442021-05-06 13:42:48 -07003849 if depTag == stubImplDepTag {
3850 // We don't track from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003851 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003852 }
Jiyong Park12177fc2021-01-05 14:37:15 +09003853 if depTag == staticVariantTag {
3854 // This dependency is for optimization (reuse *.o from the static lib). It doesn't
3855 // actually mean that the static lib (and its dependencies) are copied into the
3856 // APEX.
3857 return false
3858 }
Colin Cross8acea3e2024-12-12 14:53:30 -08003859
3860 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3861 if isLibDepTag && c.static() && libDepTag.shared() {
3862 // shared_lib dependency from a static lib is considered as crossing
3863 // the APEX boundary because the dependency doesn't actually is
3864 // linked; the dependency is used only during the compilation phase.
3865 return false
3866 }
3867
3868 if isLibDepTag && libDepTag.excludeInApex {
3869 return false
3870 }
3871
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003872 return true
3873}
3874
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003875func (c *Module) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool {
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003876 if c.HasStubsVariants() {
3877 if IsSharedDepTag(depTag) {
3878 // dynamic dep to a stubs lib crosses APEX boundary
3879 return false
3880 }
3881 if IsRuntimeDepTag(depTag) {
3882 // runtime dep to a stubs lib also crosses APEX boundary
3883 return false
3884 }
3885 if IsHeaderDepTag(depTag) {
3886 return false
3887 }
3888 }
3889 if c.IsLlndk() {
3890 return false
3891 }
Colin Crossf7bbd2f2024-12-05 13:57:10 -08003892
3893 return true
3894}
3895
Jiyong Park45bf82e2020-12-15 22:29:02 +09003896// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003897func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3898 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003899 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3900 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3901 return nil
3902 }
Jooyung Han749dc692020-04-15 11:03:39 +09003903 // We don't check for prebuilt modules
3904 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3905 return nil
3906 }
Kiyoung Kim487689e2022-07-26 09:48:22 +09003907
Jooyung Han749dc692020-04-15 11:03:39 +09003908 minSdkVersion := c.MinSdkVersion()
3909 if minSdkVersion == "apex_inherit" {
3910 return nil
3911 }
3912 if minSdkVersion == "" {
3913 // JNI libs within APK-in-APEX fall into here
3914 // Those are okay to set sdk_version instead
3915 // We don't have to check if this is a SDK variant because
3916 // non-SDK variant resets sdk_version, which works too.
3917 minSdkVersion = c.SdkVersion()
3918 }
Dan Albertc8060532020-07-22 22:32:17 -07003919 if minSdkVersion == "" {
3920 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3921 }
3922 // Not using nativeApiLevelFromUser because the context here is not
3923 // necessarily a native context.
3924 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003925 if err != nil {
3926 return err
3927 }
Dan Albertc8060532020-07-22 22:32:17 -07003928
Colin Cross8ca61c12022-10-06 21:00:14 -07003929 // A dependency only needs to support a min_sdk_version at least
3930 // as high as the api level that the architecture was introduced in.
3931 // This allows introducing new architectures in the platform that
3932 // need to be included in apexes that normally require an older
3933 // min_sdk_version.
Colin Crossbb137a32023-01-26 09:54:42 -08003934 minApiForArch := MinApiForArch(ctx, c.Target().Arch.ArchType)
Colin Cross8ca61c12022-10-06 21:00:14 -07003935 if sdkVersion.LessThan(minApiForArch) {
3936 sdkVersion = minApiForArch
3937 }
3938
Dan Albertc8060532020-07-22 22:32:17 -07003939 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003940 return fmt.Errorf("newer SDK(%v)", ver)
3941 }
3942 return nil
3943}
3944
Paul Duffinb5769c12021-05-12 16:16:51 +01003945// Implements android.ApexModule
3946func (c *Module) AlwaysRequiresPlatformApexVariant() bool {
3947 // stub libraries and native bridge libraries are always available to platform
3948 return c.IsStubs() || c.Target().NativeBridge == android.NativeBridgeEnabled
3949}
3950
Inseob Kima1888ce2022-10-04 14:42:02 +09003951func (c *Module) overriddenModules() []string {
3952 if o, ok := c.linker.(overridable); ok {
3953 return o.overriddenModules()
3954 }
3955 return nil
3956}
3957
Liz Kammer35ca77e2021-12-22 15:31:40 -05003958type moduleType int
3959
3960const (
3961 unknownType moduleType = iota
3962 binary
3963 object
3964 fullLibrary
3965 staticLibrary
3966 sharedLibrary
3967 headerLibrary
Jingwen Chen537242c2022-08-24 11:53:27 +00003968 testBin // testBinary already declared
Spandan Das1278c2c2022-08-19 18:17:28 +00003969 ndkLibrary
Liz Kammer35ca77e2021-12-22 15:31:40 -05003970)
3971
3972func (c *Module) typ() moduleType {
Jingwen Chen537242c2022-08-24 11:53:27 +00003973 if c.testBinary() {
3974 // testBinary is also a binary, so this comes before the c.Binary()
3975 // conditional. A testBinary has additional implicit dependencies and
3976 // other test-only semantics.
3977 return testBin
3978 } else if c.Binary() {
Liz Kammer35ca77e2021-12-22 15:31:40 -05003979 return binary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003980 } else if c.Object() {
Liz Kammer35ca77e2021-12-22 15:31:40 -05003981 return object
Jingwen Chen537242c2022-08-24 11:53:27 +00003982 } else if c.testLibrary() {
3983 // TODO(b/244431896) properly convert cc_test_library to its own macro. This
3984 // will let them add implicit compile deps on gtest, for example.
3985 //
Liz Kammerefc51d92023-04-21 15:11:25 -04003986 // For now, treat them as regular libraries.
3987 return fullLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003988 } else if c.CcLibrary() {
Chris Parsons58852a02021-12-09 18:10:18 -05003989 static := false
3990 shared := false
3991 if library, ok := c.linker.(*libraryDecorator); ok {
3992 static = library.MutatedProperties.BuildStatic
3993 shared = library.MutatedProperties.BuildShared
3994 } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
3995 static = library.MutatedProperties.BuildStatic
3996 shared = library.MutatedProperties.BuildShared
3997 }
Liz Kammerbe46fcc2021-11-01 15:32:43 -04003998 if static && shared {
Liz Kammer35ca77e2021-12-22 15:31:40 -05003999 return fullLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04004000 } else if !static && !shared {
Liz Kammer35ca77e2021-12-22 15:31:40 -05004001 return headerLibrary
Liz Kammerbe46fcc2021-11-01 15:32:43 -04004002 } else if static {
Liz Kammer35ca77e2021-12-22 15:31:40 -05004003 return staticLibrary
4004 }
4005 return sharedLibrary
Spandan Das1278c2c2022-08-19 18:17:28 +00004006 } else if c.isNDKStubLibrary() {
4007 return ndkLibrary
Liz Kammer35ca77e2021-12-22 15:31:40 -05004008 }
4009 return unknownType
4010}
4011
Colin Crosscfad1192015-11-02 16:43:11 -08004012// Defaults
Colin Crossca860ac2016-01-04 14:34:37 -08004013type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07004014 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07004015 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09004016 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08004017}
4018
Patrice Arrudac249c712019-03-19 17:00:29 -07004019// cc_defaults provides a set of properties that can be inherited by other cc
4020// modules. A module can use the properties from a cc_defaults using
4021// `defaults: ["<:default_module_name>"]`. Properties of both modules are
4022// merged (when possible) by prepending the default module's values to the
4023// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07004024func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07004025 return DefaultsFactory()
4026}
4027
Colin Cross36242852017-06-23 15:06:31 -07004028func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08004029 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08004030
Colin Cross36242852017-06-23 15:06:31 -07004031 module.AddProperties(props...)
4032 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08004033 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07004034 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004035 &BaseCompilerProperties{},
4036 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01004037 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07004038 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07004039 &StaticProperties{},
4040 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07004041 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004042 &BinaryLinkerProperties{},
Trevor Radcliffef389cb42022-03-24 21:06:14 +00004043 &TestLinkerProperties{},
4044 &TestInstallerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07004045 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07004046 &BenchmarkProperties{},
hamzehc0a671f2021-07-22 12:05:08 -07004047 &fuzz.FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08004048 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08004049 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07004050 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07004051 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07004052 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08004053 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08004054 &SAbiProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07004055 &LTOProperties{},
Yi Kongeb8efc92021-12-09 18:06:29 +08004056 &AfdoProperties{},
Sharjeel Khanc6a93d82023-07-18 21:01:11 +00004057 &OrderfileProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08004058 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04004059 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
4060 &RustBindgenClangProperties{},
Yu-Chi Cheng24b2b0f2021-06-23 15:56:39 -07004061 &prebuiltLinkerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07004062 )
Colin Crosscfad1192015-11-02 16:43:11 -08004063
Jooyung Hancc372c52019-09-25 15:18:44 +09004064 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07004065
4066 return module
Colin Crosscfad1192015-11-02 16:43:11 -08004067}
4068
Jiyong Park2286afd2020-06-16 21:58:53 +09004069func (c *Module) IsSdkVariant() bool {
Lukacs T. Berki2063a0d2021-06-17 09:32:36 +02004070 return c.Properties.IsSdkVariant
Jiyong Park2286afd2020-06-16 21:58:53 +09004071}
4072
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004073func kytheExtractAllFactory() android.Singleton {
4074 return &kytheExtractAllSingleton{}
4075}
4076
4077type kytheExtractAllSingleton struct {
4078}
4079
4080func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
4081 var xrefTargets android.Paths
Yu Liuec7043d2024-11-05 18:22:20 +00004082 ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
4083 files := android.OtherModuleProviderOrDefault(ctx, module, CcObjectInfoProvider).kytheFiles
4084 if len(files) > 0 {
4085 xrefTargets = append(xrefTargets, files...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004086 }
4087 })
4088 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
4089 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07004090 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08004091 }
4092}
4093
Jihoon Kangf78a8902022-09-01 22:47:07 +00004094func (c *Module) Partition() string {
4095 if p, ok := c.installer.(interface {
4096 getPartition() string
4097 }); ok {
4098 return p.getPartition()
4099 }
4100 return ""
4101}
4102
Spandan Das2b6dfb52024-01-19 00:22:22 +00004103type sourceModuleName interface {
4104 sourceModuleName() string
4105}
4106
4107func (c *Module) BaseModuleName() string {
4108 if smn, ok := c.linker.(sourceModuleName); ok && smn.sourceModuleName() != "" {
4109 // if the prebuilt module sets a source_module_name in Android.bp, use that
4110 return smn.sourceModuleName()
4111 }
4112 return c.ModuleBase.BaseModuleName()
4113}
4114
Spandan Dase20c56c2024-07-23 21:34:24 +00004115func (c *Module) stubsSymbolFilePath() android.Path {
4116 if library, ok := c.linker.(*libraryDecorator); ok {
4117 return library.stubsSymbolFilePath
4118 }
4119 return android.OptionalPath{}.Path()
4120}
4121
Colin Cross06a931b2015-10-28 17:23:31 -07004122var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07004123var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08004124var BoolPtr = proptools.BoolPtr
4125var String = proptools.String
4126var StringPtr = proptools.StringPtr