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