Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 2 | // |
| 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 | |
| 15 | package 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 | |
| 21 | import ( |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 22 | "fmt" |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 23 | "io" |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 24 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 25 | "strings" |
| 26 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint" |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 29 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 30 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 31 | "android/soong/cc/config" |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 32 | "android/soong/genrule" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 33 | ) |
| 34 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 35 | func init() { |
Paul Duffin | 036e700 | 2019-12-19 19:16:28 +0000 | [diff] [blame] | 36 | RegisterCCBuildComponents(android.InitRegistrationContext) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 37 | |
Paul Duffin | 036e700 | 2019-12-19 19:16:28 +0000 | [diff] [blame] | 38 | pctx.Import("android/soong/cc/config") |
| 39 | } |
| 40 | |
| 41 | func RegisterCCBuildComponents(ctx android.RegistrationContext) { |
| 42 | ctx.RegisterModuleType("cc_defaults", defaultsFactory) |
| 43 | |
| 44 | ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 45 | ctx.BottomUp("sdk", sdkMutator).Parallel() |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 46 | ctx.BottomUp("vndk", VndkMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 47 | ctx.BottomUp("link", LinkageMutator).Parallel() |
Jooyung Han | b90e491 | 2019-12-09 18:21:48 +0900 | [diff] [blame] | 48 | ctx.BottomUp("ndk_api", NdkApiMutator).Parallel() |
Roland Levillain | 9b5fde9 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 49 | ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel() |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 50 | ctx.BottomUp("version_selector", versionSelectorMutator).Parallel() |
| 51 | ctx.BottomUp("version", versionMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 52 | ctx.BottomUp("begin", BeginMutator).Parallel() |
Inseob Kim | ac1e986 | 2019-12-09 18:15:47 +0900 | [diff] [blame] | 53 | ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 54 | ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel() |
| 55 | ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 56 | }) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 57 | |
Paul Duffin | 036e700 | 2019-12-19 19:16:28 +0000 | [diff] [blame] | 58 | ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 59 | ctx.TopDown("asan_deps", sanitizerDepsMutator(asan)) |
| 60 | ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel() |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 61 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 62 | ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan)) |
| 63 | ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel() |
| 64 | |
Mitch Phillips | bfeade6 | 2019-05-01 14:42:05 -0700 | [diff] [blame] | 65 | ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer)) |
| 66 | ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel() |
| 67 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 68 | // cfi mutator shouldn't run before sanitizers that return true for |
| 69 | // incompatibleWithCfi() |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 70 | ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi)) |
| 71 | ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel() |
| 72 | |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 73 | ctx.TopDown("scs_deps", sanitizerDepsMutator(scs)) |
| 74 | ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel() |
| 75 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 76 | ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan)) |
| 77 | ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel() |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 78 | |
Colin Cross | 0b90833 | 2019-06-19 23:00:20 -0700 | [diff] [blame] | 79 | ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel() |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 80 | ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel() |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 81 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 82 | ctx.BottomUp("coverage", coverageMutator).Parallel() |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 83 | ctx.TopDown("vndk_deps", sabiDepsMutator) |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 84 | |
| 85 | ctx.TopDown("lto_deps", ltoDepsMutator) |
| 86 | ctx.BottomUp("lto", ltoMutator).Parallel() |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 87 | |
| 88 | ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 89 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 90 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 91 | android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 94 | type Deps struct { |
| 95 | SharedLibs, LateSharedLibs []string |
| 96 | StaticLibs, LateStaticLibs, WholeStaticLibs []string |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 97 | HeaderLibs []string |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 98 | RuntimeLibs []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 99 | |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 100 | // Used for data dependencies adjacent to tests |
| 101 | DataLibs []string |
| 102 | |
Yo Chiang | 219968c | 2020-09-22 18:45:04 +0800 | [diff] [blame] | 103 | // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py. |
| 104 | SystemSharedLibs []string |
| 105 | |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 106 | StaticUnwinderIfLegacy bool |
| 107 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 108 | ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 109 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 110 | ObjFiles []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 111 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 112 | GeneratedSources []string |
| 113 | GeneratedHeaders []string |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 114 | GeneratedDeps []string |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 115 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 116 | ReexportGeneratedHeaders []string |
| 117 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 118 | CrtBegin, CrtEnd string |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 119 | |
| 120 | // Used for host bionic |
| 121 | LinkerFlagsFile string |
| 122 | DynamicLinker string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 125 | type PathDeps struct { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 126 | // Paths to .so files |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 127 | SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 128 | // Paths to the dependencies to use for .so files (.so.toc files) |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 129 | SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 130 | // Paths to .a files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 131 | StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 132 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 133 | // Paths to .o files |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 134 | Objs Objects |
| 135 | // Paths to .o files in dependencies that provide them. Note that these lists |
| 136 | // aren't complete since prebuilt modules don't provide the .o files. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 137 | StaticLibObjs Objects |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 138 | WholeStaticLibObjs Objects |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 139 | |
Martin Stjernholm | 391d94c | 2020-04-17 17:34:31 +0100 | [diff] [blame] | 140 | // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain |
| 141 | // the libs from all whole_static_lib dependencies. |
| 142 | WholeStaticLibsFromPrebuilts android.Paths |
| 143 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 144 | // Paths to generated source files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 145 | GeneratedSources android.Paths |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 146 | GeneratedDeps android.Paths |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 147 | |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 148 | Flags []string |
| 149 | IncludeDirs android.Paths |
| 150 | SystemIncludeDirs android.Paths |
| 151 | ReexportedDirs android.Paths |
| 152 | ReexportedSystemDirs android.Paths |
| 153 | ReexportedFlags []string |
| 154 | ReexportedGeneratedHeaders android.Paths |
| 155 | ReexportedDeps android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 156 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 157 | // Paths to crt*.o files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 158 | CrtBegin, CrtEnd android.OptionalPath |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 159 | |
| 160 | // Path to the file container flags to use with the linker |
| 161 | LinkerFlagsFile android.OptionalPath |
| 162 | |
| 163 | // Path to the dynamic linker binary |
| 164 | DynamicLinker android.OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 167 | // LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module |
| 168 | // tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the |
| 169 | // command line so they can be overridden by the local module flags). |
| 170 | type LocalOrGlobalFlags struct { |
| 171 | CommonFlags []string // Flags that apply to C, C++, and assembly source files |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 172 | AsFlags []string // Flags that apply to assembly source files |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 173 | YasmFlags []string // Flags that apply to yasm assembly source files |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 174 | CFlags []string // Flags that apply to C and C++ source files |
| 175 | ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools |
| 176 | ConlyFlags []string // Flags that apply to C source files |
| 177 | CppFlags []string // Flags that apply to C++ source files |
| 178 | ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 179 | LdFlags []string // Flags that apply to linker command lines |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | type Flags struct { |
| 183 | Local LocalOrGlobalFlags |
| 184 | Global LocalOrGlobalFlags |
| 185 | |
| 186 | aidlFlags []string // Flags that apply to aidl source files |
| 187 | rsFlags []string // Flags that apply to renderscript source files |
| 188 | libFlags []string // Flags to add libraries early to the link order |
| 189 | extraLibFlags []string // Flags to add libraries late in the link order after LdFlags |
| 190 | TidyFlags []string // Flags that apply to clang-tidy |
| 191 | SAbiFlags []string // Flags that apply to header-abi-dumper |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 192 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 193 | // Global include flags that apply to C, C++, and assembly source files |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 194 | // These must be after any module include flags, which will be in CommonFlags. |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 195 | SystemIncludeFlags []string |
| 196 | |
Oliver Nguyen | 0452678 | 2020-04-21 12:40:27 -0700 | [diff] [blame] | 197 | Toolchain config.Toolchain |
| 198 | Tidy bool |
| 199 | GcovCoverage bool |
| 200 | SAbiDump bool |
| 201 | EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 202 | |
| 203 | RequiredInstructionSet string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 204 | DynamicLinker string |
| 205 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 206 | CFlagsDeps android.Paths // Files depended on by compiler flags |
| 207 | LdFlagsDeps android.Paths // Files depended on by linker flags |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 208 | |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 209 | AssemblerWithCpp bool |
| 210 | GroupStaticLibs bool |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 211 | |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 212 | proto android.ProtoFlags |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 213 | protoC bool // Whether to use C instead of C++ |
| 214 | protoOptionsFile bool // Whether to look for a .options file next to the .proto |
Dan Willemsen | 4e0aa23 | 2019-04-10 22:59:54 -0700 | [diff] [blame] | 215 | |
| 216 | Yacc *YaccProperties |
Matthias Maennich | 22fd4d1 | 2020-07-15 10:58:56 +0200 | [diff] [blame] | 217 | Lex *LexProperties |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 220 | // Properties used to compile all C or C++ modules |
| 221 | type BaseProperties struct { |
Dan Willemsen | 742a545 | 2018-07-23 17:19:36 -0700 | [diff] [blame] | 222 | // Deprecated. true is the default, false is invalid. |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 223 | Clang *bool `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 224 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 225 | // Minimum sdk version supported when compiling against the ndk. Setting this property causes |
| 226 | // two variants to be built, one for the platform and one for apps. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 227 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 228 | |
Jooyung Han | 379660c | 2020-04-21 15:24:00 +0900 | [diff] [blame] | 229 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 230 | Min_sdk_version *string |
| 231 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 232 | // If true, always create an sdk variant and don't create a platform variant. |
| 233 | Sdk_variant_only *bool |
| 234 | |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 235 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
| 236 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
| 237 | AndroidMkRuntimeLibs []string `blueprint:"mutated"` |
| 238 | AndroidMkWholeStaticLibs []string `blueprint:"mutated"` |
Bill Peckham | a46de70 | 2020-04-21 17:23:37 -0700 | [diff] [blame] | 239 | AndroidMkHeaderLibs []string `blueprint:"mutated"` |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 240 | HideFromMake bool `blueprint:"mutated"` |
| 241 | PreventInstall bool `blueprint:"mutated"` |
| 242 | ApexesProvidingSharedLibs []string `blueprint:"mutated"` |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 243 | |
Yo Chiang | 219968c | 2020-09-22 18:45:04 +0800 | [diff] [blame] | 244 | // Set by DepsMutator. |
| 245 | AndroidMkSystemSharedLibs []string `blueprint:"mutated"` |
| 246 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 247 | ImageVariationPrefix string `blueprint:"mutated"` |
| 248 | VndkVersion string `blueprint:"mutated"` |
| 249 | SubName string `blueprint:"mutated"` |
Colin Cross | 5beccee | 2017-12-07 15:28:59 -0800 | [diff] [blame] | 250 | |
| 251 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 252 | // file |
| 253 | Logtags []string |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 254 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 255 | // Make this module available when building for ramdisk |
| 256 | Ramdisk_available *bool |
| 257 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 258 | // Make this module available when building for recovery |
| 259 | Recovery_available *bool |
| 260 | |
Colin Cross | ae6c520 | 2019-11-20 13:35:50 -0800 | [diff] [blame] | 261 | // Set by imageMutator |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 262 | CoreVariantNeeded bool `blueprint:"mutated"` |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 263 | RamdiskVariantNeeded bool `blueprint:"mutated"` |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 264 | RecoveryVariantNeeded bool `blueprint:"mutated"` |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 265 | ExtraVariants []string `blueprint:"mutated"` |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 266 | |
| 267 | // Allows this module to use non-APEX version of libraries. Useful |
| 268 | // for building binaries that are started before APEXes are activated. |
| 269 | Bootstrap *bool |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 270 | |
| 271 | // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant. |
| 272 | // see soong/cc/config/vndk.go |
| 273 | MustUseVendorVariant bool `blueprint:"mutated"` |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 274 | |
| 275 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 276 | SnapshotSharedLibs []string `blueprint:"mutated"` |
| 277 | SnapshotRuntimeLibs []string `blueprint:"mutated"` |
Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 278 | |
| 279 | Installable *bool |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 280 | |
| 281 | // Set by factories of module types that can only be referenced from variants compiled against |
| 282 | // the SDK. |
| 283 | AlwaysSdk bool `blueprint:"mutated"` |
| 284 | |
| 285 | // Variant is an SDK variant created by sdkMutator |
| 286 | IsSdkVariant bool `blueprint:"mutated"` |
| 287 | // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK |
| 288 | // variant to have a ".sdk" suffix. |
| 289 | SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"` |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 290 | |
| 291 | // Normally Soong uses the directory structure to decide which modules |
| 292 | // should be included (framework) or excluded (non-framework) from the |
| 293 | // vendor snapshot, but this property allows a partner to exclude a |
| 294 | // module normally thought of as a framework module from the vendor |
| 295 | // snapshot. |
| 296 | Exclude_from_vendor_snapshot *bool |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | type VendorProperties struct { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 300 | // whether this module should be allowed to be directly depended by other |
| 301 | // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`. |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 302 | // In addition, this module should be allowed to be directly depended by |
| 303 | // product modules with `product_specific: true`. |
| 304 | // If set to true, three variants will be built separately, one like |
| 305 | // normal, another limited to the set of libraries and headers |
| 306 | // that are exposed to /vendor modules, and the other to /product modules. |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 307 | // |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 308 | // The vendor and product variants may be used with a different (newer) /system, |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 309 | // so it shouldn't have any unversioned runtime dependencies, or |
| 310 | // make assumptions about the system that may not be true in the |
| 311 | // future. |
| 312 | // |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 313 | // If set to false, this module becomes inaccessible from /vendor or /product |
| 314 | // modules. |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 315 | // |
| 316 | // Default value is true when vndk: {enabled: true} or vendor: true. |
| 317 | // |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 318 | // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 319 | // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used. |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 320 | Vendor_available *bool |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 321 | |
| 322 | // whether this module is capable of being loaded with other instance |
| 323 | // (possibly an older version) of the same module in the same process. |
| 324 | // Currently, a shared library that is a member of VNDK (vndk: {enabled: true}) |
| 325 | // can be double loaded in a vendor process if the library is also a |
| 326 | // (direct and indirect) dependency of an LLNDK library. Such libraries must be |
| 327 | // explicitly marked as `double_loadable: true` by the owner, or the dependency |
| 328 | // from the LLNDK lib should be cut if the lib is not designed to be double loaded. |
| 329 | Double_loadable *bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 332 | type ModuleContextIntf interface { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 333 | static() bool |
| 334 | staticBinary() bool |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 335 | header() bool |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 336 | binary() bool |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 337 | object() bool |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 338 | toolchain() config.Toolchain |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 339 | canUseSdk() bool |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 340 | useSdk() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 341 | sdkVersion() string |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 342 | useVndk() bool |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 343 | isNdk() bool |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 344 | isLlndk(config android.Config) bool |
| 345 | isLlndkPublic(config android.Config) bool |
| 346 | isVndkPrivate(config android.Config) bool |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 347 | isVndk() bool |
| 348 | isVndkSp() bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 349 | isVndkExt() bool |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 350 | inProduct() bool |
| 351 | inVendor() bool |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 352 | inRamdisk() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 353 | inRecovery() bool |
Hsin-Yi Chen | af17d74 | 2019-07-29 17:46:59 +0800 | [diff] [blame] | 354 | shouldCreateSourceAbiDump() bool |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 355 | selectedStl() string |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 356 | baseModuleName() string |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 357 | getVndkExtendsModuleName() string |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 358 | isPgoCompile() bool |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 359 | isNDKStubLibrary() bool |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 360 | useClangLld(actx ModuleContext) bool |
Logan Chien | e274fc9 | 2019-12-03 11:18:32 -0800 | [diff] [blame] | 361 | isForPlatform() bool |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 362 | apexVariationName() string |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 363 | apexSdkVersion() android.ApiLevel |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 364 | hasStubsVariants() bool |
| 365 | isStubs() bool |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 366 | bootstrap() bool |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 367 | mustUseVendorVariant() bool |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 368 | nativeCoverage() bool |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 369 | directlyInAnyApex() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | type ModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 373 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 374 | ModuleContextIntf |
| 375 | } |
| 376 | |
| 377 | type BaseModuleContext interface { |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 378 | android.BaseModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 379 | ModuleContextIntf |
| 380 | } |
| 381 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 382 | type DepsContext interface { |
| 383 | android.BottomUpMutatorContext |
| 384 | ModuleContextIntf |
| 385 | } |
| 386 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 387 | type feature interface { |
| 388 | begin(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 389 | deps(ctx DepsContext, deps Deps) Deps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 390 | flags(ctx ModuleContext, flags Flags) Flags |
| 391 | props() []interface{} |
| 392 | } |
| 393 | |
| 394 | type compiler interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 395 | compilerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 396 | compilerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 397 | compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 398 | compilerProps() []interface{} |
| 399 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 400 | appendCflags([]string) |
| 401 | appendAsflags([]string) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 402 | compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | type linker interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 406 | linkerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 407 | linkerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 408 | linkerFlags(ctx ModuleContext, flags Flags) Flags |
| 409 | linkerProps() []interface{} |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 410 | useClangLld(actx ModuleContext) bool |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 411 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 412 | link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 413 | appendLdflags([]string) |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 414 | unstrippedOutputFilePath() android.Path |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 415 | |
| 416 | nativeCoverage() bool |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 417 | coverageOutputFilePath() android.OptionalPath |
Paul Duffin | 13f0271 | 2020-03-06 12:30:43 +0000 | [diff] [blame] | 418 | |
| 419 | // Get the deps that have been explicitly specified in the properties. |
| 420 | // Only updates the |
| 421 | linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps |
| 422 | } |
| 423 | |
| 424 | type specifiedDeps struct { |
| 425 | sharedLibs []string |
Martin Stjernholm | 10566a0 | 2020-03-24 01:19:52 +0000 | [diff] [blame] | 426 | systemSharedLibs []string // Note nil and [] are semantically distinct. |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | type installer interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 430 | installerProps() []interface{} |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 431 | install(ctx ModuleContext, path android.Path) |
Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 432 | everInstallable() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 433 | inData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 434 | inSanitizerDir() bool |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 435 | hostToolPath() android.OptionalPath |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 436 | relativeInstallPath() string |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 437 | makeUninstallable(mod *Module) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 440 | type xref interface { |
| 441 | XrefCcFiles() android.Paths |
| 442 | } |
| 443 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 444 | type libraryDependencyKind int |
| 445 | |
| 446 | const ( |
| 447 | headerLibraryDependency = iota |
| 448 | sharedLibraryDependency |
| 449 | staticLibraryDependency |
| 450 | ) |
| 451 | |
| 452 | func (k libraryDependencyKind) String() string { |
| 453 | switch k { |
| 454 | case headerLibraryDependency: |
| 455 | return "headerLibraryDependency" |
| 456 | case sharedLibraryDependency: |
| 457 | return "sharedLibraryDependency" |
| 458 | case staticLibraryDependency: |
| 459 | return "staticLibraryDependency" |
| 460 | default: |
| 461 | panic(fmt.Errorf("unknown libraryDependencyKind %d", k)) |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | type libraryDependencyOrder int |
| 466 | |
| 467 | const ( |
| 468 | earlyLibraryDependency = -1 |
| 469 | normalLibraryDependency = 0 |
| 470 | lateLibraryDependency = 1 |
| 471 | ) |
| 472 | |
| 473 | func (o libraryDependencyOrder) String() string { |
| 474 | switch o { |
| 475 | case earlyLibraryDependency: |
| 476 | return "earlyLibraryDependency" |
| 477 | case normalLibraryDependency: |
| 478 | return "normalLibraryDependency" |
| 479 | case lateLibraryDependency: |
| 480 | return "lateLibraryDependency" |
| 481 | default: |
| 482 | panic(fmt.Errorf("unknown libraryDependencyOrder %d", o)) |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | // libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency |
| 487 | // tags that have a set of predefined tag objects that are reused for each dependency, a |
| 488 | // libraryDependencyTag is designed to contain extra metadata and is constructed as needed. |
| 489 | // That means that comparing a libraryDependencyTag for equality will only be equal if all |
| 490 | // of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and |
| 491 | // then check individual metadata fields instead. |
| 492 | type libraryDependencyTag struct { |
| 493 | blueprint.BaseDependencyTag |
| 494 | |
| 495 | // These are exported so that fmt.Printf("%#v") can call their String methods. |
| 496 | Kind libraryDependencyKind |
| 497 | Order libraryDependencyOrder |
| 498 | |
| 499 | wholeStatic bool |
| 500 | |
| 501 | reexportFlags bool |
| 502 | explicitlyVersioned bool |
| 503 | dataLib bool |
| 504 | ndk bool |
| 505 | |
| 506 | staticUnwinder bool |
| 507 | |
| 508 | makeSuffix string |
| 509 | } |
| 510 | |
| 511 | // header returns true if the libraryDependencyTag is tagging a header lib dependency. |
| 512 | func (d libraryDependencyTag) header() bool { |
| 513 | return d.Kind == headerLibraryDependency |
| 514 | } |
| 515 | |
| 516 | // shared returns true if the libraryDependencyTag is tagging a shared lib dependency. |
| 517 | func (d libraryDependencyTag) shared() bool { |
| 518 | return d.Kind == sharedLibraryDependency |
| 519 | } |
| 520 | |
| 521 | // shared returns true if the libraryDependencyTag is tagging a static lib dependency. |
| 522 | func (d libraryDependencyTag) static() bool { |
| 523 | return d.Kind == staticLibraryDependency |
| 524 | } |
| 525 | |
| 526 | // dependencyTag is used for tagging miscellanous dependency types that don't fit into |
| 527 | // libraryDependencyTag. Each tag object is created globally and reused for multiple |
| 528 | // dependencies (although since the object contains no references, assigning a tag to a |
| 529 | // variable and modifying it will not modify the original). Users can compare the tag |
| 530 | // returned by ctx.OtherModuleDependencyTag against the global original |
| 531 | type dependencyTag struct { |
| 532 | blueprint.BaseDependencyTag |
| 533 | name string |
| 534 | } |
| 535 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 536 | var ( |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 537 | genSourceDepTag = dependencyTag{name: "gen source"} |
| 538 | genHeaderDepTag = dependencyTag{name: "gen header"} |
| 539 | genHeaderExportDepTag = dependencyTag{name: "gen header export"} |
| 540 | objDepTag = dependencyTag{name: "obj"} |
| 541 | linkerFlagsDepTag = dependencyTag{name: "linker flags file"} |
| 542 | dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"} |
| 543 | reuseObjTag = dependencyTag{name: "reuse objects"} |
| 544 | staticVariantTag = dependencyTag{name: "static variant"} |
| 545 | vndkExtDepTag = dependencyTag{name: "vndk extends"} |
| 546 | dataLibDepTag = dependencyTag{name: "data lib"} |
| 547 | runtimeDepTag = dependencyTag{name: "runtime lib"} |
| 548 | testPerSrcDepTag = dependencyTag{name: "test_per_src"} |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 549 | testForDepTag = dependencyTag{name: "test for apex"} |
| 550 | |
| 551 | stubImplDepTag = copyDirectlyInAnyApexDependencyTag{name: "stub_impl"} |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 552 | ) |
| 553 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 554 | type copyDirectlyInAnyApexDependencyTag dependencyTag |
| 555 | |
| 556 | func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {} |
| 557 | |
| 558 | var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{} |
| 559 | |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 560 | func IsSharedDepTag(depTag blueprint.DependencyTag) bool { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 561 | ccLibDepTag, ok := depTag.(libraryDependencyTag) |
| 562 | return ok && ccLibDepTag.shared() |
| 563 | } |
| 564 | |
| 565 | func IsStaticDepTag(depTag blueprint.DependencyTag) bool { |
| 566 | ccLibDepTag, ok := depTag.(libraryDependencyTag) |
| 567 | return ok && ccLibDepTag.static() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 571 | ccDepTag, ok := depTag.(dependencyTag) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 572 | return ok && ccDepTag == runtimeDepTag |
| 573 | } |
| 574 | |
| 575 | func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 576 | ccDepTag, ok := depTag.(dependencyTag) |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 577 | return ok && ccDepTag == testPerSrcDepTag |
| 578 | } |
| 579 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 580 | // Module contains the properties and members used by all C/C++ module types, and implements |
| 581 | // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces |
| 582 | // to construct the output file. Behavior can be customized with a Customizer interface |
| 583 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 584 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 585 | android.DefaultableModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 586 | android.ApexModuleBase |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 587 | android.SdkBase |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 588 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 589 | Properties BaseProperties |
| 590 | VendorProperties VendorProperties |
Colin Cross | fa13879 | 2015-04-24 17:31:52 -0700 | [diff] [blame] | 591 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 592 | // initialize before calling Init |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 593 | hod android.HostOrDeviceSupported |
| 594 | multilib android.Multilib |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 595 | |
Paul Duffin | a0843f6 | 2019-12-13 19:50:38 +0000 | [diff] [blame] | 596 | // Allowable SdkMemberTypes of this module type. |
| 597 | sdkMemberTypes []android.SdkMemberType |
| 598 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 599 | // delegates, initialize before calling Init |
Colin Cross | b4ce0ec | 2016-09-13 13:41:39 -0700 | [diff] [blame] | 600 | features []feature |
| 601 | compiler compiler |
| 602 | linker linker |
| 603 | installer installer |
| 604 | stl *stl |
| 605 | sanitize *sanitize |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 606 | coverage *coverage |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 607 | sabi *sabi |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 608 | vndkdep *vndkdep |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 609 | lto *lto |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 610 | pgo *pgo |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 611 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 612 | outputFile android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 613 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 614 | cachedToolchain config.Toolchain |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 615 | |
| 616 | subAndroidMkOnce map[subAndroidMkProvider]bool |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 617 | |
| 618 | // Flags used to compile this module |
| 619 | flags Flags |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 620 | |
| 621 | // When calling a linker, if module A depends on module B, then A must precede B in its command |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 622 | // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 623 | // deps of this module |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 624 | depsInLinkOrder android.Paths |
| 625 | |
| 626 | // only non-nil when this is a shared library that reuses the objects of a static library |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 627 | staticVariant LinkableInterface |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 628 | |
| 629 | makeLinkType string |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 630 | // Kythe (source file indexer) paths for this compilation module |
| 631 | kytheFiles android.Paths |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 632 | |
| 633 | // For apex variants, this is set as apex.min_sdk_version |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 634 | apexSdkVersion android.ApiLevel |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 635 | |
| 636 | hideApexVariantFromMake bool |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 639 | func (c *Module) Toc() android.OptionalPath { |
| 640 | if c.linker != nil { |
| 641 | if library, ok := c.linker.(libraryInterface); ok { |
| 642 | return library.toc() |
| 643 | } |
| 644 | } |
| 645 | panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName())) |
| 646 | } |
| 647 | |
| 648 | func (c *Module) ApiLevel() string { |
| 649 | if c.linker != nil { |
| 650 | if stub, ok := c.linker.(*stubDecorator); ok { |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 651 | return stub.apiLevel.String() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName())) |
| 655 | } |
| 656 | |
| 657 | func (c *Module) Static() bool { |
| 658 | if c.linker != nil { |
| 659 | if library, ok := c.linker.(libraryInterface); ok { |
| 660 | return library.static() |
| 661 | } |
| 662 | } |
| 663 | panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName())) |
| 664 | } |
| 665 | |
| 666 | func (c *Module) Shared() bool { |
| 667 | if c.linker != nil { |
| 668 | if library, ok := c.linker.(libraryInterface); ok { |
| 669 | return library.shared() |
| 670 | } |
| 671 | } |
| 672 | panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName())) |
| 673 | } |
| 674 | |
| 675 | func (c *Module) SelectedStl() string { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 676 | if c.stl != nil { |
| 677 | return c.stl.Properties.SelectedStl |
| 678 | } |
| 679 | return "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | func (c *Module) ToolchainLibrary() bool { |
| 683 | if _, ok := c.linker.(*toolchainLibraryDecorator); ok { |
| 684 | return true |
| 685 | } |
| 686 | return false |
| 687 | } |
| 688 | |
| 689 | func (c *Module) NdkPrebuiltStl() bool { |
| 690 | if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok { |
| 691 | return true |
| 692 | } |
| 693 | return false |
| 694 | } |
| 695 | |
| 696 | func (c *Module) StubDecorator() bool { |
| 697 | if _, ok := c.linker.(*stubDecorator); ok { |
| 698 | return true |
| 699 | } |
| 700 | return false |
| 701 | } |
| 702 | |
| 703 | func (c *Module) SdkVersion() string { |
| 704 | return String(c.Properties.Sdk_version) |
| 705 | } |
| 706 | |
Artur Satayev | 480e25b | 2020-04-27 18:53:18 +0100 | [diff] [blame] | 707 | func (c *Module) MinSdkVersion() string { |
| 708 | return String(c.Properties.Min_sdk_version) |
| 709 | } |
| 710 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 711 | func (c *Module) SplitPerApiLevel() bool { |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 712 | if !c.canUseSdk() { |
| 713 | return false |
| 714 | } |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 715 | if linker, ok := c.linker.(*objectLinker); ok { |
| 716 | return linker.isCrt() |
| 717 | } |
| 718 | return false |
| 719 | } |
| 720 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 721 | func (c *Module) AlwaysSdk() bool { |
| 722 | return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only) |
| 723 | } |
| 724 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 725 | func (c *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 726 | if c.linker != nil { |
| 727 | if library, ok := c.linker.(exportedFlagsProducer); ok { |
| 728 | return library.exportedDirs() |
| 729 | } |
| 730 | } |
| 731 | panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName())) |
| 732 | } |
| 733 | |
| 734 | func (c *Module) HasStaticVariant() bool { |
| 735 | if c.staticVariant != nil { |
| 736 | return true |
| 737 | } |
| 738 | return false |
| 739 | } |
| 740 | |
| 741 | func (c *Module) GetStaticVariant() LinkableInterface { |
| 742 | return c.staticVariant |
| 743 | } |
| 744 | |
| 745 | func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) { |
| 746 | c.depsInLinkOrder = depsInLinkOrder |
| 747 | } |
| 748 | |
| 749 | func (c *Module) GetDepsInLinkOrder() []android.Path { |
| 750 | return c.depsInLinkOrder |
| 751 | } |
| 752 | |
| 753 | func (c *Module) StubsVersions() []string { |
| 754 | if c.linker != nil { |
| 755 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 756 | return library.Properties.Stubs.Versions |
| 757 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 758 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 759 | return library.Properties.Stubs.Versions |
| 760 | } |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 761 | } |
| 762 | panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName())) |
| 763 | } |
| 764 | |
| 765 | func (c *Module) CcLibrary() bool { |
| 766 | if c.linker != nil { |
| 767 | if _, ok := c.linker.(*libraryDecorator); ok { |
| 768 | return true |
| 769 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 770 | if _, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 771 | return true |
| 772 | } |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 773 | } |
| 774 | return false |
| 775 | } |
| 776 | |
| 777 | func (c *Module) CcLibraryInterface() bool { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 778 | if _, ok := c.linker.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 779 | return true |
| 780 | } |
| 781 | return false |
| 782 | } |
| 783 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 784 | func (c *Module) NonCcVariants() bool { |
| 785 | return false |
| 786 | } |
| 787 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 788 | func (c *Module) SetBuildStubs() { |
| 789 | if c.linker != nil { |
| 790 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 791 | library.MutatedProperties.BuildStubs = true |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 792 | c.Properties.HideFromMake = true |
| 793 | c.sanitize = nil |
| 794 | c.stl = nil |
| 795 | c.Properties.PreventInstall = true |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 796 | return |
| 797 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 798 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 799 | library.MutatedProperties.BuildStubs = true |
| 800 | c.Properties.HideFromMake = true |
| 801 | c.sanitize = nil |
| 802 | c.stl = nil |
| 803 | c.Properties.PreventInstall = true |
| 804 | return |
| 805 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 806 | if _, ok := c.linker.(*llndkStubDecorator); ok { |
| 807 | c.Properties.HideFromMake = true |
| 808 | return |
| 809 | } |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 810 | } |
| 811 | panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName())) |
| 812 | } |
| 813 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 814 | func (c *Module) BuildStubs() bool { |
| 815 | if c.linker != nil { |
| 816 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 817 | return library.buildStubs() |
| 818 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 819 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 820 | return library.buildStubs() |
| 821 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 822 | } |
| 823 | panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName())) |
| 824 | } |
| 825 | |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 826 | func (c *Module) SetAllStubsVersions(versions []string) { |
| 827 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 828 | library.MutatedProperties.AllStubsVersions = versions |
| 829 | return |
| 830 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 831 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 832 | library.MutatedProperties.AllStubsVersions = versions |
| 833 | return |
| 834 | } |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 835 | if llndk, ok := c.linker.(*llndkStubDecorator); ok { |
| 836 | llndk.libraryDecorator.MutatedProperties.AllStubsVersions = versions |
| 837 | return |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | func (c *Module) AllStubsVersions() []string { |
| 842 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 843 | return library.MutatedProperties.AllStubsVersions |
| 844 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 845 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 846 | return library.MutatedProperties.AllStubsVersions |
| 847 | } |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 848 | if llndk, ok := c.linker.(*llndkStubDecorator); ok { |
| 849 | return llndk.libraryDecorator.MutatedProperties.AllStubsVersions |
| 850 | } |
| 851 | return nil |
| 852 | } |
| 853 | |
| 854 | func (c *Module) SetStubsVersion(version string) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 855 | if c.linker != nil { |
| 856 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 857 | library.MutatedProperties.StubsVersion = version |
| 858 | return |
| 859 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 860 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 861 | library.MutatedProperties.StubsVersion = version |
| 862 | return |
| 863 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 864 | if llndk, ok := c.linker.(*llndkStubDecorator); ok { |
| 865 | llndk.libraryDecorator.MutatedProperties.StubsVersion = version |
| 866 | return |
| 867 | } |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 868 | } |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 869 | panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName())) |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 872 | func (c *Module) StubsVersion() string { |
| 873 | if c.linker != nil { |
| 874 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 875 | return library.MutatedProperties.StubsVersion |
| 876 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 877 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 878 | return library.MutatedProperties.StubsVersion |
| 879 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 880 | if llndk, ok := c.linker.(*llndkStubDecorator); ok { |
| 881 | return llndk.libraryDecorator.MutatedProperties.StubsVersion |
| 882 | } |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 883 | } |
| 884 | panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName())) |
| 885 | } |
| 886 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 887 | func (c *Module) SetStatic() { |
| 888 | if c.linker != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 889 | if library, ok := c.linker.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 890 | library.setStatic() |
| 891 | return |
| 892 | } |
| 893 | } |
| 894 | panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName())) |
| 895 | } |
| 896 | |
| 897 | func (c *Module) SetShared() { |
| 898 | if c.linker != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 899 | if library, ok := c.linker.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 900 | library.setShared() |
| 901 | return |
| 902 | } |
| 903 | } |
| 904 | panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName())) |
| 905 | } |
| 906 | |
| 907 | func (c *Module) BuildStaticVariant() bool { |
| 908 | if c.linker != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 909 | if library, ok := c.linker.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 910 | return library.buildStatic() |
| 911 | } |
| 912 | } |
| 913 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName())) |
| 914 | } |
| 915 | |
| 916 | func (c *Module) BuildSharedVariant() bool { |
| 917 | if c.linker != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 918 | if library, ok := c.linker.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 919 | return library.buildShared() |
| 920 | } |
| 921 | } |
| 922 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName())) |
| 923 | } |
| 924 | |
| 925 | func (c *Module) Module() android.Module { |
| 926 | return c |
| 927 | } |
| 928 | |
Jiyong Park | c20eee3 | 2018-09-05 22:36:17 +0900 | [diff] [blame] | 929 | func (c *Module) OutputFile() android.OptionalPath { |
| 930 | return c.outputFile |
| 931 | } |
| 932 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 933 | func (c *Module) CoverageFiles() android.Paths { |
| 934 | if c.linker != nil { |
| 935 | if library, ok := c.linker.(libraryInterface); ok { |
| 936 | return library.objs().coverageFiles |
| 937 | } |
| 938 | } |
| 939 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName())) |
| 940 | } |
| 941 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 942 | var _ LinkableInterface = (*Module)(nil) |
| 943 | |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 944 | func (c *Module) UnstrippedOutputFile() android.Path { |
Jiyong Park | af6d895 | 2019-01-31 12:21:23 +0900 | [diff] [blame] | 945 | if c.linker != nil { |
| 946 | return c.linker.unstrippedOutputFilePath() |
Jiyong Park | 719b446 | 2019-01-13 00:39:51 +0900 | [diff] [blame] | 947 | } |
| 948 | return nil |
| 949 | } |
| 950 | |
Jiyong Park | ee9a98d | 2019-08-09 14:44:36 +0900 | [diff] [blame] | 951 | func (c *Module) CoverageOutputFile() android.OptionalPath { |
| 952 | if c.linker != nil { |
| 953 | return c.linker.coverageOutputFilePath() |
| 954 | } |
| 955 | return android.OptionalPath{} |
| 956 | } |
| 957 | |
Jiyong Park | b7c24df | 2019-02-01 12:03:59 +0900 | [diff] [blame] | 958 | func (c *Module) RelativeInstallPath() string { |
| 959 | if c.installer != nil { |
| 960 | return c.installer.relativeInstallPath() |
| 961 | } |
| 962 | return "" |
| 963 | } |
| 964 | |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 965 | func (c *Module) VndkVersion() string { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 966 | return c.Properties.VndkVersion |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 967 | } |
| 968 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 969 | func (c *Module) Init() android.Module { |
Dan Willemsen | f923f2b | 2018-05-09 13:45:03 -0700 | [diff] [blame] | 970 | c.AddProperties(&c.Properties, &c.VendorProperties) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 971 | if c.compiler != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 972 | c.AddProperties(c.compiler.compilerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 973 | } |
| 974 | if c.linker != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 975 | c.AddProperties(c.linker.linkerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 976 | } |
| 977 | if c.installer != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 978 | c.AddProperties(c.installer.installerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 979 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 980 | if c.stl != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 981 | c.AddProperties(c.stl.props()...) |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 982 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 983 | if c.sanitize != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 984 | c.AddProperties(c.sanitize.props()...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 985 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 986 | if c.coverage != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 987 | c.AddProperties(c.coverage.props()...) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 988 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 989 | if c.sabi != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 990 | c.AddProperties(c.sabi.props()...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 991 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 992 | if c.vndkdep != nil { |
| 993 | c.AddProperties(c.vndkdep.props()...) |
| 994 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 995 | if c.lto != nil { |
| 996 | c.AddProperties(c.lto.props()...) |
| 997 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 998 | if c.pgo != nil { |
| 999 | c.AddProperties(c.pgo.props()...) |
| 1000 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1001 | for _, feature := range c.features { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1002 | c.AddProperties(feature.props()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1003 | } |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1004 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1005 | c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool { |
Elliott Hughes | 79ae341 | 2020-04-17 15:49:49 -0700 | [diff] [blame] | 1006 | // Windows builds always prefer 32-bit |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1007 | return os == android.Windows |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 1008 | }) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1009 | android.InitAndroidArchModule(c, c.hod, c.multilib) |
Jiyong Park | 7916bfc | 2019-09-30 19:13:12 +0900 | [diff] [blame] | 1010 | android.InitApexModule(c) |
Jiyong Park | d1063c1 | 2019-07-17 20:08:41 +0900 | [diff] [blame] | 1011 | android.InitSdkAwareModule(c) |
Jooyung Han | 18020ea | 2019-11-13 10:50:48 +0900 | [diff] [blame] | 1012 | android.InitDefaultableModule(c) |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 1013 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1014 | return c |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1017 | // Returns true for dependency roots (binaries) |
| 1018 | // TODO(ccross): also handle dlopenable libraries |
| 1019 | func (c *Module) isDependencyRoot() bool { |
| 1020 | if root, ok := c.linker.(interface { |
| 1021 | isDependencyRoot() bool |
| 1022 | }); ok { |
| 1023 | return root.isDependencyRoot() |
| 1024 | } |
| 1025 | return false |
| 1026 | } |
| 1027 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1028 | // Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64. |
| 1029 | // "product" and "vendor" variant modules return true for this function. |
| 1030 | // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true", |
| 1031 | // "soc_specific: true" and more vendor installed modules are included here. |
| 1032 | // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or |
| 1033 | // "product_specific: true" modules are included here. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1034 | func (c *Module) UseVndk() bool { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1035 | return c.Properties.VndkVersion != "" |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1036 | } |
| 1037 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1038 | func (c *Module) canUseSdk() bool { |
| 1039 | return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() |
| 1040 | } |
| 1041 | |
| 1042 | func (c *Module) UseSdk() bool { |
| 1043 | if c.canUseSdk() { |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 1044 | return String(c.Properties.Sdk_version) != "" |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1045 | } |
| 1046 | return false |
| 1047 | } |
| 1048 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1049 | func (c *Module) isCoverageVariant() bool { |
| 1050 | return c.coverage.Properties.IsCoverageVariant |
| 1051 | } |
| 1052 | |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1053 | func (c *Module) IsNdk() bool { |
Colin Cross | f0913fb | 2020-07-29 12:59:39 -0700 | [diff] [blame] | 1054 | return inList(c.BaseModuleName(), ndkKnownLibs) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1055 | } |
| 1056 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1057 | func (c *Module) isLlndk(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1058 | // Returns true for both LLNDK (public) and LLNDK-private libs. |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1059 | return isLlndkLibrary(c.BaseModuleName(), config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1060 | } |
| 1061 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1062 | func (c *Module) isLlndkPublic(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1063 | // Returns true only for LLNDK (public) libs. |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1064 | name := c.BaseModuleName() |
| 1065 | return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1068 | func (c *Module) isVndkPrivate(config android.Config) bool { |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1069 | // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private. |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 1070 | return isVndkPrivateLibrary(c.BaseModuleName(), config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1071 | } |
| 1072 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1073 | func (c *Module) IsVndk() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1074 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1075 | return vndkdep.isVndk() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1076 | } |
| 1077 | return false |
| 1078 | } |
| 1079 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 1080 | func (c *Module) isPgoCompile() bool { |
| 1081 | if pgo := c.pgo; pgo != nil { |
| 1082 | return pgo.Properties.PgoCompile |
| 1083 | } |
| 1084 | return false |
| 1085 | } |
| 1086 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1087 | func (c *Module) isNDKStubLibrary() bool { |
| 1088 | if _, ok := c.compiler.(*stubDecorator); ok { |
| 1089 | return true |
| 1090 | } |
| 1091 | return false |
| 1092 | } |
| 1093 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1094 | func (c *Module) isVndkSp() bool { |
| 1095 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1096 | return vndkdep.isVndkSp() |
| 1097 | } |
| 1098 | return false |
| 1099 | } |
| 1100 | |
| 1101 | func (c *Module) isVndkExt() bool { |
| 1102 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1103 | return vndkdep.isVndkExt() |
| 1104 | } |
| 1105 | return false |
| 1106 | } |
| 1107 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1108 | func (c *Module) MustUseVendorVariant() bool { |
Jooyung Han | 097087b | 2019-10-22 19:32:18 +0900 | [diff] [blame] | 1109 | return c.isVndkSp() || c.Properties.MustUseVendorVariant |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1112 | func (c *Module) getVndkExtendsModuleName() string { |
| 1113 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1114 | return vndkdep.getVndkExtendsModuleName() |
| 1115 | } |
| 1116 | return "" |
| 1117 | } |
| 1118 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1119 | func (c *Module) IsStubs() bool { |
| 1120 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 1121 | return library.buildStubs() |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 1122 | } else if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 1123 | return library.buildStubs() |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1124 | } else if _, ok := c.linker.(*llndkStubDecorator); ok { |
| 1125 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1126 | } |
| 1127 | return false |
| 1128 | } |
| 1129 | |
| 1130 | func (c *Module) HasStubsVariants() bool { |
| 1131 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 1132 | return len(library.Properties.Stubs.Versions) > 0 |
| 1133 | } |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 1134 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 1135 | return len(library.Properties.Stubs.Versions) > 0 |
| 1136 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1137 | return false |
| 1138 | } |
| 1139 | |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 1140 | func (c *Module) bootstrap() bool { |
| 1141 | return Bool(c.Properties.Bootstrap) |
| 1142 | } |
| 1143 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 1144 | func (c *Module) nativeCoverage() bool { |
Pirama Arumuga Nainar | 5f69b9a | 2019-09-12 13:18:48 -0700 | [diff] [blame] | 1145 | // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage |
| 1146 | if c.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1147 | return false |
| 1148 | } |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 1149 | return c.linker != nil && c.linker.nativeCoverage() |
| 1150 | } |
| 1151 | |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1152 | func (c *Module) isSnapshotPrebuilt() bool { |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1153 | if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok { |
| 1154 | return p.isSnapshotPrebuilt() |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1155 | } |
| 1156 | return false |
Inseob Kim | 8471cda | 2019-11-15 09:59:12 +0900 | [diff] [blame] | 1157 | } |
| 1158 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1159 | func (c *Module) ExportedIncludeDirs() android.Paths { |
| 1160 | if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { |
| 1161 | return flagsProducer.exportedDirs() |
| 1162 | } |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 1163 | return nil |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | func (c *Module) ExportedSystemIncludeDirs() android.Paths { |
| 1167 | if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { |
| 1168 | return flagsProducer.exportedSystemDirs() |
| 1169 | } |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 1170 | return nil |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | func (c *Module) ExportedFlags() []string { |
| 1174 | if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { |
| 1175 | return flagsProducer.exportedFlags() |
| 1176 | } |
Jiyong Park | 232e785 | 2019-11-04 12:23:40 +0900 | [diff] [blame] | 1177 | return nil |
| 1178 | } |
| 1179 | |
| 1180 | func (c *Module) ExportedDeps() android.Paths { |
| 1181 | if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { |
| 1182 | return flagsProducer.exportedDeps() |
| 1183 | } |
| 1184 | return nil |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1185 | } |
| 1186 | |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 1187 | func (c *Module) ExportedGeneratedHeaders() android.Paths { |
| 1188 | if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok { |
| 1189 | return flagsProducer.exportedGeneratedHeaders() |
| 1190 | } |
| 1191 | return nil |
| 1192 | } |
| 1193 | |
Bill Peckham | 945441c | 2020-08-31 16:07:58 -0700 | [diff] [blame] | 1194 | func (c *Module) ExcludeFromVendorSnapshot() bool { |
| 1195 | return Bool(c.Properties.Exclude_from_vendor_snapshot) |
| 1196 | } |
| 1197 | |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 1198 | func isBionic(name string) bool { |
| 1199 | switch name { |
Martin Stjernholm | 203489b | 2019-11-11 15:33:27 +0000 | [diff] [blame] | 1200 | case "libc", "libm", "libdl", "libdl_android", "linker": |
Jiyong Park | f119435 | 2019-02-25 11:05:47 +0900 | [diff] [blame] | 1201 | return true |
| 1202 | } |
| 1203 | return false |
| 1204 | } |
| 1205 | |
Martin Stjernholm | 279de57 | 2019-09-10 23:18:20 +0100 | [diff] [blame] | 1206 | func InstallToBootstrap(name string, config android.Config) bool { |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 1207 | if name == "libclang_rt.hwasan-aarch64-android" { |
Jooyung Han | 8ce8db9 | 2020-05-15 19:05:05 +0900 | [diff] [blame] | 1208 | return true |
Peter Collingbourne | 3478bb2 | 2019-04-24 14:41:12 -0700 | [diff] [blame] | 1209 | } |
| 1210 | return isBionic(name) |
| 1211 | } |
| 1212 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1213 | func (c *Module) XrefCcFiles() android.Paths { |
| 1214 | return c.kytheFiles |
| 1215 | } |
| 1216 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1217 | type baseModuleContext struct { |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1218 | android.BaseModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1219 | moduleContextImpl |
| 1220 | } |
| 1221 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1222 | type depsContext struct { |
| 1223 | android.BottomUpMutatorContext |
| 1224 | moduleContextImpl |
| 1225 | } |
| 1226 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1227 | type moduleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1228 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1229 | moduleContextImpl |
| 1230 | } |
| 1231 | |
| 1232 | type moduleContextImpl struct { |
| 1233 | mod *Module |
| 1234 | ctx BaseModuleContext |
| 1235 | } |
| 1236 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 1237 | func (ctx *moduleContextImpl) toolchain() config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1238 | return ctx.mod.toolchain(ctx.ctx) |
| 1239 | } |
| 1240 | |
| 1241 | func (ctx *moduleContextImpl) static() bool { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1242 | return ctx.mod.static() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | func (ctx *moduleContextImpl) staticBinary() bool { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1246 | return ctx.mod.staticBinary() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1247 | } |
| 1248 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 1249 | func (ctx *moduleContextImpl) header() bool { |
| 1250 | return ctx.mod.header() |
| 1251 | } |
| 1252 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 1253 | func (ctx *moduleContextImpl) binary() bool { |
| 1254 | return ctx.mod.binary() |
| 1255 | } |
| 1256 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 1257 | func (ctx *moduleContextImpl) object() bool { |
| 1258 | return ctx.mod.object() |
| 1259 | } |
| 1260 | |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1261 | func (ctx *moduleContextImpl) canUseSdk() bool { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1262 | return ctx.mod.canUseSdk() |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1263 | } |
| 1264 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1265 | func (ctx *moduleContextImpl) useSdk() bool { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1266 | return ctx.mod.UseSdk() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | func (ctx *moduleContextImpl) sdkVersion() string { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1270 | if ctx.ctx.Device() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1271 | if ctx.useVndk() { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1272 | vndkVer := ctx.mod.VndkVersion() |
Jooyung Han | 03302ee | 2020-04-08 09:22:26 +0900 | [diff] [blame] | 1273 | if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) { |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1274 | return "current" |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 1275 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1276 | return vndkVer |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 1277 | } |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 1278 | return String(ctx.mod.Properties.Sdk_version) |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1279 | } |
| 1280 | return "" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1283 | func (ctx *moduleContextImpl) useVndk() bool { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1284 | return ctx.mod.UseVndk() |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1285 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1286 | |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1287 | func (ctx *moduleContextImpl) isNdk() bool { |
Peter Collingbourne | ad84f97 | 2019-12-17 16:46:18 -0800 | [diff] [blame] | 1288 | return ctx.mod.IsNdk() |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1289 | } |
| 1290 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1291 | func (ctx *moduleContextImpl) isLlndk(config android.Config) bool { |
| 1292 | return ctx.mod.isLlndk(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1293 | } |
| 1294 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1295 | func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool { |
| 1296 | return ctx.mod.isLlndkPublic(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1299 | func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool { |
| 1300 | return ctx.mod.isVndkPrivate(config) |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 1301 | } |
| 1302 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1303 | func (ctx *moduleContextImpl) isVndk() bool { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1304 | return ctx.mod.IsVndk() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 1307 | func (ctx *moduleContextImpl) isPgoCompile() bool { |
| 1308 | return ctx.mod.isPgoCompile() |
| 1309 | } |
| 1310 | |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1311 | func (ctx *moduleContextImpl) isNDKStubLibrary() bool { |
| 1312 | return ctx.mod.isNDKStubLibrary() |
| 1313 | } |
| 1314 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1315 | func (ctx *moduleContextImpl) isVndkSp() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1316 | return ctx.mod.isVndkSp() |
| 1317 | } |
| 1318 | |
| 1319 | func (ctx *moduleContextImpl) isVndkExt() bool { |
| 1320 | return ctx.mod.isVndkExt() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1321 | } |
| 1322 | |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1323 | func (ctx *moduleContextImpl) mustUseVendorVariant() bool { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1324 | return ctx.mod.MustUseVendorVariant() |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 1327 | // Check whether ABI dumps should be created for this module. |
Hsin-Yi Chen | af17d74 | 2019-07-29 17:46:59 +0800 | [diff] [blame] | 1328 | func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 1329 | if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") { |
| 1330 | return false |
Jayant Chowdhary | ea0a2e1 | 2018-03-01 19:12:16 -0800 | [diff] [blame] | 1331 | } |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 1332 | |
Hsin-Yi Chen | f81bb65 | 2020-04-07 21:42:19 +0800 | [diff] [blame] | 1333 | // Coverage builds have extra symbols. |
| 1334 | if ctx.mod.isCoverageVariant() { |
| 1335 | return false |
| 1336 | } |
| 1337 | |
Doug Horn | c32c6b0 | 2019-01-17 14:44:05 -0800 | [diff] [blame] | 1338 | if ctx.ctx.Fuchsia() { |
| 1339 | return false |
| 1340 | } |
| 1341 | |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 1342 | if sanitize := ctx.mod.sanitize; sanitize != nil { |
| 1343 | if !sanitize.isVariantOnProductionDevice() { |
| 1344 | return false |
| 1345 | } |
| 1346 | } |
| 1347 | if !ctx.ctx.Device() { |
| 1348 | // Host modules do not need ABI dumps. |
| 1349 | return false |
| 1350 | } |
Hsin-Yi Chen | d245168 | 2020-01-10 16:47:50 +0800 | [diff] [blame] | 1351 | if ctx.isStubs() || ctx.isNDKStubLibrary() { |
Hsin-Yi Chen | f6a9546 | 2019-06-25 14:46:52 +0800 | [diff] [blame] | 1352 | // Stubs do not need ABI dumps. |
| 1353 | return false |
| 1354 | } |
Hsin-Yi Chen | af17d74 | 2019-07-29 17:46:59 +0800 | [diff] [blame] | 1355 | return true |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 1358 | func (ctx *moduleContextImpl) selectedStl() string { |
| 1359 | if stl := ctx.mod.stl; stl != nil { |
| 1360 | return stl.Properties.SelectedStl |
| 1361 | } |
| 1362 | return "" |
| 1363 | } |
| 1364 | |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 1365 | func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool { |
| 1366 | return ctx.mod.linker.useClangLld(actx) |
| 1367 | } |
| 1368 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1369 | func (ctx *moduleContextImpl) baseModuleName() string { |
| 1370 | return ctx.mod.ModuleBase.BaseModuleName() |
| 1371 | } |
| 1372 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1373 | func (ctx *moduleContextImpl) getVndkExtendsModuleName() string { |
| 1374 | return ctx.mod.getVndkExtendsModuleName() |
| 1375 | } |
| 1376 | |
Logan Chien | e274fc9 | 2019-12-03 11:18:32 -0800 | [diff] [blame] | 1377 | func (ctx *moduleContextImpl) isForPlatform() bool { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1378 | return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() |
Logan Chien | e274fc9 | 2019-12-03 11:18:32 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
Colin Cross | e07f231 | 2020-08-13 11:24:56 -0700 | [diff] [blame] | 1381 | func (ctx *moduleContextImpl) apexVariationName() string { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1382 | return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1383 | } |
| 1384 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 1385 | func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel { |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 1386 | return ctx.mod.apexSdkVersion |
Jooyung Han | ccce2f2 | 2020-03-07 03:45:53 +0900 | [diff] [blame] | 1387 | } |
| 1388 | |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1389 | func (ctx *moduleContextImpl) hasStubsVariants() bool { |
| 1390 | return ctx.mod.HasStubsVariants() |
| 1391 | } |
| 1392 | |
| 1393 | func (ctx *moduleContextImpl) isStubs() bool { |
| 1394 | return ctx.mod.IsStubs() |
| 1395 | } |
| 1396 | |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 1397 | func (ctx *moduleContextImpl) bootstrap() bool { |
| 1398 | return ctx.mod.bootstrap() |
| 1399 | } |
| 1400 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 1401 | func (ctx *moduleContextImpl) nativeCoverage() bool { |
| 1402 | return ctx.mod.nativeCoverage() |
| 1403 | } |
| 1404 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1405 | func (ctx *moduleContextImpl) directlyInAnyApex() bool { |
| 1406 | return ctx.mod.DirectlyInAnyApex() |
| 1407 | } |
| 1408 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1409 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1410 | return &Module{ |
| 1411 | hod: hod, |
| 1412 | multilib: multilib, |
| 1413 | } |
| 1414 | } |
| 1415 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1416 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1417 | module := newBaseModule(hod, multilib) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1418 | module.features = []feature{ |
| 1419 | &tidyFeature{}, |
| 1420 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1421 | module.stl = &stl{} |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1422 | module.sanitize = &sanitize{} |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1423 | module.coverage = &coverage{} |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1424 | module.sabi = &sabi{} |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1425 | module.vndkdep = &vndkdep{} |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1426 | module.lto = <o{} |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1427 | module.pgo = &pgo{} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1428 | return module |
| 1429 | } |
| 1430 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1431 | func (c *Module) Prebuilt() *android.Prebuilt { |
| 1432 | if p, ok := c.linker.(prebuiltLinkerInterface); ok { |
| 1433 | return p.prebuilt() |
| 1434 | } |
| 1435 | return nil |
| 1436 | } |
| 1437 | |
| 1438 | func (c *Module) Name() string { |
| 1439 | name := c.ModuleBase.Name() |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 1440 | if p, ok := c.linker.(interface { |
| 1441 | Name(string) string |
| 1442 | }); ok { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1443 | name = p.Name(name) |
| 1444 | } |
| 1445 | return name |
| 1446 | } |
| 1447 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 1448 | func (c *Module) Symlinks() []string { |
| 1449 | if p, ok := c.installer.(interface { |
| 1450 | symlinkList() []string |
| 1451 | }); ok { |
| 1452 | return p.symlinkList() |
| 1453 | } |
| 1454 | return nil |
| 1455 | } |
| 1456 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1457 | // orderDeps reorders dependencies into a list such that if module A depends on B, then |
| 1458 | // A will precede B in the resultant list. |
| 1459 | // This is convenient for passing into a linker. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1460 | // Note that directSharedDeps should be the analogous static library for each shared lib dep |
| 1461 | func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1462 | // If A depends on B, then |
| 1463 | // Every list containing A will also contain B later in the list |
| 1464 | // So, after concatenating all lists, the final instance of B will have come from the same |
| 1465 | // original list as the final instance of A |
| 1466 | // So, the final instance of B will be later in the concatenation than the final A |
| 1467 | // So, keeping only the final instance of A and of B ensures that A is earlier in the output |
| 1468 | // list than B |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1469 | for _, dep := range directStaticDeps { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1470 | orderedAllDeps = append(orderedAllDeps, dep) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1471 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
| 1472 | } |
| 1473 | for _, dep := range directSharedDeps { |
| 1474 | orderedAllDeps = append(orderedAllDeps, dep) |
| 1475 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1478 | orderedAllDeps = android.LastUniquePaths(orderedAllDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1479 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1480 | // We don't want to add any new dependencies into directStaticDeps (to allow the caller to |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1481 | // intentionally exclude or replace any unwanted transitive dependencies), so we limit the |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1482 | // resultant list to only what the caller has chosen to include in directStaticDeps |
| 1483 | _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1484 | |
| 1485 | return orderedAllDeps, orderedDeclaredDeps |
| 1486 | } |
| 1487 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 1488 | func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1489 | // convert Module to Path |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 1490 | var depsInLinkOrder []android.Path |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1491 | allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps)) |
| 1492 | staticDepFiles := []android.Path{} |
| 1493 | for _, dep := range staticDeps { |
Nicolas Geoffray | 0b78766 | 2020-02-04 18:27:55 +0000 | [diff] [blame] | 1494 | // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set. |
| 1495 | if dep.OutputFile().Valid() { |
| 1496 | allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder() |
| 1497 | staticDepFiles = append(staticDepFiles, dep.OutputFile().Path()) |
| 1498 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1499 | } |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1500 | sharedDepFiles := []android.Path{} |
| 1501 | for _, sharedDep := range sharedDeps { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 1502 | if sharedDep.HasStaticVariant() { |
| 1503 | staticAnalogue := sharedDep.GetStaticVariant() |
| 1504 | allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder() |
| 1505 | sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path()) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1506 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | // reorder the dependencies based on transitive dependencies |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 1510 | depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps) |
| 1511 | module.SetDepsInLinkOrder(depsInLinkOrder) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1512 | |
| 1513 | return results |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1514 | } |
| 1515 | |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1516 | func (c *Module) IsTestPerSrcAllTestsVariation() bool { |
| 1517 | test, ok := c.linker.(testPerSrc) |
| 1518 | return ok && test.isAllTestsVariation() |
| 1519 | } |
| 1520 | |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 1521 | func (c *Module) DataPaths() []android.DataPath { |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 1522 | if p, ok := c.installer.(interface { |
Chris Parsons | 216e10a | 2020-07-09 17:12:52 -0400 | [diff] [blame] | 1523 | dataPaths() []android.DataPath |
Liz Kammer | 1c14a21 | 2020-05-12 15:26:55 -0700 | [diff] [blame] | 1524 | }); ok { |
| 1525 | return p.dataPaths() |
| 1526 | } |
| 1527 | return nil |
| 1528 | } |
| 1529 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1530 | func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string { |
| 1531 | // Returns the name suffix for product and vendor variants. If the VNDK version is not |
| 1532 | // "current", it will append the VNDK version to the name suffix. |
| 1533 | var vndkVersion string |
| 1534 | var nameSuffix string |
| 1535 | if c.inProduct() { |
| 1536 | vndkVersion = ctx.DeviceConfig().ProductVndkVersion() |
| 1537 | nameSuffix = productSuffix |
| 1538 | } else { |
| 1539 | vndkVersion = ctx.DeviceConfig().VndkVersion() |
| 1540 | nameSuffix = vendorSuffix |
| 1541 | } |
| 1542 | if vndkVersion == "current" { |
| 1543 | vndkVersion = ctx.DeviceConfig().PlatformVndkVersion() |
| 1544 | } |
| 1545 | if c.Properties.VndkVersion != vndkVersion { |
| 1546 | // add version suffix only if the module is using different vndk version than the |
| 1547 | // version in product or vendor partition. |
| 1548 | nameSuffix += "." + c.Properties.VndkVersion |
| 1549 | } |
| 1550 | return nameSuffix |
| 1551 | } |
| 1552 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1553 | func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1554 | // Handle the case of a test module split by `test_per_src` mutator. |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 1555 | // |
| 1556 | // The `test_per_src` mutator adds an extra variation named "", depending on all the other |
| 1557 | // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this |
| 1558 | // module and return early, as this module does not produce an output file per se. |
| 1559 | if c.IsTestPerSrcAllTestsVariation() { |
| 1560 | c.outputFile = android.OptionalPath{} |
| 1561 | return |
Roland Levillain | f2fad97 | 2019-06-28 15:41:19 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1564 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1565 | if !apexInfo.IsForPlatform() { |
| 1566 | c.hideApexVariantFromMake = true |
| 1567 | } |
| 1568 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1569 | c.makeLinkType = c.getMakeLinkType(actx) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1570 | |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1571 | c.Properties.SubName = "" |
| 1572 | |
| 1573 | if c.Target().NativeBridge == android.NativeBridgeEnabled { |
| 1574 | c.Properties.SubName += nativeBridgeSuffix |
| 1575 | } |
| 1576 | |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 1577 | _, llndk := c.linker.(*llndkStubDecorator) |
| 1578 | _, llndkHeader := c.linker.(*llndkHeadersDecorator) |
| 1579 | if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) { |
| 1580 | // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is |
| 1581 | // added for product variant only when we have vendor and product variants with core |
| 1582 | // variant. The suffix is not added for vendor-only or product-only module. |
| 1583 | c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx) |
| 1584 | } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1585 | // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with |
| 1586 | // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp. |
| 1587 | c.Properties.SubName += vendorSuffix |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 1588 | } else if c.InRamdisk() && !c.OnlyInRamdisk() { |
| 1589 | c.Properties.SubName += ramdiskSuffix |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1590 | } else if c.InRecovery() && !c.OnlyInRecovery() { |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1591 | c.Properties.SubName += recoverySuffix |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1592 | } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) { |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 1593 | c.Properties.SubName += sdkSuffix |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1594 | if c.SplitPerApiLevel() { |
| 1595 | c.Properties.SubName += "." + c.SdkVersion() |
| 1596 | } |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 1597 | } |
| 1598 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1599 | ctx := &moduleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1600 | ModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1601 | moduleContextImpl: moduleContextImpl{ |
| 1602 | mod: c, |
| 1603 | }, |
| 1604 | } |
| 1605 | ctx.ctx = ctx |
| 1606 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 1607 | deps := c.depsToPaths(ctx) |
| 1608 | if ctx.Failed() { |
| 1609 | return |
| 1610 | } |
| 1611 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 1612 | if c.Properties.Clang != nil && *c.Properties.Clang == false { |
| 1613 | ctx.PropertyErrorf("clang", "false (GCC) is no longer supported") |
| 1614 | } |
| 1615 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1616 | flags := Flags{ |
| 1617 | Toolchain: c.toolchain(ctx), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1618 | EmitXrefs: ctx.Config().EmitXrefRules(), |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1619 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1620 | if c.compiler != nil { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 1621 | flags = c.compiler.compilerFlags(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1622 | } |
| 1623 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1624 | flags = c.linker.linkerFlags(ctx, flags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1625 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1626 | if c.stl != nil { |
| 1627 | flags = c.stl.flags(ctx, flags) |
| 1628 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1629 | if c.sanitize != nil { |
| 1630 | flags = c.sanitize.flags(ctx, flags) |
| 1631 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1632 | if c.coverage != nil { |
Pirama Arumuga Nainar | 82fe59b | 2019-07-02 14:55:35 -0700 | [diff] [blame] | 1633 | flags, deps = c.coverage.flags(ctx, flags, deps) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1634 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1635 | if c.lto != nil { |
| 1636 | flags = c.lto.flags(ctx, flags) |
| 1637 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1638 | if c.pgo != nil { |
| 1639 | flags = c.pgo.flags(ctx, flags) |
| 1640 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1641 | for _, feature := range c.features { |
| 1642 | flags = feature.flags(ctx, flags) |
| 1643 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1644 | if ctx.Failed() { |
| 1645 | return |
| 1646 | } |
| 1647 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1648 | flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags) |
| 1649 | flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags) |
| 1650 | flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1651 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1652 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1653 | |
| 1654 | for _, dir := range deps.IncludeDirs { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1655 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String()) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1656 | } |
| 1657 | for _, dir := range deps.SystemIncludeDirs { |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1658 | flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String()) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 1659 | } |
| 1660 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 1661 | c.flags = flags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 1662 | // We need access to all the flags seen by a source file. |
| 1663 | if c.sabi != nil { |
| 1664 | flags = c.sabi.flags(ctx, flags) |
| 1665 | } |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 1666 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1667 | flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags) |
Dan Willemsen | 98ab311 | 2019-08-27 21:20:40 -0700 | [diff] [blame] | 1668 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1669 | // Optimization to reduce size of build.ninja |
| 1670 | // Replace the long list of flags for each file with a module-local variable |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 1671 | ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " ")) |
| 1672 | ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " ")) |
| 1673 | ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " ")) |
| 1674 | flags.Local.CFlags = []string{"$cflags"} |
| 1675 | flags.Local.CppFlags = []string{"$cppflags"} |
| 1676 | flags.Local.AsFlags = []string{"$asflags"} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1677 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1678 | var objs Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1679 | if c.compiler != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1680 | objs = c.compiler.compile(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1681 | if ctx.Failed() { |
| 1682 | return |
| 1683 | } |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 1684 | c.kytheFiles = objs.kytheFiles |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1685 | } |
| 1686 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1687 | if c.linker != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1688 | outputFile := c.linker.link(ctx, flags, deps, objs) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1689 | if ctx.Failed() { |
| 1690 | return |
| 1691 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1692 | c.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1693 | |
| 1694 | // If a lib is directly included in any of the APEXes, unhide the stubs |
| 1695 | // variant having the latest version gets visible to make. In addition, |
| 1696 | // the non-stubs variant is renamed to <libname>.bootstrap. This is to |
| 1697 | // force anything in the make world to link against the stubs library. |
| 1698 | // (unless it is explicitly referenced via .bootstrap suffix or the |
| 1699 | // module is marked with 'bootstrap: true'). |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1700 | if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() && |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1701 | !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() && |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1702 | c.IsStubs() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1703 | c.Properties.HideFromMake = false // unhide |
| 1704 | // Note: this is still non-installable |
| 1705 | } |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 1706 | |
| 1707 | // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current. |
| 1708 | if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1709 | if isSnapshotAware(ctx, c, apexInfo) { |
Inseob Kim | eda2e9c | 2020-03-03 22:06:32 +0900 | [diff] [blame] | 1710 | i.collectHeadersForSnapshot(ctx) |
| 1711 | } |
| 1712 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1713 | } |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1714 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 1715 | if c.installable(apexInfo) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1716 | c.installer.install(ctx, c.outputFile.Path()) |
| 1717 | if ctx.Failed() { |
| 1718 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1719 | } |
Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 1720 | } else if !proptools.BoolDefault(c.Properties.Installable, true) { |
| 1721 | // If the module has been specifically configure to not be installed then |
| 1722 | // skip the installation as otherwise it will break when running inside make |
| 1723 | // as the output path to install will not be specified. Not all uninstallable |
| 1724 | // modules can skip installation as some are needed for resolving make side |
| 1725 | // dependencies. |
| 1726 | c.SkipInstall() |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1727 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1730 | func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1731 | if c.cachedToolchain == nil { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 1732 | c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1733 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1734 | return c.cachedToolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1735 | } |
| 1736 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1737 | func (c *Module) begin(ctx BaseModuleContext) { |
| 1738 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1739 | c.compiler.compilerInit(ctx) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1740 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1741 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1742 | c.linker.linkerInit(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1743 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1744 | if c.stl != nil { |
| 1745 | c.stl.begin(ctx) |
| 1746 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1747 | if c.sanitize != nil { |
| 1748 | c.sanitize.begin(ctx) |
| 1749 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1750 | if c.coverage != nil { |
| 1751 | c.coverage.begin(ctx) |
| 1752 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1753 | if c.sabi != nil { |
| 1754 | c.sabi.begin(ctx) |
| 1755 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1756 | if c.vndkdep != nil { |
| 1757 | c.vndkdep.begin(ctx) |
| 1758 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1759 | if c.lto != nil { |
| 1760 | c.lto.begin(ctx) |
| 1761 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1762 | if c.pgo != nil { |
| 1763 | c.pgo.begin(ctx) |
| 1764 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1765 | for _, feature := range c.features { |
| 1766 | feature.begin(ctx) |
| 1767 | } |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1768 | if ctx.useSdk() && c.IsSdkVariant() { |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 1769 | version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion()) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1770 | if err != nil { |
| 1771 | ctx.PropertyErrorf("sdk_version", err.Error()) |
Dan Albert | 1a24627 | 2020-07-06 14:49:35 -0700 | [diff] [blame] | 1772 | c.Properties.Sdk_version = nil |
| 1773 | } else { |
| 1774 | c.Properties.Sdk_version = StringPtr(version.String()) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1775 | } |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1776 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1779 | func (c *Module) deps(ctx DepsContext) Deps { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1780 | deps := Deps{} |
| 1781 | |
| 1782 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1783 | deps = c.compiler.compilerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1784 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1785 | // Add the PGO dependency (the clang_rt.profile runtime library), which |
| 1786 | // sometimes depends on symbols from libgcc, before libgcc gets added |
| 1787 | // in linkerDeps(). |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 1788 | if c.pgo != nil { |
| 1789 | deps = c.pgo.deps(ctx, deps) |
| 1790 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1791 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1792 | deps = c.linker.linkerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1793 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1794 | if c.stl != nil { |
| 1795 | deps = c.stl.deps(ctx, deps) |
| 1796 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1797 | if c.sanitize != nil { |
| 1798 | deps = c.sanitize.deps(ctx, deps) |
| 1799 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1800 | if c.coverage != nil { |
| 1801 | deps = c.coverage.deps(ctx, deps) |
| 1802 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1803 | if c.sabi != nil { |
| 1804 | deps = c.sabi.deps(ctx, deps) |
| 1805 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1806 | if c.vndkdep != nil { |
| 1807 | deps = c.vndkdep.deps(ctx, deps) |
| 1808 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1809 | if c.lto != nil { |
| 1810 | deps = c.lto.deps(ctx, deps) |
| 1811 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1812 | for _, feature := range c.features { |
| 1813 | deps = feature.deps(ctx, deps) |
| 1814 | } |
| 1815 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1816 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
| 1817 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 1818 | deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs) |
| 1819 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1820 | deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs) |
| 1821 | deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1822 | deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1823 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1824 | for _, lib := range deps.ReexportSharedLibHeaders { |
| 1825 | if !inList(lib, deps.SharedLibs) { |
| 1826 | ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) |
| 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | for _, lib := range deps.ReexportStaticLibHeaders { |
| 1831 | if !inList(lib, deps.StaticLibs) { |
| 1832 | ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib) |
| 1833 | } |
| 1834 | } |
| 1835 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1836 | for _, lib := range deps.ReexportHeaderLibHeaders { |
| 1837 | if !inList(lib, deps.HeaderLibs) { |
| 1838 | ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib) |
| 1839 | } |
| 1840 | } |
| 1841 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1842 | for _, gen := range deps.ReexportGeneratedHeaders { |
| 1843 | if !inList(gen, deps.GeneratedHeaders) { |
| 1844 | ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen) |
| 1845 | } |
| 1846 | } |
| 1847 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1848 | return deps |
| 1849 | } |
| 1850 | |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1851 | func (c *Module) beginMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1852 | ctx := &baseModuleContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1853 | BaseModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1854 | moduleContextImpl: moduleContextImpl{ |
| 1855 | mod: c, |
| 1856 | }, |
| 1857 | } |
| 1858 | ctx.ctx = ctx |
| 1859 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1860 | c.begin(ctx) |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1863 | // Split name#version into name and version |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1864 | func StubsLibNameAndVersion(name string) (string, string) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1865 | if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 { |
| 1866 | version := name[sharp+1:] |
| 1867 | libname := name[:sharp] |
| 1868 | return libname, version |
| 1869 | } |
| 1870 | return name, "" |
| 1871 | } |
| 1872 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1873 | func GetCrtVariations(ctx android.BottomUpMutatorContext, |
| 1874 | m LinkableInterface) []blueprint.Variation { |
| 1875 | if ctx.Os() != android.Android { |
| 1876 | return nil |
| 1877 | } |
| 1878 | if m.UseSdk() { |
| 1879 | return []blueprint.Variation{ |
| 1880 | {Mutator: "sdk", Variation: "sdk"}, |
| 1881 | {Mutator: "ndk_api", Variation: m.SdkVersion()}, |
| 1882 | } |
| 1883 | } |
| 1884 | return []blueprint.Variation{ |
| 1885 | {Mutator: "sdk", Variation: ""}, |
| 1886 | } |
| 1887 | } |
| 1888 | |
Colin Cross | e7257d2 | 2020-09-24 09:56:18 -0700 | [diff] [blame] | 1889 | func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext, |
| 1890 | variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) { |
| 1891 | |
| 1892 | variations = append([]blueprint.Variation(nil), variations...) |
| 1893 | |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1894 | if version != "" && CanBeOrLinkAgainstVersionVariants(c) { |
Colin Cross | e7257d2 | 2020-09-24 09:56:18 -0700 | [diff] [blame] | 1895 | // Version is explicitly specified. i.e. libFoo#30 |
| 1896 | variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) |
| 1897 | depTag.explicitlyVersioned = true |
| 1898 | } |
| 1899 | var deps []blueprint.Module |
| 1900 | if far { |
| 1901 | deps = ctx.AddFarVariationDependencies(variations, depTag, name) |
| 1902 | } else { |
| 1903 | deps = ctx.AddVariationDependencies(variations, depTag, name) |
| 1904 | } |
| 1905 | |
| 1906 | // If the version is not specified, add dependency to all stubs libraries. |
| 1907 | // The stubs library will be used when the depending module is built for APEX and |
| 1908 | // the dependent module is not in the same APEX. |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1909 | if version == "" && CanBeOrLinkAgainstVersionVariants(c) { |
Colin Cross | e7257d2 | 2020-09-24 09:56:18 -0700 | [diff] [blame] | 1910 | if dep, ok := deps[0].(*Module); ok { |
| 1911 | for _, ver := range dep.AllStubsVersions() { |
| 1912 | // Note that depTag.ExplicitlyVersioned is false in this case. |
| 1913 | versionVariations := append(variations, |
| 1914 | blueprint.Variation{Mutator: "version", Variation: ver}) |
| 1915 | if far { |
| 1916 | ctx.AddFarVariationDependencies(versionVariations, depTag, name) |
| 1917 | } else { |
| 1918 | ctx.AddVariationDependencies(versionVariations, depTag, name) |
| 1919 | } |
| 1920 | } |
| 1921 | } |
| 1922 | } |
| 1923 | } |
| 1924 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1925 | func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1926 | if !c.Enabled() { |
| 1927 | return |
| 1928 | } |
| 1929 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1930 | ctx := &depsContext{ |
| 1931 | BottomUpMutatorContext: actx, |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1932 | moduleContextImpl: moduleContextImpl{ |
| 1933 | mod: c, |
| 1934 | }, |
| 1935 | } |
| 1936 | ctx.ctx = ctx |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1937 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1938 | deps := c.deps(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1939 | |
Yo Chiang | 219968c | 2020-09-22 18:45:04 +0800 | [diff] [blame] | 1940 | c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs |
| 1941 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1942 | variantNdkLibs := []string{} |
| 1943 | variantLateNdkLibs := []string{} |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 1944 | if ctx.Os() == android.Android { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1945 | // rewriteLibs takes a list of names of shared libraries and scans it for three types |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1946 | // of names: |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1947 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1948 | // 1. Name of an NDK library that refers to a prebuilt module. |
| 1949 | // For each of these, it adds the name of the prebuilt module (which will be in |
| 1950 | // prebuilts/ndk) to the list of nonvariant libs. |
| 1951 | // 2. Name of an NDK library that refers to an ndk_library module. |
| 1952 | // For each of these, it adds the name of the ndk_library module to the list of |
| 1953 | // variant libs. |
| 1954 | // 3. Anything else (so anything that isn't an NDK library). |
| 1955 | // It adds these to the nonvariantLibs list. |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1956 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1957 | // The caller can then know to add the variantLibs dependencies differently from the |
| 1958 | // nonvariantLibs |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1959 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1960 | vendorPublicLibraries := vendorPublicLibraries(actx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1961 | vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config()) |
| 1962 | |
| 1963 | rewriteVendorLibs := func(lib string) string { |
| 1964 | if isLlndkLibrary(lib, ctx.Config()) { |
| 1965 | return lib + llndkLibrarySuffix |
| 1966 | } |
| 1967 | |
| 1968 | // only modules with BOARD_VNDK_VERSION uses snapshot. |
| 1969 | if c.VndkVersion() != actx.DeviceConfig().VndkVersion() { |
| 1970 | return lib |
| 1971 | } |
| 1972 | |
| 1973 | if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok { |
| 1974 | return snapshot |
| 1975 | } |
| 1976 | |
| 1977 | return lib |
| 1978 | } |
| 1979 | |
| 1980 | rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1981 | variantLibs = []string{} |
| 1982 | nonvariantLibs = []string{} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1983 | for _, entry := range list { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1984 | // strip #version suffix out |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 1985 | name, _ := StubsLibNameAndVersion(entry) |
Dan Albert | de5aade | 2020-06-30 12:32:51 -0700 | [diff] [blame] | 1986 | if ctx.useSdk() && inList(name, ndkKnownLibs) { |
| 1987 | variantLibs = append(variantLibs, name+ndkLibrarySuffix) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 1988 | } else if ctx.useVndk() { |
| 1989 | nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry)) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1990 | } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1991 | vendorPublicLib := name + vendorPublicLibrarySuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1992 | if actx.OtherModuleExists(vendorPublicLib) { |
| 1993 | nonvariantLibs = append(nonvariantLibs, vendorPublicLib) |
| 1994 | } else { |
| 1995 | // This can happen if vendor_public_library module is defined in a |
| 1996 | // namespace that isn't visible to the current module. In that case, |
| 1997 | // link to the original library. |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1998 | nonvariantLibs = append(nonvariantLibs, name) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1999 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 2000 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2001 | // put name#version back |
Dan Willemsen | 7cbf5f8 | 2017-03-28 00:08:30 -0700 | [diff] [blame] | 2002 | nonvariantLibs = append(nonvariantLibs, entry) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2003 | } |
| 2004 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 2005 | return nonvariantLibs, variantLibs |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2008 | deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs) |
| 2009 | deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs) |
| 2010 | deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders) |
| 2011 | if ctx.useVndk() { |
| 2012 | for idx, lib := range deps.RuntimeLibs { |
| 2013 | deps.RuntimeLibs[idx] = rewriteVendorLibs(lib) |
| 2014 | } |
| 2015 | } |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 2016 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2017 | |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2018 | buildStubs := false |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2019 | if c.linker != nil { |
| 2020 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 2021 | if library.buildStubs() { |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2022 | buildStubs = true |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2023 | } |
| 2024 | } |
Colin Cross | d48fe73 | 2020-09-23 20:37:24 -0700 | [diff] [blame] | 2025 | if library, ok := c.linker.(*prebuiltLibraryLinker); ok { |
| 2026 | if library.buildStubs() { |
| 2027 | buildStubs = true |
| 2028 | } |
| 2029 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2030 | } |
| 2031 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2032 | rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string { |
| 2033 | // only modules with BOARD_VNDK_VERSION uses snapshot. |
| 2034 | if c.VndkVersion() != actx.DeviceConfig().VndkVersion() { |
| 2035 | return lib |
| 2036 | } |
| 2037 | |
| 2038 | if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok { |
| 2039 | return snapshot |
| 2040 | } |
| 2041 | |
| 2042 | return lib |
| 2043 | } |
| 2044 | |
| 2045 | vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config()) |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 2046 | for _, lib := range deps.HeaderLibs { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2047 | depTag := libraryDependencyTag{Kind: headerLibraryDependency} |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 2048 | if inList(lib, deps.ReexportHeaderLibHeaders) { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2049 | depTag.reexportFlags = true |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 2050 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2051 | |
| 2052 | lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs) |
| 2053 | |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2054 | if buildStubs { |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 2055 | actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()), |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 2056 | depTag, lib) |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 2057 | } else { |
| 2058 | actx.AddVariationDependencies(nil, depTag, lib) |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | if buildStubs { |
| 2063 | // Stubs lib does not have dependency to other static/shared libraries. |
| 2064 | // Don't proceed. |
| 2065 | return |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 2066 | } |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 2067 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2068 | syspropImplLibraries := syspropImplLibraries(actx.Config()) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2069 | vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config()) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2070 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 2071 | for _, lib := range deps.WholeStaticLibs { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2072 | depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true} |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 2073 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 2074 | lib = impl |
| 2075 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2076 | |
| 2077 | lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs) |
| 2078 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 2079 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2080 | {Mutator: "link", Variation: "static"}, |
| 2081 | }, depTag, lib) |
| 2082 | } |
| 2083 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2084 | for _, lib := range deps.StaticLibs { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2085 | depTag := libraryDependencyTag{Kind: staticLibraryDependency} |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2086 | if inList(lib, deps.ReexportStaticLibHeaders) { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2087 | depTag.reexportFlags = true |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2088 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2089 | |
| 2090 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 2091 | lib = impl |
| 2092 | } |
| 2093 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2094 | lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs) |
| 2095 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2096 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2097 | {Mutator: "link", Variation: "static"}, |
| 2098 | }, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2099 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2100 | |
Jooyung Han | 7556839 | 2020-03-20 04:29:24 +0900 | [diff] [blame] | 2101 | // staticUnwinderDep is treated as staticDep for Q apexes |
| 2102 | // so that native libraries/binaries are linked with static unwinder |
| 2103 | // because Q libc doesn't have unwinder APIs |
| 2104 | if deps.StaticUnwinderIfLegacy { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2105 | depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true} |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 2106 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2107 | {Mutator: "link", Variation: "static"}, |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2108 | }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs)) |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2111 | for _, lib := range deps.LateStaticLibs { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2112 | depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency} |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2113 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2114 | {Mutator: "link", Variation: "static"}, |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2115 | }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2116 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2117 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2118 | // shared lib names without the #version suffix |
| 2119 | var sharedLibNames []string |
| 2120 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2121 | for _, lib := range deps.SharedLibs { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2122 | depTag := libraryDependencyTag{Kind: sharedLibraryDependency} |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2123 | if inList(lib, deps.ReexportSharedLibHeaders) { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2124 | depTag.reexportFlags = true |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2125 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2126 | |
| 2127 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 2128 | lib = impl |
| 2129 | } |
| 2130 | |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 2131 | name, version := StubsLibNameAndVersion(lib) |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 2132 | sharedLibNames = append(sharedLibNames, name) |
| 2133 | |
Colin Cross | e7257d2 | 2020-09-24 09:56:18 -0700 | [diff] [blame] | 2134 | variations := []blueprint.Variation{ |
| 2135 | {Mutator: "link", Variation: "shared"}, |
| 2136 | } |
| 2137 | c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2138 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2139 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2140 | for _, lib := range deps.LateSharedLibs { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2141 | if inList(lib, sharedLibNames) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2142 | // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...) |
| 2143 | // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be |
| 2144 | // linking against both the stubs lib and the non-stubs lib at the same time. |
| 2145 | continue |
| 2146 | } |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2147 | depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency} |
Colin Cross | e7257d2 | 2020-09-24 09:56:18 -0700 | [diff] [blame] | 2148 | variations := []blueprint.Variation{ |
| 2149 | {Mutator: "link", Variation: "shared"}, |
| 2150 | } |
| 2151 | c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false) |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2152 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2153 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2154 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2155 | {Mutator: "link", Variation: "shared"}, |
Chris Parsons | 79d66a5 | 2020-06-05 17:26:16 -0400 | [diff] [blame] | 2156 | }, dataLibDepTag, deps.DataLibs...) |
| 2157 | |
| 2158 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 2159 | {Mutator: "link", Variation: "shared"}, |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2160 | }, runtimeDepTag, deps.RuntimeLibs...) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2161 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 2162 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 2163 | |
| 2164 | for _, gen := range deps.GeneratedHeaders { |
| 2165 | depTag := genHeaderDepTag |
| 2166 | if inList(gen, deps.ReexportGeneratedHeaders) { |
| 2167 | depTag = genHeaderExportDepTag |
| 2168 | } |
| 2169 | actx.AddDependency(c, depTag, gen) |
| 2170 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2171 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 2172 | actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2173 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 2174 | vendorSnapshotObjects := vendorSnapshotObjects(actx.Config()) |
| 2175 | |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 2176 | crtVariations := GetCrtVariations(ctx, c) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2177 | if deps.CrtBegin != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 2178 | actx.AddVariationDependencies(crtVariations, CrtBeginDepTag, |
| 2179 | rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects)) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2180 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2181 | if deps.CrtEnd != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 2182 | actx.AddVariationDependencies(crtVariations, CrtEndDepTag, |
| 2183 | rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects)) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2184 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 2185 | if deps.LinkerFlagsFile != "" { |
| 2186 | actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) |
| 2187 | } |
| 2188 | if deps.DynamicLinker != "" { |
| 2189 | actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 2190 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 2191 | |
| 2192 | version := ctx.sdkVersion() |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2193 | |
| 2194 | ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 2195 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2196 | {Mutator: "ndk_api", Variation: version}, |
| 2197 | {Mutator: "link", Variation: "shared"}, |
| 2198 | }, ndkStubDepTag, variantNdkLibs...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2199 | |
| 2200 | ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 2201 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2202 | {Mutator: "ndk_api", Variation: version}, |
| 2203 | {Mutator: "link", Variation: "shared"}, |
| 2204 | }, ndkLateStubDepTag, variantLateNdkLibs...) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2205 | |
| 2206 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 2207 | if vndkdep.isVndkExt() { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2208 | actx.AddVariationDependencies([]blueprint.Variation{ |
Colin Cross | 7228ecd | 2019-11-18 16:00:16 -0800 | [diff] [blame] | 2209 | c.ImageVariation(), |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 2210 | {Mutator: "link", Variation: "shared"}, |
| 2211 | }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName()) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2212 | } |
| 2213 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 2214 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 2215 | |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 2216 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 2217 | if c, ok := ctx.Module().(*Module); ok && c.Enabled() { |
| 2218 | c.beginMutator(ctx) |
| 2219 | } |
| 2220 | } |
| 2221 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2222 | // Whether a module can link to another module, taking into |
| 2223 | // account NDK linking. |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2224 | func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, |
| 2225 | tag blueprint.DependencyTag) { |
| 2226 | |
| 2227 | switch t := tag.(type) { |
| 2228 | case dependencyTag: |
| 2229 | if t != vndkExtDepTag { |
| 2230 | return |
| 2231 | } |
| 2232 | case libraryDependencyTag: |
| 2233 | default: |
| 2234 | return |
| 2235 | } |
| 2236 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2237 | if from.Module().Target().Os != android.Android { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2238 | // Host code is not restricted |
| 2239 | return |
| 2240 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2241 | |
| 2242 | // VNDK is cc.Module supported only for now. |
| 2243 | if ccFrom, ok := from.(*Module); ok && from.UseVndk() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2244 | // Though vendor code is limited by the vendor mutator, |
| 2245 | // each vendor-available module needs to check |
| 2246 | // link-type for VNDK. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2247 | if ccTo, ok := to.(*Module); ok { |
| 2248 | if ccFrom.vndkdep != nil { |
| 2249 | ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag) |
| 2250 | } |
| 2251 | } else { |
| 2252 | ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type") |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2253 | } |
| 2254 | return |
| 2255 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2256 | if from.SdkVersion() == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2257 | // Platform code can link to anything |
| 2258 | return |
| 2259 | } |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 2260 | if from.InRamdisk() { |
| 2261 | // Ramdisk code is not NDK |
| 2262 | return |
| 2263 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2264 | if from.InRecovery() { |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2265 | // Recovery code is not NDK |
| 2266 | return |
| 2267 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2268 | if to.ToolchainLibrary() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2269 | // These are always allowed |
| 2270 | return |
| 2271 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2272 | if to.NdkPrebuiltStl() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2273 | // These are allowed, but they don't set sdk_version |
| 2274 | return |
| 2275 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2276 | if to.StubDecorator() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2277 | // These aren't real libraries, but are the stub shared libraries that are included in |
| 2278 | // the NDK. |
| 2279 | return |
| 2280 | } |
Logan Chien | 834b9a6 | 2019-01-14 15:39:03 +0800 | [diff] [blame] | 2281 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2282 | if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" { |
Logan Chien | 834b9a6 | 2019-01-14 15:39:03 +0800 | [diff] [blame] | 2283 | // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version) |
| 2284 | // to link to libc++ (non-NDK and without sdk_version). |
| 2285 | return |
| 2286 | } |
| 2287 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2288 | if to.SdkVersion() == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2289 | // NDK code linking to platform code is never okay. |
| 2290 | ctx.ModuleErrorf("depends on non-NDK-built library %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2291 | ctx.OtherModuleName(to.Module())) |
Dan Willemsen | 155d17c | 2019-02-06 18:30:02 -0800 | [diff] [blame] | 2292 | return |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | // At this point we know we have two NDK libraries, but we need to |
| 2296 | // check that we're not linking against anything built against a higher |
| 2297 | // API level, as it is only valid to link against older or equivalent |
| 2298 | // APIs. |
| 2299 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2300 | // Current can link against anything. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2301 | if from.SdkVersion() != "current" { |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2302 | // Otherwise we need to check. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2303 | if to.SdkVersion() == "current" { |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2304 | // Current can't be linked against by anything else. |
| 2305 | ctx.ModuleErrorf("links %q built against newer API version %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2306 | ctx.OtherModuleName(to.Module()), "current") |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2307 | } else { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2308 | fromApi, err := strconv.Atoi(from.SdkVersion()) |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2309 | if err != nil { |
| 2310 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 2311 | "Invalid sdk_version value (must be int or current): %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2312 | from.SdkVersion()) |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2313 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2314 | toApi, err := strconv.Atoi(to.SdkVersion()) |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2315 | if err != nil { |
| 2316 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 2317 | "Invalid sdk_version value (must be int or current): %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2318 | to.SdkVersion()) |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2319 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2320 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2321 | if toApi > fromApi { |
| 2322 | ctx.ModuleErrorf("links %q built against newer API version %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2323 | ctx.OtherModuleName(to.Module()), to.SdkVersion()) |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 2324 | } |
| 2325 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2326 | } |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 2327 | |
| 2328 | // Also check that the two STL choices are compatible. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2329 | fromStl := from.SelectedStl() |
| 2330 | toStl := to.SelectedStl() |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 2331 | if fromStl == "" || toStl == "" { |
| 2332 | // Libraries that don't use the STL are unrestricted. |
Inseob Kim | da2171a | 2018-04-11 15:41:38 +0900 | [diff] [blame] | 2333 | } else if fromStl == "ndk_system" || toStl == "ndk_system" { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 2334 | // We can be permissive with the system "STL" since it is only the C++ |
| 2335 | // ABI layer, but in the future we should make sure that everyone is |
| 2336 | // using either libc++ or nothing. |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2337 | } else if getNdkStlFamily(from) != getNdkStlFamily(to) { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 2338 | ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q", |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2339 | from.SelectedStl(), ctx.OtherModuleName(to.Module()), |
| 2340 | to.SelectedStl()) |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 2341 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2344 | // Tests whether the dependent library is okay to be double loaded inside a single process. |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2345 | // If a library has a vendor variant and is a (transitive) dependency of an LLNDK library, |
| 2346 | // it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2347 | // or as vndk-sp (vndk: { enabled: true, support_system_process: true}). |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2348 | func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) { |
| 2349 | check := func(child, parent android.Module) bool { |
| 2350 | to, ok := child.(*Module) |
| 2351 | if !ok { |
| 2352 | // follow thru cc.Defaults, etc. |
| 2353 | return true |
| 2354 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2355 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2356 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 2357 | return false |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2358 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2359 | |
| 2360 | // if target lib has no vendor variant, keep checking dependency graph |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2361 | if !to.HasVendorVariant() { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2362 | return true |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2363 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2364 | |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2365 | if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2366 | return false |
| 2367 | } |
| 2368 | |
| 2369 | var stringPath []string |
| 2370 | for _, m := range ctx.GetWalkPath() { |
| 2371 | stringPath = append(stringPath, m.Name()) |
| 2372 | } |
| 2373 | ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+ |
| 2374 | "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+ |
| 2375 | "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> ")) |
| 2376 | return false |
| 2377 | } |
| 2378 | if module, ok := ctx.Module().(*Module); ok { |
| 2379 | if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() { |
Jooyung Han | 0302a84 | 2019-10-30 18:43:49 +0900 | [diff] [blame] | 2380 | if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 2381 | ctx.WalkDeps(check) |
| 2382 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2387 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2388 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2389 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2390 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 2391 | directStaticDeps := []LinkableInterface{} |
| 2392 | directSharedDeps := []LinkableInterface{} |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2393 | |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2394 | reexportExporter := func(exporter exportedFlagsProducer) { |
| 2395 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...) |
| 2396 | depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...) |
| 2397 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...) |
| 2398 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...) |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2399 | depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2400 | } |
| 2401 | |
Jooyung Han | de34d23 | 2020-07-23 13:04:15 +0900 | [diff] [blame] | 2402 | // For the dependency from platform to apex, use the latest stubs |
| 2403 | c.apexSdkVersion = android.FutureApiLevel |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2404 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 2405 | if !apexInfo.IsForPlatform() { |
| 2406 | c.apexSdkVersion = apexInfo.MinSdkVersion(ctx) |
Jooyung Han | de34d23 | 2020-07-23 13:04:15 +0900 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { |
| 2410 | // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) |
| 2411 | // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). |
| 2412 | // (b/144430859) |
| 2413 | c.apexSdkVersion = android.FutureApiLevel |
| 2414 | } |
| 2415 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2416 | ctx.VisitDirectDeps(func(dep android.Module) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2417 | depName := ctx.OtherModuleName(dep) |
| 2418 | depTag := ctx.OtherModuleDependencyTag(dep) |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 2419 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2420 | ccDep, ok := dep.(LinkableInterface) |
| 2421 | if !ok { |
| 2422 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2423 | // handling for a few module types that aren't cc Module but that are also supported |
| 2424 | switch depTag { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2425 | case genSourceDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2426 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2427 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 2428 | genRule.GeneratedSourceFiles()...) |
| 2429 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2430 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2431 | } |
Colin Cross | e90bfd1 | 2017-04-26 16:59:26 -0700 | [diff] [blame] | 2432 | // Support exported headers from a generated_sources dependency |
| 2433 | fallthrough |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 2434 | case genHeaderDepTag, genHeaderExportDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2435 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2436 | depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, |
Dan Willemsen | 9da9d49 | 2018-02-21 18:28:18 -0800 | [diff] [blame] | 2437 | genRule.GeneratedDeps()...) |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 2438 | dirs := genRule.GeneratedHeaderDirs() |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2439 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2440 | if depTag == genHeaderExportDepTag { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2441 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...) |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2442 | depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, |
| 2443 | genRule.GeneratedSourceFiles()...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2444 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 2445 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 2446 | c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 2447 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 2448 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2449 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2450 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 2451 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 2452 | case linkerFlagsDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2453 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 2454 | files := genRule.GeneratedSourceFiles() |
| 2455 | if len(files) == 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 2456 | depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0]) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 2457 | } else if len(files) > 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 2458 | ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 2459 | } |
| 2460 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2461 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 2462 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2463 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2464 | return |
| 2465 | } |
| 2466 | |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 2467 | if depTag == android.ProtoPluginDepTag { |
| 2468 | return |
| 2469 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2470 | if depTag == llndkImplDep { |
| 2471 | return |
| 2472 | } |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 2473 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2474 | if dep.Target().Os != ctx.Os() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2475 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 2476 | return |
| 2477 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 2478 | if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2479 | ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)", |
| 2480 | ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 2481 | return |
| 2482 | } |
| 2483 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 2484 | // re-exporting flags |
| 2485 | if depTag == reuseObjTag { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2486 | // reusing objects only make sense for cc.Modules. |
| 2487 | if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2488 | c.staticVariant = ccDep |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2489 | objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs() |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 2490 | depPaths.Objs = depPaths.Objs.Append(objs) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2491 | reexportExporter(exporter) |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 2492 | return |
| 2493 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2494 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2495 | |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2496 | if depTag == staticVariantTag { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2497 | // staticVariants are a cc.Module specific concept. |
| 2498 | if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() { |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 2499 | c.staticVariant = ccDep |
| 2500 | return |
| 2501 | } |
| 2502 | } |
| 2503 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2504 | checkLinkType(ctx, c, ccDep, depTag) |
| 2505 | |
| 2506 | linkFile := ccDep.OutputFile() |
| 2507 | |
| 2508 | if libDepTag, ok := depTag.(libraryDependencyTag); ok { |
| 2509 | // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859) |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 2510 | if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) { |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 2511 | return |
| 2512 | } |
Peter Collingbourne | dc4f986 | 2020-02-12 17:13:25 -0800 | [diff] [blame] | 2513 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2514 | if ccDep.CcLibrary() && !libDepTag.static() { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2515 | depIsStubs := ccDep.BuildStubs() |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 2516 | depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants() |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2517 | depInSameApexes := android.DirectlyInAllApexes(apexInfo, depName) |
| 2518 | depInPlatform := !dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2519 | |
| 2520 | var useThisDep bool |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2521 | if depIsStubs && libDepTag.explicitlyVersioned { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2522 | // Always respect dependency to the versioned stubs (i.e. libX#10) |
| 2523 | useThisDep = true |
| 2524 | } else if !depHasStubs { |
| 2525 | // Use non-stub variant if that is the only choice |
| 2526 | // (i.e. depending on a lib without stubs.version property) |
| 2527 | useThisDep = true |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2528 | } else if apexInfo.IsForPlatform() { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2529 | // If not building for APEX, use stubs only when it is from |
| 2530 | // an APEX (and not from platform) |
| 2531 | useThisDep = (depInPlatform != depIsStubs) |
Jooyung Han | 624d35c | 2020-04-10 12:57:24 +0900 | [diff] [blame] | 2532 | if c.bootstrap() { |
| 2533 | // However, for host, ramdisk, recovery or bootstrap modules, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2534 | // always link to non-stub variant |
| 2535 | useThisDep = !depIsStubs |
| 2536 | } |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2537 | // Another exception: if this module is bundled with an APEX, then |
| 2538 | // it is linked with the non-stub variant of a module in the APEX |
| 2539 | // as if this is part of the APEX. |
| 2540 | testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo) |
| 2541 | for _, apexContents := range testFor.ApexContents { |
| 2542 | if apexContents.DirectlyInApex(depName) { |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 2543 | useThisDep = !depIsStubs |
| 2544 | break |
| 2545 | } |
| 2546 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2547 | } else { |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 2548 | // If building for APEX, use stubs when the parent is in any APEX that |
| 2549 | // the child is not in. |
| 2550 | useThisDep = (depInSameApexes != depIsStubs) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2551 | } |
| 2552 | |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2553 | // when to use (unspecified) stubs, check min_sdk_version and choose the right one |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2554 | if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned { |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 2555 | versionToUse, err := c.ChooseSdkVersion(ctx, ccDep.StubsVersions(), c.apexSdkVersion) |
Jooyung Han | 03b5185 | 2020-02-26 22:45:42 +0900 | [diff] [blame] | 2556 | if err != nil { |
| 2557 | ctx.OtherModuleErrorf(dep, err.Error()) |
| 2558 | return |
| 2559 | } |
| 2560 | if versionToUse != ccDep.StubsVersion() { |
| 2561 | useThisDep = false |
| 2562 | } |
| 2563 | } |
| 2564 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2565 | if !useThisDep { |
| 2566 | return // stop processing this dep |
| 2567 | } |
| 2568 | } |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2569 | if c.UseVndk() { |
| 2570 | if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK |
| 2571 | // by default, use current version of LLNDK |
| 2572 | versionToUse := "" |
Colin Cross | d1f898e | 2020-08-18 18:35:15 -0700 | [diff] [blame] | 2573 | versions := m.AllStubsVersions() |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2574 | if apexInfo.ApexVariationName != "" && len(versions) > 0 { |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2575 | // if this is for use_vendor apex && dep has stubsVersions |
| 2576 | // apply the same rule of apex sdk enforcement to choose right version |
| 2577 | var err error |
Colin Cross | 7812fd3 | 2020-09-25 12:35:10 -0700 | [diff] [blame] | 2578 | versionToUse, err = c.ChooseSdkVersion(ctx, versions, c.apexSdkVersion) |
Jooyung Han | 61b66e9 | 2020-03-21 14:21:46 +0000 | [diff] [blame] | 2579 | if err != nil { |
| 2580 | ctx.OtherModuleErrorf(dep, err.Error()) |
| 2581 | return |
| 2582 | } |
| 2583 | } |
| 2584 | if versionToUse != ccDep.StubsVersion() { |
| 2585 | return |
| 2586 | } |
| 2587 | } |
| 2588 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 2589 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 2590 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...) |
| 2591 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2592 | // Exporting flags only makes sense for cc.Modules |
| 2593 | if _, ok := ccDep.(*Module); ok { |
| 2594 | if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2595 | depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...) |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2596 | depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2597 | depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2598 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2599 | if libDepTag.reexportFlags { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2600 | reexportExporter(i) |
| 2601 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
| 2602 | // Re-exported shared library headers must be included as well since they can help us with type information |
| 2603 | // about template instantiations (instantiated from their headers). |
| 2604 | // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version |
| 2605 | // scripts. |
| 2606 | c.sabi.Properties.ReexportedIncludes = append( |
| 2607 | c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...) |
| 2608 | } |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 2609 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2610 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2611 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2612 | var ptr *android.Paths |
| 2613 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2614 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2615 | depFile := android.OptionalPath{} |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 2616 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2617 | switch { |
| 2618 | case libDepTag.header(): |
| 2619 | // nothing |
| 2620 | case libDepTag.shared(): |
| 2621 | ptr = &depPaths.SharedLibs |
| 2622 | switch libDepTag.Order { |
| 2623 | case earlyLibraryDependency: |
| 2624 | ptr = &depPaths.EarlySharedLibs |
| 2625 | depPtr = &depPaths.EarlySharedLibsDeps |
| 2626 | case normalLibraryDependency: |
| 2627 | ptr = &depPaths.SharedLibs |
| 2628 | depPtr = &depPaths.SharedLibsDeps |
| 2629 | directSharedDeps = append(directSharedDeps, ccDep) |
| 2630 | case lateLibraryDependency: |
| 2631 | ptr = &depPaths.LateSharedLibs |
| 2632 | depPtr = &depPaths.LateSharedLibsDeps |
| 2633 | default: |
| 2634 | panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order)) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 2635 | } |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2636 | depFile = ccDep.Toc() |
| 2637 | case libDepTag.static(): |
| 2638 | if libDepTag.wholeStatic { |
| 2639 | ptr = &depPaths.WholeStaticLibs |
| 2640 | if !ccDep.CcLibraryInterface() || !ccDep.Static() { |
| 2641 | ctx.ModuleErrorf("module %q not a static library", depName) |
| 2642 | return |
Inseob Kim | 752edec | 2020-03-14 01:30:34 +0900 | [diff] [blame] | 2643 | } |
| 2644 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2645 | // Because the static library objects are included, this only makes sense |
| 2646 | // in the context of proper cc.Modules. |
| 2647 | if ccWholeStaticLib, ok := ccDep.(*Module); ok { |
| 2648 | staticLib := ccWholeStaticLib.linker.(libraryInterface) |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 2649 | if objs := staticLib.objs(); len(objs.objFiles) > 0 { |
| 2650 | depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(objs) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2651 | } else { |
Colin Cross | e4f6eba | 2020-09-22 18:11:25 -0700 | [diff] [blame] | 2652 | // This case normally catches prebuilt static |
| 2653 | // libraries, but it can also occur when |
| 2654 | // AllowMissingDependencies is on and the |
| 2655 | // dependencies has no sources of its own |
| 2656 | // but has a whole_static_libs dependency |
| 2657 | // on a missing library. We want to depend |
| 2658 | // on the .a file so that there is something |
| 2659 | // in the dependency tree that contains the |
| 2660 | // error rule for the missing transitive |
| 2661 | // dependency. |
| 2662 | depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path()) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2663 | } |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2664 | } else { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2665 | ctx.ModuleErrorf( |
| 2666 | "non-cc.Modules cannot be included as whole static libraries.", depName) |
| 2667 | return |
| 2668 | } |
| 2669 | |
| 2670 | } else { |
| 2671 | switch libDepTag.Order { |
| 2672 | case earlyLibraryDependency: |
| 2673 | panic(fmt.Errorf("early static libs not suppported")) |
| 2674 | case normalLibraryDependency: |
| 2675 | // static dependencies will be handled separately so they can be ordered |
| 2676 | // using transitive dependencies. |
| 2677 | ptr = nil |
| 2678 | directStaticDeps = append(directStaticDeps, ccDep) |
| 2679 | case lateLibraryDependency: |
| 2680 | ptr = &depPaths.LateStaticLibs |
| 2681 | default: |
| 2682 | panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order)) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | } |
| 2686 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2687 | if libDepTag.static() && !libDepTag.wholeStatic { |
| 2688 | if !ccDep.CcLibraryInterface() || !ccDep.Static() { |
| 2689 | ctx.ModuleErrorf("module %q not a static library", depName) |
| 2690 | return |
| 2691 | } |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 2692 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2693 | // When combining coverage files for shared libraries and executables, coverage files |
| 2694 | // in static libraries act as if they were whole static libraries. The same goes for |
| 2695 | // source based Abi dump files. |
| 2696 | if c, ok := ccDep.(*Module); ok { |
| 2697 | staticLib := c.linker.(libraryInterface) |
| 2698 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 2699 | staticLib.objs().coverageFiles...) |
| 2700 | depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, |
| 2701 | staticLib.objs().sAbiDumpFiles...) |
| 2702 | } else if c, ok := ccDep.(LinkableInterface); ok { |
| 2703 | // Handle non-CC modules here |
| 2704 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 2705 | c.CoverageFiles()...) |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2709 | if ptr != nil { |
| 2710 | if !linkFile.Valid() { |
| 2711 | if !ctx.Config().AllowMissingDependencies() { |
| 2712 | ctx.ModuleErrorf("module %q missing output file", depName) |
| 2713 | } else { |
| 2714 | ctx.AddMissingDependencies([]string{depName}) |
| 2715 | } |
| 2716 | return |
| 2717 | } |
| 2718 | *ptr = append(*ptr, linkFile.Path()) |
| 2719 | } |
| 2720 | |
| 2721 | if depPtr != nil { |
| 2722 | dep := depFile |
| 2723 | if !dep.Valid() { |
| 2724 | dep = linkFile |
| 2725 | } |
| 2726 | *depPtr = append(*depPtr, dep.Path()) |
| 2727 | } |
| 2728 | |
| 2729 | makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix |
| 2730 | switch { |
| 2731 | case libDepTag.header(): |
Colin Cross | 370173e | 2020-07-29 12:48:33 -0700 | [diff] [blame] | 2732 | c.Properties.AndroidMkHeaderLibs = append( |
| 2733 | c.Properties.AndroidMkHeaderLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2734 | case libDepTag.shared(): |
| 2735 | if ccDep.CcLibrary() { |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2736 | if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2737 | // Add the dependency to the APEX(es) providing the library so that |
| 2738 | // m <module> can trigger building the APEXes as well. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 2739 | depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo) |
| 2740 | for _, an := range depApexInfo.InApexes { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2741 | c.Properties.ApexesProvidingSharedLibs = append( |
| 2742 | c.Properties.ApexesProvidingSharedLibs, an) |
| 2743 | } |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | // Note: the order of libs in this list is not important because |
| 2748 | // they merely serve as Make dependencies and do not affect this lib itself. |
Colin Cross | 370173e | 2020-07-29 12:48:33 -0700 | [diff] [blame] | 2749 | c.Properties.AndroidMkSharedLibs = append( |
| 2750 | c.Properties.AndroidMkSharedLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2751 | // Record baseLibName for snapshots. |
| 2752 | c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName)) |
| 2753 | case libDepTag.static(): |
| 2754 | if libDepTag.wholeStatic { |
| 2755 | c.Properties.AndroidMkWholeStaticLibs = append( |
| 2756 | c.Properties.AndroidMkWholeStaticLibs, makeLibName) |
| 2757 | } else { |
| 2758 | c.Properties.AndroidMkStaticLibs = append( |
| 2759 | c.Properties.AndroidMkStaticLibs, makeLibName) |
| 2760 | } |
| 2761 | } |
| 2762 | } else { |
| 2763 | switch depTag { |
| 2764 | case runtimeDepTag: |
| 2765 | c.Properties.AndroidMkRuntimeLibs = append( |
| 2766 | c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix) |
| 2767 | // Record baseLibName for snapshots. |
| 2768 | c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName)) |
| 2769 | case objDepTag: |
| 2770 | depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) |
| 2771 | case CrtBeginDepTag: |
| 2772 | depPaths.CrtBegin = linkFile |
| 2773 | case CrtEndDepTag: |
| 2774 | depPaths.CrtEnd = linkFile |
| 2775 | case dynamicLinkerDepTag: |
| 2776 | depPaths.DynamicLinker = linkFile |
| 2777 | } |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 2778 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2779 | }) |
| 2780 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2781 | // use the ordered dependencies as this module's dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 2782 | depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 2783 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 2784 | // Dedup exported flags from dependencies |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 2785 | depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags) |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 2786 | depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs) |
| 2787 | depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs) |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2788 | depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps) |
Jiyong Park | 7495504 | 2019-10-22 20:19:51 +0900 | [diff] [blame] | 2789 | depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs) |
| 2790 | depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs) |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 2791 | depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2792 | depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps) |
Inseob Kim | d110f87 | 2019-12-06 13:15:38 +0900 | [diff] [blame] | 2793 | depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 2794 | |
| 2795 | if c.sabi != nil { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame] | 2796 | c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 2797 | } |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 2798 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2799 | return depPaths |
| 2800 | } |
| 2801 | |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 2802 | // baseLibName trims known prefixes and suffixes |
| 2803 | func baseLibName(depName string) string { |
| 2804 | libName := strings.TrimSuffix(depName, llndkLibrarySuffix) |
| 2805 | libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) |
| 2806 | libName = strings.TrimPrefix(libName, "prebuilt_") |
| 2807 | return libName |
| 2808 | } |
| 2809 | |
| 2810 | func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string { |
| 2811 | vendorSuffixModules := vendorSuffixModules(ctx.Config()) |
| 2812 | vendorPublicLibraries := vendorPublicLibraries(ctx.Config()) |
| 2813 | |
| 2814 | libName := baseLibName(depName) |
| 2815 | isLLndk := isLlndkLibrary(libName, ctx.Config()) |
| 2816 | isVendorPublicLib := inList(libName, *vendorPublicLibraries) |
| 2817 | bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk |
| 2818 | |
| 2819 | if c, ok := ccDep.(*Module); ok { |
| 2820 | // Use base module name for snapshots when exporting to Makefile. |
| 2821 | if c.isSnapshotPrebuilt() { |
| 2822 | baseName := c.BaseModuleName() |
| 2823 | |
| 2824 | if c.IsVndk() { |
| 2825 | return baseName + ".vendor" |
| 2826 | } |
| 2827 | |
| 2828 | if vendorSuffixModules[baseName] { |
| 2829 | return baseName + ".vendor" |
| 2830 | } else { |
| 2831 | return baseName |
| 2832 | } |
| 2833 | } |
| 2834 | } |
| 2835 | |
| 2836 | if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() { |
| 2837 | // The vendor module is a no-vendor-variant VNDK library. Depend on the |
| 2838 | // core module instead. |
| 2839 | return libName |
| 2840 | } else if c.UseVndk() && bothVendorAndCoreVariantsExist { |
| 2841 | // The vendor module in Make will have been renamed to not conflict with the core |
| 2842 | // module, so update the dependency name here accordingly. |
| 2843 | return libName + c.getNameSuffixWithVndkVersion(ctx) |
| 2844 | } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib { |
| 2845 | return libName + vendorPublicLibrarySuffix |
| 2846 | } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() { |
| 2847 | return libName + ramdiskSuffix |
| 2848 | } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() { |
| 2849 | return libName + recoverySuffix |
| 2850 | } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled { |
| 2851 | return libName + nativeBridgeSuffix |
| 2852 | } else { |
| 2853 | return libName |
| 2854 | } |
| 2855 | } |
| 2856 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2857 | func (c *Module) InstallInData() bool { |
| 2858 | if c.installer == nil { |
| 2859 | return false |
| 2860 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 2861 | return c.installer.inData() |
| 2862 | } |
| 2863 | |
| 2864 | func (c *Module) InstallInSanitizerDir() bool { |
| 2865 | if c.installer == nil { |
| 2866 | return false |
| 2867 | } |
| 2868 | if c.sanitize != nil && c.sanitize.inSanitizerDir() { |
Colin Cross | 9461040 | 2016-08-29 13:41:32 -0700 | [diff] [blame] | 2869 | return true |
| 2870 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 2871 | return c.installer.inSanitizerDir() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2872 | } |
| 2873 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 2874 | func (c *Module) InstallInRamdisk() bool { |
| 2875 | return c.InRamdisk() |
| 2876 | } |
| 2877 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2878 | func (c *Module) InstallInRecovery() bool { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2879 | return c.InRecovery() |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2880 | } |
| 2881 | |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 2882 | func (c *Module) MakeUninstallable() { |
Martin Stjernholm | bf37d16 | 2020-03-31 16:05:34 +0100 | [diff] [blame] | 2883 | if c.installer == nil { |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 2884 | c.ModuleBase.MakeUninstallable() |
Martin Stjernholm | bf37d16 | 2020-03-31 16:05:34 +0100 | [diff] [blame] | 2885 | return |
| 2886 | } |
Martin Stjernholm | 9e9bb7f | 2020-08-06 22:34:42 +0100 | [diff] [blame] | 2887 | c.installer.makeUninstallable(c) |
Martin Stjernholm | bf37d16 | 2020-03-31 16:05:34 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 2890 | func (c *Module) HostToolPath() android.OptionalPath { |
| 2891 | if c.installer == nil { |
| 2892 | return android.OptionalPath{} |
| 2893 | } |
| 2894 | return c.installer.hostToolPath() |
| 2895 | } |
| 2896 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 2897 | func (c *Module) IntermPathForModuleOut() android.OptionalPath { |
| 2898 | return c.outputFile |
| 2899 | } |
| 2900 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2901 | func (c *Module) OutputFiles(tag string) (android.Paths, error) { |
| 2902 | switch tag { |
| 2903 | case "": |
| 2904 | if c.outputFile.Valid() { |
| 2905 | return android.Paths{c.outputFile.Path()}, nil |
| 2906 | } |
| 2907 | return android.Paths{}, nil |
| 2908 | default: |
| 2909 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2910 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 2913 | func (c *Module) static() bool { |
| 2914 | if static, ok := c.linker.(interface { |
| 2915 | static() bool |
| 2916 | }); ok { |
| 2917 | return static.static() |
| 2918 | } |
| 2919 | return false |
| 2920 | } |
| 2921 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 2922 | func (c *Module) staticBinary() bool { |
| 2923 | if static, ok := c.linker.(interface { |
| 2924 | staticBinary() bool |
| 2925 | }); ok { |
| 2926 | return static.staticBinary() |
| 2927 | } |
| 2928 | return false |
| 2929 | } |
| 2930 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 2931 | func (c *Module) header() bool { |
| 2932 | if h, ok := c.linker.(interface { |
| 2933 | header() bool |
| 2934 | }); ok { |
| 2935 | return h.header() |
| 2936 | } |
| 2937 | return false |
| 2938 | } |
| 2939 | |
Inseob Kim | 7f283f4 | 2020-06-01 21:53:49 +0900 | [diff] [blame] | 2940 | func (c *Module) binary() bool { |
| 2941 | if b, ok := c.linker.(interface { |
| 2942 | binary() bool |
| 2943 | }); ok { |
| 2944 | return b.binary() |
| 2945 | } |
| 2946 | return false |
| 2947 | } |
| 2948 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 2949 | func (c *Module) object() bool { |
| 2950 | if o, ok := c.linker.(interface { |
| 2951 | object() bool |
| 2952 | }); ok { |
| 2953 | return o.object() |
| 2954 | } |
| 2955 | return false |
| 2956 | } |
| 2957 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2958 | func (c *Module) getMakeLinkType(actx android.ModuleContext) string { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2959 | if c.UseVndk() { |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2960 | if lib, ok := c.linker.(*llndkStubDecorator); ok { |
| 2961 | if Bool(lib.Properties.Vendor_available) { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2962 | return "native:vndk" |
| 2963 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2964 | return "native:vndk_private" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2965 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2966 | if c.IsVndk() && !c.isVndkExt() { |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2967 | if Bool(c.VendorProperties.Vendor_available) { |
| 2968 | return "native:vndk" |
| 2969 | } |
| 2970 | return "native:vndk_private" |
| 2971 | } |
Justin Yun | 5f7f7e8 | 2019-11-18 19:52:14 +0900 | [diff] [blame] | 2972 | if c.inProduct() { |
| 2973 | return "native:product" |
| 2974 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2975 | return "native:vendor" |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 2976 | } else if c.InRamdisk() { |
| 2977 | return "native:ramdisk" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2978 | } else if c.InRecovery() { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2979 | return "native:recovery" |
| 2980 | } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" { |
| 2981 | return "native:ndk:none:none" |
| 2982 | // TODO(b/114741097): use the correct ndk stl once build errors have been fixed |
| 2983 | //family, link := getNdkStlFamilyAndLinkType(c) |
| 2984 | //return fmt.Sprintf("native:ndk:%s:%s", family, link) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 2985 | } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() { |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 2986 | return "native:platform_vndk" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2987 | } else { |
| 2988 | return "native:platform" |
| 2989 | } |
| 2990 | } |
| 2991 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2992 | // Overrides ApexModule.IsInstallabeToApex() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 2993 | // Only shared/runtime libraries and "test_per_src" tests are installable to APEX. |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2994 | func (c *Module) IsInstallableToApex() bool { |
| 2995 | if shared, ok := c.linker.(interface { |
| 2996 | shared() bool |
| 2997 | }); ok { |
Jiyong Park | 73c54ee | 2019-10-22 20:31:18 +0900 | [diff] [blame] | 2998 | // Stub libs and prebuilt libs in a versioned SDK are not |
| 2999 | // installable to APEX even though they are shared libs. |
| 3000 | return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned() |
Roland Levillain | f89cd09 | 2019-07-29 16:22:59 +0100 | [diff] [blame] | 3001 | } else if _, ok := c.linker.(testPerSrc); ok { |
| 3002 | return true |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 3003 | } |
| 3004 | return false |
| 3005 | } |
| 3006 | |
Jiyong Park | a90ca00 | 2019-10-07 15:47:24 +0900 | [diff] [blame] | 3007 | func (c *Module) AvailableFor(what string) bool { |
| 3008 | if linker, ok := c.linker.(interface { |
| 3009 | availableFor(string) bool |
| 3010 | }); ok { |
| 3011 | return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what) |
| 3012 | } else { |
| 3013 | return c.ApexModuleBase.AvailableFor(what) |
| 3014 | } |
| 3015 | } |
| 3016 | |
Jiyong Park | 62304bb | 2020-04-13 16:19:48 +0900 | [diff] [blame] | 3017 | func (c *Module) TestFor() []string { |
| 3018 | if test, ok := c.linker.(interface { |
| 3019 | testFor() []string |
| 3020 | }); ok { |
| 3021 | return test.testFor() |
| 3022 | } else { |
| 3023 | return c.ApexModuleBase.TestFor() |
| 3024 | } |
| 3025 | } |
| 3026 | |
Colin Cross | aede88c | 2020-08-11 12:17:01 -0700 | [diff] [blame] | 3027 | func (c *Module) UniqueApexVariations() bool { |
| 3028 | if u, ok := c.compiler.(interface { |
| 3029 | uniqueApexVariations() bool |
| 3030 | }); ok { |
| 3031 | return u.uniqueApexVariations() |
| 3032 | } else { |
| 3033 | return false |
| 3034 | } |
| 3035 | } |
| 3036 | |
Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 3037 | // Return true if the module is ever installable. |
| 3038 | func (c *Module) EverInstallable() bool { |
| 3039 | return c.installer != nil && |
| 3040 | // Check to see whether the module is actually ever installable. |
| 3041 | c.installer.everInstallable() |
| 3042 | } |
| 3043 | |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 3044 | func (c *Module) installable(apexInfo android.ApexInfo) bool { |
Paul Duffin | 0cb37b9 | 2020-03-04 14:52:46 +0000 | [diff] [blame] | 3045 | ret := c.EverInstallable() && |
| 3046 | // Check to see whether the module has been configured to not be installed. |
| 3047 | proptools.BoolDefault(c.Properties.Installable, true) && |
| 3048 | !c.Properties.PreventInstall && c.outputFile.Valid() |
Jiyong Park | fe9a430 | 2020-01-07 16:59:44 +0900 | [diff] [blame] | 3049 | |
| 3050 | // The platform variant doesn't need further condition. Apex variants however might not |
| 3051 | // be installable because it will likely to be included in the APEX and won't appear |
| 3052 | // in the system partition. |
Colin Cross | 56a8321 | 2020-09-15 18:30:11 -0700 | [diff] [blame^] | 3053 | if apexInfo.IsForPlatform() { |
Jiyong Park | fe9a430 | 2020-01-07 16:59:44 +0900 | [diff] [blame] | 3054 | return ret |
| 3055 | } |
| 3056 | |
| 3057 | // Special case for modules that are configured to be installed to /data, which includes |
| 3058 | // test modules. For these modules, both APEX and non-APEX variants are considered as |
| 3059 | // installable. This is because even the APEX variants won't be included in the APEX, but |
| 3060 | // will anyway be installed to /data/*. |
| 3061 | // See b/146995717 |
| 3062 | if c.InstallInData() { |
| 3063 | return ret |
| 3064 | } |
| 3065 | |
| 3066 | return false |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 3067 | } |
| 3068 | |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 3069 | func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) { |
| 3070 | if c.linker != nil { |
| 3071 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 3072 | library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
| 3073 | } |
| 3074 | } |
| 3075 | } |
| 3076 | |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 3077 | func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 3078 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 3079 | libDepTag, isLibDepTag := depTag.(libraryDependencyTag) |
| 3080 | |
| 3081 | if cc, ok := dep.(*Module); ok { |
| 3082 | if cc.HasStubsVariants() { |
| 3083 | if isLibDepTag && libDepTag.shared() { |
| 3084 | // dynamic dep to a stubs lib crosses APEX boundary |
| 3085 | return false |
Jiyong Park | d7536ba | 2020-01-16 17:14:23 +0900 | [diff] [blame] | 3086 | } |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 3087 | if IsRuntimeDepTag(depTag) { |
| 3088 | // runtime dep to a stubs lib also crosses APEX boundary |
Jiyong Park | d7536ba | 2020-01-16 17:14:23 +0900 | [diff] [blame] | 3089 | return false |
| 3090 | } |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 3091 | } |
Colin Cross | aac3222 | 2020-07-29 12:51:56 -0700 | [diff] [blame] | 3092 | if isLibDepTag && c.static() && libDepTag.shared() { |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 3093 | // shared_lib dependency from a static lib is considered as crossing |
| 3094 | // the APEX boundary because the dependency doesn't actually is |
| 3095 | // linked; the dependency is used only during the compilation phase. |
| 3096 | return false |
| 3097 | } |
| 3098 | } |
| 3099 | if depTag == llndkImplDep { |
Jiyong Park | 7d95a51 | 2020-05-10 15:16:24 +0900 | [diff] [blame] | 3100 | // We don't track beyond LLNDK |
| 3101 | return false |
Jiyong Park | a7bc8ad | 2019-10-15 15:20:07 +0900 | [diff] [blame] | 3102 | } |
| 3103 | return true |
| 3104 | } |
| 3105 | |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 3106 | func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, |
| 3107 | sdkVersion android.ApiLevel) error { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3108 | // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700) |
| 3109 | if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") { |
| 3110 | return nil |
| 3111 | } |
| 3112 | // b/154569636: set min_sdk_version correctly for toolchain_libraries |
| 3113 | if c.ToolchainLibrary() { |
| 3114 | return nil |
| 3115 | } |
| 3116 | // We don't check for prebuilt modules |
| 3117 | if _, ok := c.linker.(prebuiltLinkerInterface); ok { |
| 3118 | return nil |
| 3119 | } |
| 3120 | minSdkVersion := c.MinSdkVersion() |
| 3121 | if minSdkVersion == "apex_inherit" { |
| 3122 | return nil |
| 3123 | } |
| 3124 | if minSdkVersion == "" { |
| 3125 | // JNI libs within APK-in-APEX fall into here |
| 3126 | // Those are okay to set sdk_version instead |
| 3127 | // We don't have to check if this is a SDK variant because |
| 3128 | // non-SDK variant resets sdk_version, which works too. |
| 3129 | minSdkVersion = c.SdkVersion() |
| 3130 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 3131 | if minSdkVersion == "" { |
| 3132 | return fmt.Errorf("neither min_sdk_version nor sdk_version specificed") |
| 3133 | } |
| 3134 | // Not using nativeApiLevelFromUser because the context here is not |
| 3135 | // necessarily a native context. |
| 3136 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3137 | if err != nil { |
| 3138 | return err |
| 3139 | } |
Dan Albert | c806053 | 2020-07-22 22:32:17 -0700 | [diff] [blame] | 3140 | |
| 3141 | if ver.GreaterThan(sdkVersion) { |
Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 3142 | return fmt.Errorf("newer SDK(%v)", ver) |
| 3143 | } |
| 3144 | return nil |
| 3145 | } |
| 3146 | |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 3147 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 3148 | // Defaults |
| 3149 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3150 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 3151 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 3152 | android.DefaultsModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 3153 | android.ApexModuleBase |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 3154 | } |
| 3155 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 3156 | // cc_defaults provides a set of properties that can be inherited by other cc |
| 3157 | // modules. A module can use the properties from a cc_defaults using |
| 3158 | // `defaults: ["<:default_module_name>"]`. Properties of both modules are |
| 3159 | // merged (when possible) by prepending the default module's values to the |
| 3160 | // depending module's values. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 3161 | func defaultsFactory() android.Module { |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 3162 | return DefaultsFactory() |
| 3163 | } |
| 3164 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 3165 | func DefaultsFactory(props ...interface{}) android.Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3166 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 3167 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 3168 | module.AddProperties(props...) |
| 3169 | module.AddProperties( |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3170 | &BaseProperties{}, |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 3171 | &VendorProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3172 | &BaseCompilerProperties{}, |
| 3173 | &BaseLinkerProperties{}, |
Paul Duffin | a37832a | 2019-07-18 12:31:26 +0100 | [diff] [blame] | 3174 | &ObjectLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 3175 | &LibraryProperties{}, |
Colin Cross | e1bb5d0 | 2019-09-24 14:55:04 -0700 | [diff] [blame] | 3176 | &StaticProperties{}, |
| 3177 | &SharedProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 3178 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3179 | &BinaryLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 3180 | &TestProperties{}, |
| 3181 | &TestBinaryProperties{}, |
Colin Cross | 4328765 | 2020-06-30 10:15:07 -0700 | [diff] [blame] | 3182 | &BenchmarkProperties{}, |
Mitch Phillips | 4e4ab8a | 2019-09-13 17:32:50 -0700 | [diff] [blame] | 3183 | &FuzzProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 3184 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 3185 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 3186 | &StripProperties{}, |
Dan Willemsen | 7424d61 | 2016-09-01 13:45:39 -0700 | [diff] [blame] | 3187 | &InstallerProperties{}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 3188 | &TidyProperties{}, |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 3189 | &CoverageProperties{}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 3190 | &SAbiProperties{}, |
Justin Yun | 4b2382f | 2017-07-26 14:22:10 +0900 | [diff] [blame] | 3191 | &VndkProperties{}, |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 3192 | <OProperties{}, |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 3193 | &PgoProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 3194 | &android.ProtoProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 3195 | // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules. |
| 3196 | &RustBindgenClangProperties{}, |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 3197 | ) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 3198 | |
Jooyung Han | cc372c5 | 2019-09-25 15:18:44 +0900 | [diff] [blame] | 3199 | android.InitDefaultsModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 3200 | |
| 3201 | return module |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 3204 | func squashVendorSrcs(m *Module) { |
| 3205 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 3206 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 3207 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 3208 | |
| 3209 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 3210 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
Jooyung Han | ac07f88 | 2020-07-05 03:54:35 +0900 | [diff] [blame] | 3211 | |
| 3212 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 3213 | lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...) |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 3214 | } |
| 3215 | } |
| 3216 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 3217 | func squashRecoverySrcs(m *Module) { |
| 3218 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 3219 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 3220 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 3221 | |
| 3222 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 3223 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
Jooyung Han | ac07f88 | 2020-07-05 03:54:35 +0900 | [diff] [blame] | 3224 | |
| 3225 | lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources, |
| 3226 | lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...) |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 3227 | } |
| 3228 | } |
| 3229 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 3230 | func (c *Module) IsSdkVariant() bool { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 3231 | return c.Properties.IsSdkVariant || c.AlwaysSdk() |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 3232 | } |
| 3233 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 3234 | func kytheExtractAllFactory() android.Singleton { |
| 3235 | return &kytheExtractAllSingleton{} |
| 3236 | } |
| 3237 | |
| 3238 | type kytheExtractAllSingleton struct { |
| 3239 | } |
| 3240 | |
| 3241 | func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 3242 | var xrefTargets android.Paths |
| 3243 | ctx.VisitAllModules(func(module android.Module) { |
| 3244 | if ccModule, ok := module.(xref); ok { |
| 3245 | xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...) |
| 3246 | } |
| 3247 | }) |
| 3248 | // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets |
| 3249 | if len(xrefTargets) > 0 { |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 3250 | ctx.Phony("xref_cxx", xrefTargets...) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 3251 | } |
| 3252 | } |
| 3253 | |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 3254 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 3255 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 3256 | var BoolPtr = proptools.BoolPtr |
| 3257 | var String = proptools.String |
| 3258 | var StringPtr = proptools.StringPtr |