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