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