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