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 ( |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "strings" |
| 24 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 27 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 28 | "android/soong/android" |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 29 | "android/soong/cc/config" |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 30 | "android/soong/genrule" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 31 | ) |
| 32 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 33 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 34 | android.RegisterModuleType("cc_defaults", defaultsFactory) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 35 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 36 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 37 | ctx.BottomUp("image", ImageMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 38 | ctx.BottomUp("link", LinkageMutator).Parallel() |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 39 | ctx.BottomUp("vndk", VndkMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 40 | ctx.BottomUp("ndk_api", ndkApiMutator).Parallel() |
| 41 | ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 42 | ctx.BottomUp("version", VersionMutator).Parallel() |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 43 | ctx.BottomUp("begin", BeginMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 44 | }) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 45 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 46 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 47 | ctx.TopDown("asan_deps", sanitizerDepsMutator(asan)) |
| 48 | ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel() |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 49 | |
Evgenii Stepanov | d97a6e9 | 2018-08-02 16:19:13 -0700 | [diff] [blame] | 50 | ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan)) |
| 51 | ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel() |
| 52 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 53 | ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi)) |
| 54 | ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel() |
| 55 | |
Peter Collingbourne | 8c7e6e2 | 2018-11-19 16:03:58 -0800 | [diff] [blame] | 56 | ctx.TopDown("scs_deps", sanitizerDepsMutator(scs)) |
| 57 | ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel() |
| 58 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 59 | ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan)) |
| 60 | ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel() |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 61 | |
Colin Cross | 6b75360 | 2018-06-21 13:03:07 -0700 | [diff] [blame] | 62 | ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator) |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 63 | ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel() |
Ivan Lozano | 30c5db2 | 2018-02-21 15:49:20 -0800 | [diff] [blame] | 64 | |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 65 | ctx.BottomUp("coverage", coverageLinkingMutator).Parallel() |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 66 | ctx.TopDown("vndk_deps", sabiDepsMutator) |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 67 | |
| 68 | ctx.TopDown("lto_deps", ltoDepsMutator) |
| 69 | ctx.BottomUp("lto", ltoMutator).Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 70 | }) |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 71 | |
| 72 | pctx.Import("android/soong/cc/config") |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 75 | type Deps struct { |
| 76 | SharedLibs, LateSharedLibs []string |
| 77 | StaticLibs, LateStaticLibs, WholeStaticLibs []string |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 78 | HeaderLibs []string |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 79 | RuntimeLibs []string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 80 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 81 | ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 82 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 83 | ObjFiles []string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 84 | |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 85 | GeneratedSources []string |
| 86 | GeneratedHeaders []string |
| 87 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 88 | ReexportGeneratedHeaders []string |
| 89 | |
Colin Cross | 97ba073 | 2015-03-23 17:50:24 -0700 | [diff] [blame] | 90 | CrtBegin, CrtEnd string |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 91 | |
| 92 | // Used for host bionic |
| 93 | LinkerFlagsFile string |
| 94 | DynamicLinker string |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 97 | type PathDeps struct { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 98 | // Paths to .so files |
| 99 | SharedLibs, LateSharedLibs android.Paths |
| 100 | // Paths to the dependencies to use for .so files (.so.toc files) |
| 101 | SharedLibsDeps, LateSharedLibsDeps android.Paths |
| 102 | // Paths to .a files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 103 | StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 104 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 105 | // Paths to .o files |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 106 | Objs Objects |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 107 | StaticLibObjs Objects |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 108 | WholeStaticLibObjs Objects |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 109 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 110 | // Paths to generated source files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 111 | GeneratedSources android.Paths |
| 112 | GeneratedHeaders android.Paths |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 113 | |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 114 | Flags, ReexportedFlags []string |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 115 | ReexportedFlagsDeps android.Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 116 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 117 | // Paths to crt*.o files |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 118 | CrtBegin, CrtEnd android.OptionalPath |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 119 | |
| 120 | // Path to the file container flags to use with the linker |
| 121 | LinkerFlagsFile android.OptionalPath |
| 122 | |
| 123 | // Path to the dynamic linker binary |
| 124 | DynamicLinker android.OptionalPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 127 | type Flags struct { |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 128 | GlobalFlags []string // Flags that apply to C, C++, and assembly source files |
| 129 | ArFlags []string // Flags that apply to ar |
| 130 | AsFlags []string // Flags that apply to assembly source files |
| 131 | CFlags []string // Flags that apply to C and C++ source files |
| 132 | ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools |
| 133 | ConlyFlags []string // Flags that apply to C source files |
| 134 | CppFlags []string // Flags that apply to C++ source files |
| 135 | ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools |
| 136 | YaccFlags []string // Flags that apply to Yacc source files |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 137 | aidlFlags []string // Flags that apply to aidl source files |
| 138 | rsFlags []string // Flags that apply to renderscript source files |
| 139 | LdFlags []string // Flags that apply to linker command lines |
| 140 | libFlags []string // Flags to add libraries early to the link order |
| 141 | TidyFlags []string // Flags that apply to clang-tidy |
| 142 | SAbiFlags []string // Flags that apply to header-abi-dumper |
| 143 | YasmFlags []string // Flags that apply to yasm assembly source files |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 144 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 145 | // Global include flags that apply to C, C++, and assembly source files |
| 146 | // These must be after any module include flags, which will be in GlobalFlags. |
| 147 | SystemIncludeFlags []string |
| 148 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 149 | Toolchain config.Toolchain |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 150 | Tidy bool |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 151 | Coverage bool |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 152 | SAbiDump bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 153 | |
| 154 | RequiredInstructionSet string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 155 | DynamicLinker string |
| 156 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 157 | CFlagsDeps android.Paths // Files depended on by compiler flags |
| 158 | LdFlagsDeps android.Paths // Files depended on by linker flags |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 159 | |
| 160 | GroupStaticLibs bool |
Dan Willemsen | 60e62f0 | 2018-11-16 21:05:32 -0800 | [diff] [blame] | 161 | |
| 162 | protoDeps android.Paths |
| 163 | protoFlags []string // Flags that apply to proto source files |
| 164 | protoOutTypeFlag string // The output type, --cpp_out for example |
| 165 | protoOutParams []string // Flags that modify the output of proto generated files |
| 166 | protoC bool // Whether to use C instead of C++ |
| 167 | protoOptionsFile bool // Whether to look for a .options file next to the .proto |
| 168 | ProtoRoot bool |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 171 | type ObjectLinkerProperties struct { |
| 172 | // names of other cc_object modules to link into this module using partial linking |
| 173 | Objs []string `android:"arch_variant"` |
Dan Willemsen | efb1dd9 | 2017-09-18 22:47:20 -0700 | [diff] [blame] | 174 | |
| 175 | // if set, add an extra objcopy --prefix-symbols= step |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 176 | Prefix_symbols *string |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 179 | // Properties used to compile all C or C++ modules |
| 180 | type BaseProperties struct { |
Dan Willemsen | 742a545 | 2018-07-23 17:19:36 -0700 | [diff] [blame] | 181 | // Deprecated. true is the default, false is invalid. |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 182 | Clang *bool `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 183 | |
| 184 | // Minimum sdk version supported when compiling against the ndk |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 185 | Sdk_version *string |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 186 | |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 187 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
| 188 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
| 189 | AndroidMkRuntimeLibs []string `blueprint:"mutated"` |
| 190 | AndroidMkWholeStaticLibs []string `blueprint:"mutated"` |
| 191 | HideFromMake bool `blueprint:"mutated"` |
| 192 | PreventInstall bool `blueprint:"mutated"` |
| 193 | ApexesProvidingSharedLibs []string `blueprint:"mutated"` |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 194 | |
| 195 | UseVndk bool `blueprint:"mutated"` |
Colin Cross | 5beccee | 2017-12-07 15:28:59 -0800 | [diff] [blame] | 196 | |
| 197 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 198 | // file |
| 199 | Logtags []string |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 200 | |
| 201 | // Make this module available when building for recovery |
| 202 | Recovery_available *bool |
| 203 | |
| 204 | InRecovery bool `blueprint:"mutated"` |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 205 | |
| 206 | // Allows this module to use non-APEX version of libraries. Useful |
| 207 | // for building binaries that are started before APEXes are activated. |
| 208 | Bootstrap *bool |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | type VendorProperties struct { |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 212 | // whether this module should be allowed to be directly depended by other |
| 213 | // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`. |
| 214 | // If set to true, two variants will be built separately, one like |
| 215 | // normal, and the other limited to the set of libraries and headers |
| 216 | // that are exposed to /vendor modules. |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 217 | // |
| 218 | // The vendor variant may be used with a different (newer) /system, |
| 219 | // so it shouldn't have any unversioned runtime dependencies, or |
| 220 | // make assumptions about the system that may not be true in the |
| 221 | // future. |
| 222 | // |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 223 | // If set to false, this module becomes inaccessible from /vendor modules. |
| 224 | // |
| 225 | // Default value is true when vndk: {enabled: true} or vendor: true. |
| 226 | // |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 227 | // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk |
| 228 | Vendor_available *bool |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 229 | |
| 230 | // whether this module is capable of being loaded with other instance |
| 231 | // (possibly an older version) of the same module in the same process. |
| 232 | // Currently, a shared library that is a member of VNDK (vndk: {enabled: true}) |
| 233 | // can be double loaded in a vendor process if the library is also a |
| 234 | // (direct and indirect) dependency of an LLNDK library. Such libraries must be |
| 235 | // explicitly marked as `double_loadable: true` by the owner, or the dependency |
| 236 | // from the LLNDK lib should be cut if the lib is not designed to be double loaded. |
| 237 | Double_loadable *bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 240 | type ModuleContextIntf interface { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 241 | static() bool |
| 242 | staticBinary() bool |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 243 | toolchain() config.Toolchain |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 244 | useSdk() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 245 | sdkVersion() string |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 246 | useVndk() bool |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 247 | isVndk() bool |
| 248 | isVndkSp() bool |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 249 | isVndkExt() bool |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 250 | inRecovery() bool |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 251 | shouldCreateVndkSourceAbiDump() bool |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 252 | selectedStl() string |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 253 | baseModuleName() string |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 254 | getVndkExtendsModuleName() string |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 255 | isPgoCompile() bool |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 256 | useClangLld(actx ModuleContext) bool |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 257 | isApex() bool |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 258 | hasStubsVariants() bool |
| 259 | isStubs() bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | type ModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 263 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 264 | ModuleContextIntf |
| 265 | } |
| 266 | |
| 267 | type BaseModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 268 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 269 | ModuleContextIntf |
| 270 | } |
| 271 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 272 | type DepsContext interface { |
| 273 | android.BottomUpMutatorContext |
| 274 | ModuleContextIntf |
| 275 | } |
| 276 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 277 | type feature interface { |
| 278 | begin(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 279 | deps(ctx DepsContext, deps Deps) Deps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 280 | flags(ctx ModuleContext, flags Flags) Flags |
| 281 | props() []interface{} |
| 282 | } |
| 283 | |
| 284 | type compiler interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 285 | compilerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 286 | compilerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 287 | compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 288 | compilerProps() []interface{} |
| 289 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 290 | appendCflags([]string) |
| 291 | appendAsflags([]string) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 292 | compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | type linker interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 296 | linkerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 297 | linkerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 298 | linkerFlags(ctx ModuleContext, flags Flags) Flags |
| 299 | linkerProps() []interface{} |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 300 | useClangLld(actx ModuleContext) bool |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 301 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 302 | link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 303 | appendLdflags([]string) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | type installer interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 307 | installerProps() []interface{} |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 308 | install(ctx ModuleContext, path android.Path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 309 | inData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 310 | inSanitizerDir() bool |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 311 | hostToolPath() android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 314 | type dependencyTag struct { |
| 315 | blueprint.BaseDependencyTag |
| 316 | name string |
| 317 | library bool |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 318 | |
| 319 | reexportFlags bool |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 320 | |
| 321 | explicitlyVersioned bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | var ( |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 325 | sharedDepTag = dependencyTag{name: "shared", library: true} |
| 326 | sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} |
| 327 | lateSharedDepTag = dependencyTag{name: "late shared", library: true} |
| 328 | staticDepTag = dependencyTag{name: "static", library: true} |
| 329 | staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} |
| 330 | lateStaticDepTag = dependencyTag{name: "late static", library: true} |
| 331 | wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 332 | headerDepTag = dependencyTag{name: "header", library: true} |
| 333 | headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 334 | genSourceDepTag = dependencyTag{name: "gen source"} |
| 335 | genHeaderDepTag = dependencyTag{name: "gen header"} |
| 336 | genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true} |
| 337 | objDepTag = dependencyTag{name: "obj"} |
| 338 | crtBeginDepTag = dependencyTag{name: "crtbegin"} |
| 339 | crtEndDepTag = dependencyTag{name: "crtend"} |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 340 | linkerFlagsDepTag = dependencyTag{name: "linker flags file"} |
| 341 | dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 342 | reuseObjTag = dependencyTag{name: "reuse objects"} |
| 343 | ndkStubDepTag = dependencyTag{name: "ndk stub", library: true} |
| 344 | ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true} |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 345 | vndkExtDepTag = dependencyTag{name: "vndk extends", library: true} |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 346 | runtimeDepTag = dependencyTag{name: "runtime lib"} |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 347 | ) |
| 348 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 349 | // Module contains the properties and members used by all C/C++ module types, and implements |
| 350 | // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces |
| 351 | // to construct the output file. Behavior can be customized with a Customizer interface |
| 352 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 353 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 354 | android.DefaultableModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 355 | android.ApexModuleBase |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 356 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 357 | Properties BaseProperties |
| 358 | VendorProperties VendorProperties |
Colin Cross | fa13879 | 2015-04-24 17:31:52 -0700 | [diff] [blame] | 359 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 360 | // initialize before calling Init |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 361 | hod android.HostOrDeviceSupported |
| 362 | multilib android.Multilib |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 363 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 364 | // delegates, initialize before calling Init |
Colin Cross | b4ce0ec | 2016-09-13 13:41:39 -0700 | [diff] [blame] | 365 | features []feature |
| 366 | compiler compiler |
| 367 | linker linker |
| 368 | installer installer |
| 369 | stl *stl |
| 370 | sanitize *sanitize |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 371 | coverage *coverage |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 372 | sabi *sabi |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 373 | vndkdep *vndkdep |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 374 | lto *lto |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 375 | pgo *pgo |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 376 | xom *xom |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 377 | |
| 378 | androidMkSharedLibDeps []string |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 379 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 380 | outputFile android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 381 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 382 | cachedToolchain config.Toolchain |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 383 | |
| 384 | subAndroidMkOnce map[subAndroidMkProvider]bool |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 385 | |
| 386 | // Flags used to compile this module |
| 387 | flags Flags |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 388 | |
| 389 | // 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] | 390 | // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 391 | // deps of this module |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 392 | depsInLinkOrder android.Paths |
| 393 | |
| 394 | // only non-nil when this is a shared library that reuses the objects of a static library |
| 395 | staticVariant *Module |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Jiyong Park | c20eee3 | 2018-09-05 22:36:17 +0900 | [diff] [blame] | 398 | func (c *Module) OutputFile() android.OptionalPath { |
| 399 | return c.outputFile |
| 400 | } |
| 401 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 402 | func (c *Module) Init() android.Module { |
Dan Willemsen | f923f2b | 2018-05-09 13:45:03 -0700 | [diff] [blame] | 403 | c.AddProperties(&c.Properties, &c.VendorProperties) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 404 | if c.compiler != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 405 | c.AddProperties(c.compiler.compilerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 406 | } |
| 407 | if c.linker != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 408 | c.AddProperties(c.linker.linkerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 409 | } |
| 410 | if c.installer != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 411 | c.AddProperties(c.installer.installerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 412 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 413 | if c.stl != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 414 | c.AddProperties(c.stl.props()...) |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 415 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 416 | if c.sanitize != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 417 | c.AddProperties(c.sanitize.props()...) |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 418 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 419 | if c.coverage != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 420 | c.AddProperties(c.coverage.props()...) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 421 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 422 | if c.sabi != nil { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 423 | c.AddProperties(c.sabi.props()...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 424 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 425 | if c.vndkdep != nil { |
| 426 | c.AddProperties(c.vndkdep.props()...) |
| 427 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 428 | if c.lto != nil { |
| 429 | c.AddProperties(c.lto.props()...) |
| 430 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 431 | if c.pgo != nil { |
| 432 | c.AddProperties(c.pgo.props()...) |
| 433 | } |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 434 | if c.xom != nil { |
| 435 | c.AddProperties(c.xom.props()...) |
| 436 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 437 | for _, feature := range c.features { |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 438 | c.AddProperties(feature.props()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 439 | } |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 440 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 441 | c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { |
| 442 | switch class { |
| 443 | case android.Device: |
| 444 | return ctx.Config().DevicePrefer32BitExecutables() |
| 445 | case android.HostCross: |
| 446 | // Windows builds always prefer 32-bit |
| 447 | return true |
| 448 | default: |
| 449 | return false |
| 450 | } |
| 451 | }) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 452 | android.InitAndroidArchModule(c, c.hod, c.multilib) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 453 | |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 454 | android.InitDefaultableModule(c) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 455 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 456 | android.InitApexModule(c) |
| 457 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 458 | return c |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 461 | // Returns true for dependency roots (binaries) |
| 462 | // TODO(ccross): also handle dlopenable libraries |
| 463 | func (c *Module) isDependencyRoot() bool { |
| 464 | if root, ok := c.linker.(interface { |
| 465 | isDependencyRoot() bool |
| 466 | }); ok { |
| 467 | return root.isDependencyRoot() |
| 468 | } |
| 469 | return false |
| 470 | } |
| 471 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 472 | func (c *Module) useVndk() bool { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 473 | return c.Properties.UseVndk |
| 474 | } |
| 475 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 476 | func (c *Module) isVndk() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 477 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 478 | return vndkdep.isVndk() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 479 | } |
| 480 | return false |
| 481 | } |
| 482 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 483 | func (c *Module) isPgoCompile() bool { |
| 484 | if pgo := c.pgo; pgo != nil { |
| 485 | return pgo.Properties.PgoCompile |
| 486 | } |
| 487 | return false |
| 488 | } |
| 489 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 490 | func (c *Module) isVndkSp() bool { |
| 491 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 492 | return vndkdep.isVndkSp() |
| 493 | } |
| 494 | return false |
| 495 | } |
| 496 | |
| 497 | func (c *Module) isVndkExt() bool { |
| 498 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 499 | return vndkdep.isVndkExt() |
| 500 | } |
| 501 | return false |
| 502 | } |
| 503 | |
| 504 | func (c *Module) getVndkExtendsModuleName() string { |
| 505 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 506 | return vndkdep.getVndkExtendsModuleName() |
| 507 | } |
| 508 | return "" |
| 509 | } |
| 510 | |
Jiyong Park | 82e2bf3 | 2017-08-16 14:05:54 +0900 | [diff] [blame] | 511 | // Returns true only when this module is configured to have core and vendor |
| 512 | // variants. |
| 513 | func (c *Module) hasVendorVariant() bool { |
| 514 | return c.isVndk() || Bool(c.VendorProperties.Vendor_available) |
| 515 | } |
| 516 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 517 | func (c *Module) inRecovery() bool { |
| 518 | return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery() |
| 519 | } |
| 520 | |
| 521 | func (c *Module) onlyInRecovery() bool { |
| 522 | return c.ModuleBase.InstallInRecovery() |
| 523 | } |
| 524 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 525 | func (c *Module) IsStubs() bool { |
| 526 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 527 | return library.buildStubs() |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 528 | } else if _, ok := c.linker.(*llndkStubDecorator); ok { |
| 529 | return true |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 530 | } |
| 531 | return false |
| 532 | } |
| 533 | |
| 534 | func (c *Module) HasStubsVariants() bool { |
| 535 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 536 | return len(library.Properties.Stubs.Versions) > 0 |
| 537 | } |
| 538 | return false |
| 539 | } |
| 540 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 541 | type baseModuleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 542 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 543 | moduleContextImpl |
| 544 | } |
| 545 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 546 | type depsContext struct { |
| 547 | android.BottomUpMutatorContext |
| 548 | moduleContextImpl |
| 549 | } |
| 550 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 551 | type moduleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 552 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 553 | moduleContextImpl |
| 554 | } |
| 555 | |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 556 | func (ctx *moduleContext) SocSpecific() bool { |
| 557 | return ctx.ModuleContext.SocSpecific() || |
| 558 | (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk()) |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 559 | } |
| 560 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 561 | type moduleContextImpl struct { |
| 562 | mod *Module |
| 563 | ctx BaseModuleContext |
| 564 | } |
| 565 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 566 | func (ctx *moduleContextImpl) toolchain() config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 567 | return ctx.mod.toolchain(ctx.ctx) |
| 568 | } |
| 569 | |
| 570 | func (ctx *moduleContextImpl) static() bool { |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 571 | return ctx.mod.static() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | func (ctx *moduleContextImpl) staticBinary() bool { |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 575 | return ctx.mod.staticBinary() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 578 | func (ctx *moduleContextImpl) useSdk() bool { |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 579 | if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 580 | return String(ctx.mod.Properties.Sdk_version) != "" |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 581 | } |
| 582 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | func (ctx *moduleContextImpl) sdkVersion() string { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 586 | if ctx.ctx.Device() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 587 | if ctx.useVndk() { |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 588 | vndk_ver := ctx.ctx.DeviceConfig().VndkVersion() |
Ryan Prichard | 0520611 | 2018-03-26 21:25:27 -0700 | [diff] [blame] | 589 | if vndk_ver == "current" { |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 590 | platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion() |
| 591 | if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) { |
| 592 | return "current" |
| 593 | } |
| 594 | return platform_vndk_ver |
| 595 | } |
| 596 | return vndk_ver |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 597 | } |
Justin Yun | 732aa6a | 2018-03-23 17:43:47 +0900 | [diff] [blame] | 598 | return String(ctx.mod.Properties.Sdk_version) |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 599 | } |
| 600 | return "" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 601 | } |
| 602 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 603 | func (ctx *moduleContextImpl) useVndk() bool { |
| 604 | return ctx.mod.useVndk() |
| 605 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 606 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 607 | func (ctx *moduleContextImpl) isVndk() bool { |
| 608 | return ctx.mod.isVndk() |
| 609 | } |
| 610 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 611 | func (ctx *moduleContextImpl) isPgoCompile() bool { |
| 612 | return ctx.mod.isPgoCompile() |
| 613 | } |
| 614 | |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 615 | func (ctx *moduleContextImpl) isVndkSp() bool { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 616 | return ctx.mod.isVndkSp() |
| 617 | } |
| 618 | |
| 619 | func (ctx *moduleContextImpl) isVndkExt() bool { |
| 620 | return ctx.mod.isVndkExt() |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 621 | } |
| 622 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 623 | func (ctx *moduleContextImpl) inRecovery() bool { |
| 624 | return ctx.mod.inRecovery() |
| 625 | } |
| 626 | |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 627 | // Check whether ABI dumps should be created for this module. |
| 628 | func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool { |
| 629 | if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") { |
| 630 | return false |
Jayant Chowdhary | ea0a2e1 | 2018-03-01 19:12:16 -0800 | [diff] [blame] | 631 | } |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 632 | if sanitize := ctx.mod.sanitize; sanitize != nil { |
| 633 | if !sanitize.isVariantOnProductionDevice() { |
| 634 | return false |
| 635 | } |
| 636 | } |
| 637 | if !ctx.ctx.Device() { |
| 638 | // Host modules do not need ABI dumps. |
| 639 | return false |
| 640 | } |
Logan Chien | fa478c0 | 2018-12-28 16:25:39 +0800 | [diff] [blame] | 641 | if !ctx.mod.IsForPlatform() { |
| 642 | // APEX variants do not need ABI dumps. |
| 643 | return false |
| 644 | } |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 645 | if inList(ctx.baseModuleName(), llndkLibraries) { |
| 646 | return true |
| 647 | } |
Logan Chien | f4b79c6 | 2018-08-02 02:27:02 +0800 | [diff] [blame] | 648 | if inList(ctx.baseModuleName(), ndkMigratedLibs) { |
| 649 | return true |
| 650 | } |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 651 | if ctx.useVndk() && ctx.isVndk() { |
| 652 | // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not |
| 653 | // VNDK-private. |
| 654 | return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt() |
| 655 | } |
| 656 | return false |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 659 | func (ctx *moduleContextImpl) selectedStl() string { |
| 660 | if stl := ctx.mod.stl; stl != nil { |
| 661 | return stl.Properties.SelectedStl |
| 662 | } |
| 663 | return "" |
| 664 | } |
| 665 | |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 666 | func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool { |
| 667 | return ctx.mod.linker.useClangLld(actx) |
| 668 | } |
| 669 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 670 | func (ctx *moduleContextImpl) baseModuleName() string { |
| 671 | return ctx.mod.ModuleBase.BaseModuleName() |
| 672 | } |
| 673 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 674 | func (ctx *moduleContextImpl) getVndkExtendsModuleName() string { |
| 675 | return ctx.mod.getVndkExtendsModuleName() |
| 676 | } |
| 677 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 678 | // Tests if this module is built for APEX |
| 679 | func (ctx *moduleContextImpl) isApex() bool { |
| 680 | return ctx.mod.ApexName() != "" |
| 681 | } |
| 682 | |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 683 | func (ctx *moduleContextImpl) hasStubsVariants() bool { |
| 684 | return ctx.mod.HasStubsVariants() |
| 685 | } |
| 686 | |
| 687 | func (ctx *moduleContextImpl) isStubs() bool { |
| 688 | return ctx.mod.IsStubs() |
| 689 | } |
| 690 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 691 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 692 | return &Module{ |
| 693 | hod: hod, |
| 694 | multilib: multilib, |
| 695 | } |
| 696 | } |
| 697 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 698 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 699 | module := newBaseModule(hod, multilib) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 700 | module.features = []feature{ |
| 701 | &tidyFeature{}, |
| 702 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 703 | module.stl = &stl{} |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 704 | module.sanitize = &sanitize{} |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 705 | module.coverage = &coverage{} |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 706 | module.sabi = &sabi{} |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 707 | module.vndkdep = &vndkdep{} |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 708 | module.lto = <o{} |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 709 | module.pgo = &pgo{} |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 710 | module.xom = &xom{} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 711 | return module |
| 712 | } |
| 713 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 714 | func (c *Module) Prebuilt() *android.Prebuilt { |
| 715 | if p, ok := c.linker.(prebuiltLinkerInterface); ok { |
| 716 | return p.prebuilt() |
| 717 | } |
| 718 | return nil |
| 719 | } |
| 720 | |
| 721 | func (c *Module) Name() string { |
| 722 | name := c.ModuleBase.Name() |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 723 | if p, ok := c.linker.(interface { |
| 724 | Name(string) string |
| 725 | }); ok { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 726 | name = p.Name(name) |
| 727 | } |
| 728 | return name |
| 729 | } |
| 730 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 731 | // orderDeps reorders dependencies into a list such that if module A depends on B, then |
| 732 | // A will precede B in the resultant list. |
| 733 | // This is convenient for passing into a linker. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 734 | // Note that directSharedDeps should be the analogous static library for each shared lib dep |
| 735 | 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] | 736 | // If A depends on B, then |
| 737 | // Every list containing A will also contain B later in the list |
| 738 | // So, after concatenating all lists, the final instance of B will have come from the same |
| 739 | // original list as the final instance of A |
| 740 | // So, the final instance of B will be later in the concatenation than the final A |
| 741 | // So, keeping only the final instance of A and of B ensures that A is earlier in the output |
| 742 | // list than B |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 743 | for _, dep := range directStaticDeps { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 744 | orderedAllDeps = append(orderedAllDeps, dep) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 745 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
| 746 | } |
| 747 | for _, dep := range directSharedDeps { |
| 748 | orderedAllDeps = append(orderedAllDeps, dep) |
| 749 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 752 | orderedAllDeps = android.LastUniquePaths(orderedAllDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 753 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 754 | // 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] | 755 | // intentionally exclude or replace any unwanted transitive dependencies), so we limit the |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 756 | // resultant list to only what the caller has chosen to include in directStaticDeps |
| 757 | _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 758 | |
| 759 | return orderedAllDeps, orderedDeclaredDeps |
| 760 | } |
| 761 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 762 | func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) { |
| 763 | // convert Module to Path |
| 764 | allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps)) |
| 765 | staticDepFiles := []android.Path{} |
| 766 | for _, dep := range staticDeps { |
| 767 | allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder |
| 768 | staticDepFiles = append(staticDepFiles, dep.outputFile.Path()) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 769 | } |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 770 | sharedDepFiles := []android.Path{} |
| 771 | for _, sharedDep := range sharedDeps { |
| 772 | staticAnalogue := sharedDep.staticVariant |
| 773 | if staticAnalogue != nil { |
| 774 | allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder |
| 775 | sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path()) |
| 776 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | // reorder the dependencies based on transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 780 | module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 781 | |
| 782 | return results |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 785 | func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 786 | ctx := &moduleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 787 | ModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 788 | moduleContextImpl: moduleContextImpl{ |
| 789 | mod: c, |
| 790 | }, |
| 791 | } |
| 792 | ctx.ctx = ctx |
| 793 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 794 | deps := c.depsToPaths(ctx) |
| 795 | if ctx.Failed() { |
| 796 | return |
| 797 | } |
| 798 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 799 | if c.Properties.Clang != nil && *c.Properties.Clang == false { |
| 800 | ctx.PropertyErrorf("clang", "false (GCC) is no longer supported") |
| 801 | } |
| 802 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 803 | flags := Flags{ |
| 804 | Toolchain: c.toolchain(ctx), |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 805 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 806 | if c.compiler != nil { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 807 | flags = c.compiler.compilerFlags(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 808 | } |
| 809 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 810 | flags = c.linker.linkerFlags(ctx, flags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 811 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 812 | if c.stl != nil { |
| 813 | flags = c.stl.flags(ctx, flags) |
| 814 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 815 | if c.sanitize != nil { |
| 816 | flags = c.sanitize.flags(ctx, flags) |
| 817 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 818 | if c.coverage != nil { |
| 819 | flags = c.coverage.flags(ctx, flags) |
| 820 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 821 | if c.lto != nil { |
| 822 | flags = c.lto.flags(ctx, flags) |
| 823 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 824 | if c.pgo != nil { |
| 825 | flags = c.pgo.flags(ctx, flags) |
| 826 | } |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 827 | if c.xom != nil { |
| 828 | flags = c.xom.flags(ctx, flags) |
| 829 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 830 | for _, feature := range c.features { |
| 831 | flags = feature.flags(ctx, flags) |
| 832 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 833 | if ctx.Failed() { |
| 834 | return |
| 835 | } |
| 836 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 837 | flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags) |
| 838 | flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags) |
| 839 | flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 840 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 841 | flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) |
| 842 | c.flags = flags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 843 | // We need access to all the flags seen by a source file. |
| 844 | if c.sabi != nil { |
| 845 | flags = c.sabi.flags(ctx, flags) |
| 846 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 847 | // Optimization to reduce size of build.ninja |
| 848 | // Replace the long list of flags for each file with a module-local variable |
| 849 | ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) |
| 850 | ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) |
| 851 | ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) |
| 852 | flags.CFlags = []string{"$cflags"} |
| 853 | flags.CppFlags = []string{"$cppflags"} |
| 854 | flags.AsFlags = []string{"$asflags"} |
| 855 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 856 | var objs Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 857 | if c.compiler != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 858 | objs = c.compiler.compile(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 859 | if ctx.Failed() { |
| 860 | return |
| 861 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 862 | } |
| 863 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 864 | if c.linker != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 865 | outputFile := c.linker.link(ctx, flags, deps, objs) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 866 | if ctx.Failed() { |
| 867 | return |
| 868 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 869 | c.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 870 | |
| 871 | // If a lib is directly included in any of the APEXes, unhide the stubs |
| 872 | // variant having the latest version gets visible to make. In addition, |
| 873 | // the non-stubs variant is renamed to <libname>.bootstrap. This is to |
| 874 | // force anything in the make world to link against the stubs library. |
| 875 | // (unless it is explicitly referenced via .bootstrap suffix or the |
| 876 | // module is marked with 'bootstrap: true'). |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame^] | 877 | if c.HasStubsVariants() && |
| 878 | android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 879 | !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() { |
| 880 | c.Properties.HideFromMake = false // unhide |
| 881 | // Note: this is still non-installable |
| 882 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 883 | } |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 884 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 885 | if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 886 | c.installer.install(ctx, c.outputFile.Path()) |
| 887 | if ctx.Failed() { |
| 888 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 889 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 890 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 893 | func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 894 | if c.cachedToolchain == nil { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 895 | c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 896 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 897 | return c.cachedToolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 900 | func (c *Module) begin(ctx BaseModuleContext) { |
| 901 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 902 | c.compiler.compilerInit(ctx) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 903 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 904 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 905 | c.linker.linkerInit(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 906 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 907 | if c.stl != nil { |
| 908 | c.stl.begin(ctx) |
| 909 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 910 | if c.sanitize != nil { |
| 911 | c.sanitize.begin(ctx) |
| 912 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 913 | if c.coverage != nil { |
| 914 | c.coverage.begin(ctx) |
| 915 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 916 | if c.sabi != nil { |
| 917 | c.sabi.begin(ctx) |
| 918 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 919 | if c.vndkdep != nil { |
| 920 | c.vndkdep.begin(ctx) |
| 921 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 922 | if c.lto != nil { |
| 923 | c.lto.begin(ctx) |
| 924 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 925 | if c.pgo != nil { |
| 926 | c.pgo.begin(ctx) |
| 927 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 928 | for _, feature := range c.features { |
| 929 | feature.begin(ctx) |
| 930 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 931 | if ctx.useSdk() { |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 932 | version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch()) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 933 | if err != nil { |
| 934 | ctx.PropertyErrorf("sdk_version", err.Error()) |
| 935 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 936 | c.Properties.Sdk_version = StringPtr(version) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 937 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 940 | func (c *Module) deps(ctx DepsContext) Deps { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 941 | deps := Deps{} |
| 942 | |
| 943 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 944 | deps = c.compiler.compilerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 945 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 946 | // Add the PGO dependency (the clang_rt.profile runtime library), which |
| 947 | // sometimes depends on symbols from libgcc, before libgcc gets added |
| 948 | // in linkerDeps(). |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 949 | if c.pgo != nil { |
| 950 | deps = c.pgo.deps(ctx, deps) |
| 951 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 952 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 953 | deps = c.linker.linkerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 954 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 955 | if c.stl != nil { |
| 956 | deps = c.stl.deps(ctx, deps) |
| 957 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 958 | if c.sanitize != nil { |
| 959 | deps = c.sanitize.deps(ctx, deps) |
| 960 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 961 | if c.coverage != nil { |
| 962 | deps = c.coverage.deps(ctx, deps) |
| 963 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 964 | if c.sabi != nil { |
| 965 | deps = c.sabi.deps(ctx, deps) |
| 966 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 967 | if c.vndkdep != nil { |
| 968 | deps = c.vndkdep.deps(ctx, deps) |
| 969 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 970 | if c.lto != nil { |
| 971 | deps = c.lto.deps(ctx, deps) |
| 972 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 973 | for _, feature := range c.features { |
| 974 | deps = feature.deps(ctx, deps) |
| 975 | } |
| 976 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 977 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
| 978 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 979 | deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs) |
| 980 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 981 | deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs) |
| 982 | deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 983 | deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 984 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 985 | for _, lib := range deps.ReexportSharedLibHeaders { |
| 986 | if !inList(lib, deps.SharedLibs) { |
| 987 | ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | for _, lib := range deps.ReexportStaticLibHeaders { |
| 992 | if !inList(lib, deps.StaticLibs) { |
| 993 | ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib) |
| 994 | } |
| 995 | } |
| 996 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 997 | for _, lib := range deps.ReexportHeaderLibHeaders { |
| 998 | if !inList(lib, deps.HeaderLibs) { |
| 999 | ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib) |
| 1000 | } |
| 1001 | } |
| 1002 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1003 | for _, gen := range deps.ReexportGeneratedHeaders { |
| 1004 | if !inList(gen, deps.GeneratedHeaders) { |
| 1005 | ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen) |
| 1006 | } |
| 1007 | } |
| 1008 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1009 | return deps |
| 1010 | } |
| 1011 | |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1012 | func (c *Module) beginMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1013 | ctx := &baseModuleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1014 | BaseContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1015 | moduleContextImpl: moduleContextImpl{ |
| 1016 | mod: c, |
| 1017 | }, |
| 1018 | } |
| 1019 | ctx.ctx = ctx |
| 1020 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1021 | c.begin(ctx) |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1024 | // Split name#version into name and version |
| 1025 | func stubsLibNameAndVersion(name string) (string, string) { |
| 1026 | if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 { |
| 1027 | version := name[sharp+1:] |
| 1028 | libname := name[:sharp] |
| 1029 | return libname, version |
| 1030 | } |
| 1031 | return name, "" |
| 1032 | } |
| 1033 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1034 | func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1035 | ctx := &depsContext{ |
| 1036 | BottomUpMutatorContext: actx, |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1037 | moduleContextImpl: moduleContextImpl{ |
| 1038 | mod: c, |
| 1039 | }, |
| 1040 | } |
| 1041 | ctx.ctx = ctx |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1042 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1043 | deps := c.deps(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1044 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1045 | variantNdkLibs := []string{} |
| 1046 | variantLateNdkLibs := []string{} |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 1047 | if ctx.Os() == android.Android { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1048 | version := ctx.sdkVersion() |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1049 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1050 | // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types |
| 1051 | // of names: |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1052 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1053 | // 1. Name of an NDK library that refers to a prebuilt module. |
| 1054 | // For each of these, it adds the name of the prebuilt module (which will be in |
| 1055 | // prebuilts/ndk) to the list of nonvariant libs. |
| 1056 | // 2. Name of an NDK library that refers to an ndk_library module. |
| 1057 | // For each of these, it adds the name of the ndk_library module to the list of |
| 1058 | // variant libs. |
| 1059 | // 3. Anything else (so anything that isn't an NDK library). |
| 1060 | // It adds these to the nonvariantLibs list. |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1061 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1062 | // The caller can then know to add the variantLibs dependencies differently from the |
| 1063 | // nonvariantLibs |
| 1064 | rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { |
| 1065 | variantLibs = []string{} |
| 1066 | nonvariantLibs = []string{} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1067 | for _, entry := range list { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1068 | // strip #version suffix out |
| 1069 | name, _ := stubsLibNameAndVersion(entry) |
| 1070 | if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) { |
| 1071 | if !inList(name, ndkMigratedLibs) { |
| 1072 | nonvariantLibs = append(nonvariantLibs, name+".ndk."+version) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1073 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1074 | variantLibs = append(variantLibs, name+ndkLibrarySuffix) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1075 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1076 | } else if ctx.useVndk() && inList(name, llndkLibraries) { |
| 1077 | nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix) |
| 1078 | } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) { |
| 1079 | vendorPublicLib := name + vendorPublicLibrarySuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1080 | if actx.OtherModuleExists(vendorPublicLib) { |
| 1081 | nonvariantLibs = append(nonvariantLibs, vendorPublicLib) |
| 1082 | } else { |
| 1083 | // This can happen if vendor_public_library module is defined in a |
| 1084 | // namespace that isn't visible to the current module. In that case, |
| 1085 | // link to the original library. |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1086 | nonvariantLibs = append(nonvariantLibs, name) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1087 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1088 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1089 | // put name#version back |
Dan Willemsen | 7cbf5f8 | 2017-03-28 00:08:30 -0700 | [diff] [blame] | 1090 | nonvariantLibs = append(nonvariantLibs, entry) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1093 | return nonvariantLibs, variantLibs |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1096 | deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs) |
| 1097 | deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs) |
Jiyong Park | 4c35af0 | 2017-07-05 13:41:55 +0900 | [diff] [blame] | 1098 | deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1099 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1100 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1101 | if c.linker != nil { |
| 1102 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 1103 | if library.buildStubs() { |
| 1104 | // Stubs lib does not have dependency to other libraries. Don't proceed. |
| 1105 | return |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 1110 | for _, lib := range deps.HeaderLibs { |
| 1111 | depTag := headerDepTag |
| 1112 | if inList(lib, deps.ReexportHeaderLibHeaders) { |
| 1113 | depTag = headerExportDepTag |
| 1114 | } |
| 1115 | actx.AddVariationDependencies(nil, depTag, lib) |
| 1116 | } |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1117 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1118 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1119 | {Mutator: "link", Variation: "static"}, |
| 1120 | }, wholeStaticDepTag, deps.WholeStaticLibs...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1121 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1122 | for _, lib := range deps.StaticLibs { |
| 1123 | depTag := staticDepTag |
| 1124 | if inList(lib, deps.ReexportStaticLibHeaders) { |
| 1125 | depTag = staticExportDepTag |
| 1126 | } |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1127 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1128 | {Mutator: "link", Variation: "static"}, |
| 1129 | }, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1130 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1131 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1132 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1133 | {Mutator: "link", Variation: "static"}, |
| 1134 | }, lateStaticDepTag, deps.LateStaticLibs...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1135 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1136 | addSharedLibDependencies := func(depTag dependencyTag, name string, version string) { |
| 1137 | var variations []blueprint.Variation |
| 1138 | variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Jiyong Park | 0fefdea | 2018-12-13 12:01:31 +0900 | [diff] [blame] | 1139 | versionVariantAvail := !ctx.useVndk() && !c.inRecovery() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1140 | if version != "" && versionVariantAvail { |
| 1141 | // Version is explicitly specified. i.e. libFoo#30 |
| 1142 | variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) |
| 1143 | depTag.explicitlyVersioned = true |
| 1144 | } |
| 1145 | actx.AddVariationDependencies(variations, depTag, name) |
| 1146 | |
| 1147 | // If the version is not specified, add dependency to the latest stubs library. |
| 1148 | // The stubs library will be used when the depending module is built for APEX and |
| 1149 | // the dependent module is not in the same APEX. |
| 1150 | latestVersion := latestStubsVersionFor(actx.Config(), name) |
| 1151 | if version == "" && latestVersion != "" && versionVariantAvail { |
| 1152 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1153 | {Mutator: "link", Variation: "shared"}, |
| 1154 | {Mutator: "version", Variation: latestVersion}, |
| 1155 | }, depTag, name) |
| 1156 | // Note that depTag.explicitlyVersioned is false in this case. |
| 1157 | } |
| 1158 | } |
| 1159 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1160 | // shared lib names without the #version suffix |
| 1161 | var sharedLibNames []string |
| 1162 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1163 | for _, lib := range deps.SharedLibs { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1164 | name, version := stubsLibNameAndVersion(lib) |
| 1165 | sharedLibNames = append(sharedLibNames, name) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1166 | depTag := sharedDepTag |
| 1167 | if inList(lib, deps.ReexportSharedLibHeaders) { |
| 1168 | depTag = sharedExportDepTag |
| 1169 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1170 | addSharedLibDependencies(depTag, name, version) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1171 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1172 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1173 | for _, lib := range deps.LateSharedLibs { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1174 | if inList(lib, sharedLibNames) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1175 | // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...) |
| 1176 | // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be |
| 1177 | // linking against both the stubs lib and the non-stubs lib at the same time. |
| 1178 | continue |
| 1179 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1180 | addSharedLibDependencies(lateSharedDepTag, lib, "") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1181 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1182 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1183 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1184 | {Mutator: "link", Variation: "shared"}, |
| 1185 | }, runtimeDepTag, deps.RuntimeLibs...) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1186 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1187 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1188 | |
| 1189 | for _, gen := range deps.GeneratedHeaders { |
| 1190 | depTag := genHeaderDepTag |
| 1191 | if inList(gen, deps.ReexportGeneratedHeaders) { |
| 1192 | depTag = genHeaderExportDepTag |
| 1193 | } |
| 1194 | actx.AddDependency(c, depTag, gen) |
| 1195 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1196 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1197 | actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1198 | |
| 1199 | if deps.CrtBegin != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1200 | actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1201 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1202 | if deps.CrtEnd != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1203 | actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1204 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1205 | if deps.LinkerFlagsFile != "" { |
| 1206 | actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) |
| 1207 | } |
| 1208 | if deps.DynamicLinker != "" { |
| 1209 | actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1210 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1211 | |
| 1212 | version := ctx.sdkVersion() |
| 1213 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1214 | {Mutator: "ndk_api", Variation: version}, |
| 1215 | {Mutator: "link", Variation: "shared"}, |
| 1216 | }, ndkStubDepTag, variantNdkLibs...) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1217 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1218 | {Mutator: "ndk_api", Variation: version}, |
| 1219 | {Mutator: "link", Variation: "shared"}, |
| 1220 | }, ndkLateStubDepTag, variantLateNdkLibs...) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1221 | |
| 1222 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1223 | if vndkdep.isVndkExt() { |
| 1224 | baseModuleMode := vendorMode |
| 1225 | if actx.DeviceConfig().VndkVersion() == "" { |
| 1226 | baseModuleMode = coreMode |
| 1227 | } |
| 1228 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1229 | {Mutator: "image", Variation: baseModuleMode}, |
| 1230 | {Mutator: "link", Variation: "shared"}, |
| 1231 | }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName()) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1232 | } |
| 1233 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 1234 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1235 | |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 1236 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1237 | if c, ok := ctx.Module().(*Module); ok && c.Enabled() { |
| 1238 | c.beginMutator(ctx) |
| 1239 | } |
| 1240 | } |
| 1241 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1242 | // Whether a module can link to another module, taking into |
| 1243 | // account NDK linking. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1244 | func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1245 | if from.Target().Os != android.Android { |
| 1246 | // Host code is not restricted |
| 1247 | return |
| 1248 | } |
| 1249 | if from.Properties.UseVndk { |
| 1250 | // Though vendor code is limited by the vendor mutator, |
| 1251 | // each vendor-available module needs to check |
| 1252 | // link-type for VNDK. |
| 1253 | if from.vndkdep != nil { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1254 | from.vndkdep.vndkCheckLinkType(ctx, to, tag) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1255 | } |
| 1256 | return |
| 1257 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1258 | if String(from.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1259 | // Platform code can link to anything |
| 1260 | return |
| 1261 | } |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1262 | if from.inRecovery() { |
| 1263 | // Recovery code is not NDK |
| 1264 | return |
| 1265 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1266 | if _, ok := to.linker.(*toolchainLibraryDecorator); ok { |
| 1267 | // These are always allowed |
| 1268 | return |
| 1269 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1270 | if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { |
| 1271 | // These are allowed, but they don't set sdk_version |
| 1272 | return |
| 1273 | } |
| 1274 | if _, ok := to.linker.(*stubDecorator); ok { |
| 1275 | // These aren't real libraries, but are the stub shared libraries that are included in |
| 1276 | // the NDK. |
| 1277 | return |
| 1278 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1279 | if String(to.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1280 | // NDK code linking to platform code is never okay. |
| 1281 | ctx.ModuleErrorf("depends on non-NDK-built library %q", |
| 1282 | ctx.OtherModuleName(to)) |
| 1283 | } |
| 1284 | |
| 1285 | // At this point we know we have two NDK libraries, but we need to |
| 1286 | // check that we're not linking against anything built against a higher |
| 1287 | // API level, as it is only valid to link against older or equivalent |
| 1288 | // APIs. |
| 1289 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1290 | // Current can link against anything. |
| 1291 | if String(from.Properties.Sdk_version) != "current" { |
| 1292 | // Otherwise we need to check. |
| 1293 | if String(to.Properties.Sdk_version) == "current" { |
| 1294 | // Current can't be linked against by anything else. |
| 1295 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1296 | ctx.OtherModuleName(to), "current") |
| 1297 | } else { |
| 1298 | fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version)) |
| 1299 | if err != nil { |
| 1300 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1301 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1302 | String(from.Properties.Sdk_version)) |
| 1303 | } |
| 1304 | toApi, err := strconv.Atoi(String(to.Properties.Sdk_version)) |
| 1305 | if err != nil { |
| 1306 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1307 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1308 | String(to.Properties.Sdk_version)) |
| 1309 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1310 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1311 | if toApi > fromApi { |
| 1312 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1313 | ctx.OtherModuleName(to), String(to.Properties.Sdk_version)) |
| 1314 | } |
| 1315 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1316 | } |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1317 | |
| 1318 | // Also check that the two STL choices are compatible. |
| 1319 | fromStl := from.stl.Properties.SelectedStl |
| 1320 | toStl := to.stl.Properties.SelectedStl |
| 1321 | if fromStl == "" || toStl == "" { |
| 1322 | // Libraries that don't use the STL are unrestricted. |
Inseob Kim | da2171a | 2018-04-11 15:41:38 +0900 | [diff] [blame] | 1323 | } else if fromStl == "ndk_system" || toStl == "ndk_system" { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1324 | // We can be permissive with the system "STL" since it is only the C++ |
| 1325 | // ABI layer, but in the future we should make sure that everyone is |
| 1326 | // using either libc++ or nothing. |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1327 | } else if getNdkStlFamily(from) != getNdkStlFamily(to) { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1328 | ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q", |
| 1329 | from.stl.Properties.SelectedStl, ctx.OtherModuleName(to), |
| 1330 | to.stl.Properties.SelectedStl) |
| 1331 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1334 | // Tests whether the dependent library is okay to be double loaded inside a single process. |
| 1335 | // If a library is a member of VNDK and at the same time dependencies of an LLNDK library, |
| 1336 | // it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true |
| 1337 | // or as vndk-sp (vndk: { enabled: true, support_system_process: true}). |
| 1338 | func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) { |
| 1339 | if _, ok := from.linker.(*libraryDecorator); !ok { |
| 1340 | return |
| 1341 | } |
| 1342 | |
| 1343 | if inList(ctx.ModuleName(), llndkLibraries) || |
| 1344 | (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) { |
| 1345 | _, depIsLlndk := to.linker.(*llndkStubDecorator) |
| 1346 | depIsVndkSp := false |
| 1347 | if to.vndkdep != nil && to.vndkdep.isVndkSp() { |
| 1348 | depIsVndkSp = true |
| 1349 | } |
| 1350 | depIsVndk := false |
| 1351 | if to.vndkdep != nil && to.vndkdep.isVndk() { |
| 1352 | depIsVndk = true |
| 1353 | } |
| 1354 | depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable) |
| 1355 | if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk { |
Steven Moreland | 742989e | 2018-11-26 12:41:04 -0800 | [diff] [blame] | 1356 | ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+ |
| 1357 | "VNDK-SP, or explicitly marked as 'double_loadable').", |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1358 | ctx.OtherModuleName(to)) |
| 1359 | } |
| 1360 | } |
| 1361 | } |
| 1362 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1363 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1364 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1365 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1366 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1367 | directStaticDeps := []*Module{} |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1368 | directSharedDeps := []*Module{} |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1369 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1370 | ctx.VisitDirectDeps(func(dep android.Module) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1371 | depName := ctx.OtherModuleName(dep) |
| 1372 | depTag := ctx.OtherModuleDependencyTag(dep) |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 1373 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1374 | ccDep, _ := dep.(*Module) |
| 1375 | if ccDep == nil { |
| 1376 | // handling for a few module types that aren't cc Module but that are also supported |
| 1377 | switch depTag { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1378 | case genSourceDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1379 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1380 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 1381 | genRule.GeneratedSourceFiles()...) |
| 1382 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1383 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1384 | } |
Colin Cross | e90bfd1 | 2017-04-26 16:59:26 -0700 | [diff] [blame] | 1385 | // Support exported headers from a generated_sources dependency |
| 1386 | fallthrough |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1387 | case genHeaderDepTag, genHeaderExportDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1388 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1389 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
Dan Willemsen | 9da9d49 | 2018-02-21 18:28:18 -0800 | [diff] [blame] | 1390 | genRule.GeneratedDeps()...) |
Colin Cross | 5ed99c6 | 2016-11-22 12:55:55 -0800 | [diff] [blame] | 1391 | flags := includeDirsToFlags(genRule.GeneratedHeaderDirs()) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1392 | depPaths.Flags = append(depPaths.Flags, flags) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1393 | if depTag == genHeaderExportDepTag { |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1394 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 1395 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, |
Dan Willemsen | 9da9d49 | 2018-02-21 18:28:18 -0800 | [diff] [blame] | 1396 | genRule.GeneratedDeps()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1397 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
| 1398 | c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags) |
| 1399 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1400 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1401 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1402 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1403 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1404 | case linkerFlagsDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1405 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1406 | files := genRule.GeneratedSourceFiles() |
| 1407 | if len(files) == 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1408 | depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0]) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1409 | } else if len(files) > 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1410 | 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] | 1411 | } |
| 1412 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1413 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1414 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1415 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1416 | return |
| 1417 | } |
| 1418 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1419 | if dep.Target().Os != ctx.Os() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1420 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1421 | return |
| 1422 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1423 | if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1424 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1425 | return |
| 1426 | } |
| 1427 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1428 | // re-exporting flags |
| 1429 | if depTag == reuseObjTag { |
| 1430 | if l, ok := ccDep.compiler.(libraryInterface); ok { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1431 | c.staticVariant = ccDep |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 1432 | objs, flags, deps := l.reuseObjs() |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 1433 | depPaths.Objs = depPaths.Objs.Append(objs) |
| 1434 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 1435 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...) |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 1436 | return |
| 1437 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1438 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1439 | |
| 1440 | // Extract explicitlyVersioned field from the depTag and reset it inside the struct. |
| 1441 | // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true |
| 1442 | // won't be matched to sharedDepTag and lateSharedDepTag. |
| 1443 | explicitlyVersioned := false |
| 1444 | if t, ok := depTag.(dependencyTag); ok { |
| 1445 | explicitlyVersioned = t.explicitlyVersioned |
| 1446 | t.explicitlyVersioned = false |
| 1447 | depTag = t |
| 1448 | } |
| 1449 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1450 | if t, ok := depTag.(dependencyTag); ok && t.library { |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1451 | depIsStatic := false |
| 1452 | switch depTag { |
| 1453 | case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: |
| 1454 | depIsStatic = true |
| 1455 | } |
| 1456 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1457 | depIsStubs := dependentLibrary.buildStubs() |
| 1458 | depHasStubs := ccDep.HasStubsVariants() |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1459 | depInSameApex := android.DirectlyInApex(c.ApexName(), depName) |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame^] | 1460 | depInPlatform := !android.DirectlyInAnyApex(ctx, depName) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1461 | |
| 1462 | var useThisDep bool |
| 1463 | if depIsStubs && explicitlyVersioned { |
| 1464 | // Always respect dependency to the versioned stubs (i.e. libX#10) |
| 1465 | useThisDep = true |
| 1466 | } else if !depHasStubs { |
| 1467 | // Use non-stub variant if that is the only choice |
| 1468 | // (i.e. depending on a lib without stubs.version property) |
| 1469 | useThisDep = true |
| 1470 | } else if c.IsForPlatform() { |
| 1471 | // If not building for APEX, use stubs only when it is from |
| 1472 | // an APEX (and not from platform) |
| 1473 | useThisDep = (depInPlatform != depIsStubs) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1474 | if c.inRecovery() || Bool(c.Properties.Bootstrap) { |
| 1475 | // However, for recovery or bootstrap modules, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1476 | // always link to non-stub variant |
| 1477 | useThisDep = !depIsStubs |
| 1478 | } |
| 1479 | } else { |
| 1480 | // If building for APEX, use stubs only when it is not from |
| 1481 | // the same APEX |
| 1482 | useThisDep = (depInSameApex != depIsStubs) |
| 1483 | } |
| 1484 | |
| 1485 | if !useThisDep { |
| 1486 | return // stop processing this dep |
| 1487 | } |
| 1488 | } |
| 1489 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1490 | if i, ok := ccDep.linker.(exportedFlagsProducer); ok { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1491 | flags := i.exportedFlags() |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 1492 | deps := i.exportedFlagsDeps() |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1493 | depPaths.Flags = append(depPaths.Flags, flags...) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 1494 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1495 | |
| 1496 | if t.reexportFlags { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 1497 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 1498 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1499 | // 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] | 1500 | // Re-exported shared library headers must be included as well since they can help us with type information |
| 1501 | // about template instantiations (instantiated from their headers). |
| 1502 | c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1503 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1504 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1505 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1506 | checkLinkType(ctx, c, ccDep, t) |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1507 | checkDoubleLoadableLibries(ctx, c, ccDep) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1510 | var ptr *android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1511 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1512 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1513 | linkFile := ccDep.outputFile |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1514 | depFile := android.OptionalPath{} |
| 1515 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1516 | switch depTag { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1517 | case ndkStubDepTag, sharedDepTag, sharedExportDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1518 | ptr = &depPaths.SharedLibs |
| 1519 | depPtr = &depPaths.SharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1520 | depFile = ccDep.linker.(libraryInterface).toc() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1521 | directSharedDeps = append(directSharedDeps, ccDep) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1522 | case lateSharedDepTag, ndkLateStubDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1523 | ptr = &depPaths.LateSharedLibs |
| 1524 | depPtr = &depPaths.LateSharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1525 | depFile = ccDep.linker.(libraryInterface).toc() |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1526 | case staticDepTag, staticExportDepTag: |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1527 | ptr = nil |
| 1528 | directStaticDeps = append(directStaticDeps, ccDep) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1529 | case lateStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1530 | ptr = &depPaths.LateStaticLibs |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1531 | case wholeStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1532 | ptr = &depPaths.WholeStaticLibs |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1533 | staticLib, ok := ccDep.linker.(libraryInterface) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1534 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1535 | ctx.ModuleErrorf("module %q not a static library", depName) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1536 | return |
| 1537 | } |
| 1538 | |
| 1539 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1540 | postfix := " (required by " + ctx.OtherModuleName(dep) + ")" |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1541 | for i := range missingDeps { |
| 1542 | missingDeps[i] += postfix |
| 1543 | } |
| 1544 | ctx.AddMissingDependencies(missingDeps) |
| 1545 | } |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1546 | depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs()) |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1547 | case headerDepTag: |
| 1548 | // Nothing |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1549 | case objDepTag: |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1550 | depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1551 | case crtBeginDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1552 | depPaths.CrtBegin = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1553 | case crtEndDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1554 | depPaths.CrtEnd = linkFile |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1555 | case dynamicLinkerDepTag: |
| 1556 | depPaths.DynamicLinker = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1559 | switch depTag { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1560 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1561 | staticLib, ok := ccDep.linker.(libraryInterface) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1562 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1563 | ctx.ModuleErrorf("module %q not a static library", depName) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1564 | return |
| 1565 | } |
| 1566 | |
| 1567 | // When combining coverage files for shared libraries and executables, coverage files |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1568 | // in static libraries act as if they were whole static libraries. The same goes for |
| 1569 | // source based Abi dump files. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1570 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 1571 | staticLib.objs().coverageFiles...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1572 | depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, |
| 1573 | staticLib.objs().sAbiDumpFiles...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1574 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1575 | } |
| 1576 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1577 | if ptr != nil { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1578 | if !linkFile.Valid() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1579 | ctx.ModuleErrorf("module %q missing output file", depName) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1580 | return |
| 1581 | } |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1582 | *ptr = append(*ptr, linkFile.Path()) |
| 1583 | } |
| 1584 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1585 | if depPtr != nil { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1586 | dep := depFile |
| 1587 | if !dep.Valid() { |
| 1588 | dep = linkFile |
| 1589 | } |
| 1590 | *depPtr = append(*depPtr, dep.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1591 | } |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1592 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1593 | makeLibName := func(depName string) string { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1594 | libName := strings.TrimSuffix(depName, llndkLibrarySuffix) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1595 | libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1596 | libName = strings.TrimPrefix(libName, "prebuilt_") |
Jiyong Park | d5b18a5 | 2017-08-03 21:22:50 +0900 | [diff] [blame] | 1597 | isLLndk := inList(libName, llndkLibraries) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1598 | isVendorPublicLib := inList(libName, vendorPublicLibraries) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1599 | bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk |
| 1600 | if c.useVndk() && bothVendorAndCoreVariantsExist { |
| 1601 | // The vendor module in Make will have been renamed to not conflict with the core |
| 1602 | // module, so update the dependency name here accordingly. |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1603 | return libName + vendorSuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1604 | } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1605 | return libName + vendorPublicLibrarySuffix |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1606 | } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() { |
| 1607 | return libName + recoverySuffix |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1608 | } else { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1609 | return libName |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1610 | } |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | // Export the shared libs to Make. |
| 1614 | switch depTag { |
| 1615 | case sharedDepTag, sharedExportDepTag, lateSharedDepTag: |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1616 | // Dependency to the stubs lib which is already included in an APEX |
| 1617 | // is not added to the androidmk dependency |
| 1618 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1619 | if dependentLibrary.buildStubs() && android.InAnyApex(depName) { |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1620 | // Also add the dependency to the APEX(es) providing the library so that |
| 1621 | // m <module> can trigger building the APEXes as well. |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1622 | for _, an := range android.GetApexesForModule(depName) { |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1623 | c.Properties.ApexesProvidingSharedLibs = append( |
| 1624 | c.Properties.ApexesProvidingSharedLibs, an) |
| 1625 | } |
| 1626 | break |
| 1627 | } |
| 1628 | } |
| 1629 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1630 | // Note: the order of libs in this list is not important because |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1631 | // 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] | 1632 | c.Properties.AndroidMkSharedLibs = append( |
| 1633 | c.Properties.AndroidMkSharedLibs, makeLibName(depName)) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1634 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
| 1635 | c.Properties.AndroidMkStaticLibs = append( |
| 1636 | c.Properties.AndroidMkStaticLibs, makeLibName(depName)) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1637 | case runtimeDepTag: |
| 1638 | c.Properties.AndroidMkRuntimeLibs = append( |
| 1639 | c.Properties.AndroidMkRuntimeLibs, makeLibName(depName)) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1640 | case wholeStaticDepTag: |
| 1641 | c.Properties.AndroidMkWholeStaticLibs = append( |
| 1642 | c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName)) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1643 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1644 | }) |
| 1645 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1646 | // use the ordered dependencies as this module's dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1647 | depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1648 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1649 | // Dedup exported flags from dependencies |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1650 | depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1651 | depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders) |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1652 | depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1653 | depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps) |
| 1654 | |
| 1655 | if c.sabi != nil { |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1656 | c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1657 | } |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1658 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1659 | return depPaths |
| 1660 | } |
| 1661 | |
| 1662 | func (c *Module) InstallInData() bool { |
| 1663 | if c.installer == nil { |
| 1664 | return false |
| 1665 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1666 | return c.installer.inData() |
| 1667 | } |
| 1668 | |
| 1669 | func (c *Module) InstallInSanitizerDir() bool { |
| 1670 | if c.installer == nil { |
| 1671 | return false |
| 1672 | } |
| 1673 | if c.sanitize != nil && c.sanitize.inSanitizerDir() { |
Colin Cross | 9461040 | 2016-08-29 13:41:32 -0700 | [diff] [blame] | 1674 | return true |
| 1675 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1676 | return c.installer.inSanitizerDir() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1679 | func (c *Module) InstallInRecovery() bool { |
| 1680 | return c.inRecovery() |
| 1681 | } |
| 1682 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 1683 | func (c *Module) HostToolPath() android.OptionalPath { |
| 1684 | if c.installer == nil { |
| 1685 | return android.OptionalPath{} |
| 1686 | } |
| 1687 | return c.installer.hostToolPath() |
| 1688 | } |
| 1689 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 1690 | func (c *Module) IntermPathForModuleOut() android.OptionalPath { |
| 1691 | return c.outputFile |
| 1692 | } |
| 1693 | |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1694 | func (c *Module) Srcs() android.Paths { |
| 1695 | if c.outputFile.Valid() { |
| 1696 | return android.Paths{c.outputFile.Path()} |
| 1697 | } |
| 1698 | return android.Paths{} |
| 1699 | } |
| 1700 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1701 | func (c *Module) static() bool { |
| 1702 | if static, ok := c.linker.(interface { |
| 1703 | static() bool |
| 1704 | }); ok { |
| 1705 | return static.static() |
| 1706 | } |
| 1707 | return false |
| 1708 | } |
| 1709 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1710 | func (c *Module) staticBinary() bool { |
| 1711 | if static, ok := c.linker.(interface { |
| 1712 | staticBinary() bool |
| 1713 | }); ok { |
| 1714 | return static.staticBinary() |
| 1715 | } |
| 1716 | return false |
| 1717 | } |
| 1718 | |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1719 | func (c *Module) getMakeLinkType() string { |
| 1720 | if c.useVndk() { |
| 1721 | if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) { |
| 1722 | if inList(c.Name(), vndkPrivateLibraries) { |
| 1723 | return "native:vndk_private" |
| 1724 | } else { |
| 1725 | return "native:vndk" |
| 1726 | } |
| 1727 | } else { |
| 1728 | return "native:vendor" |
| 1729 | } |
| 1730 | } else if c.inRecovery() { |
| 1731 | return "native:recovery" |
| 1732 | } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" { |
| 1733 | return "native:ndk:none:none" |
| 1734 | // TODO(b/114741097): use the correct ndk stl once build errors have been fixed |
| 1735 | //family, link := getNdkStlFamilyAndLinkType(c) |
| 1736 | //return fmt.Sprintf("native:ndk:%s:%s", family, link) |
| 1737 | } else { |
| 1738 | return "native:platform" |
| 1739 | } |
| 1740 | } |
| 1741 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 1742 | // Overrides ApexModule.IsInstallabeToApex() |
| 1743 | // Only shared libraries are installable to APEX. |
| 1744 | func (c *Module) IsInstallableToApex() bool { |
| 1745 | if shared, ok := c.linker.(interface { |
| 1746 | shared() bool |
| 1747 | }); ok { |
| 1748 | return shared.shared() |
| 1749 | } |
| 1750 | return false |
| 1751 | } |
| 1752 | |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 1753 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1754 | // Defaults |
| 1755 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1756 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1757 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 1758 | android.DefaultsModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 1759 | android.ApexModuleBase |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1762 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1763 | } |
| 1764 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1765 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1766 | } |
| 1767 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1768 | func defaultsFactory() android.Module { |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1769 | return DefaultsFactory() |
| 1770 | } |
| 1771 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1772 | func DefaultsFactory(props ...interface{}) android.Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1773 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1774 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1775 | module.AddProperties(props...) |
| 1776 | module.AddProperties( |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1777 | &BaseProperties{}, |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1778 | &VendorProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1779 | &BaseCompilerProperties{}, |
| 1780 | &BaseLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1781 | &LibraryProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1782 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1783 | &BinaryLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1784 | &TestProperties{}, |
| 1785 | &TestBinaryProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1786 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1787 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1788 | &StripProperties{}, |
Dan Willemsen | 7424d61 | 2016-09-01 13:45:39 -0700 | [diff] [blame] | 1789 | &InstallerProperties{}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1790 | &TidyProperties{}, |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1791 | &CoverageProperties{}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1792 | &SAbiProperties{}, |
Justin Yun | 4b2382f | 2017-07-26 14:22:10 +0900 | [diff] [blame] | 1793 | &VndkProperties{}, |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1794 | <OProperties{}, |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1795 | &PgoProperties{}, |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 1796 | &XomProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 1797 | &android.ProtoProperties{}, |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1798 | ) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1799 | |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 1800 | android.InitDefaultsModule(module) |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 1801 | android.InitApexModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1802 | |
| 1803 | return module |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1804 | } |
| 1805 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1806 | const ( |
| 1807 | // coreMode is the variant used for framework-private libraries, or |
| 1808 | // SDK libraries. (which framework-private libraries can use) |
| 1809 | coreMode = "core" |
| 1810 | |
| 1811 | // vendorMode is the variant used for /vendor code that compiles |
| 1812 | // against the VNDK. |
| 1813 | vendorMode = "vendor" |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1814 | |
| 1815 | recoveryMode = "recovery" |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1816 | ) |
| 1817 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 1818 | func squashVendorSrcs(m *Module) { |
| 1819 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 1820 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 1821 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 1822 | |
| 1823 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 1824 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 1825 | } |
| 1826 | } |
| 1827 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1828 | func squashRecoverySrcs(m *Module) { |
| 1829 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 1830 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 1831 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 1832 | |
| 1833 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 1834 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 1835 | } |
| 1836 | } |
| 1837 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 1838 | func ImageMutator(mctx android.BottomUpMutatorContext) { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1839 | if mctx.Os() != android.Android { |
| 1840 | return |
| 1841 | } |
| 1842 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1843 | if g, ok := mctx.Module().(*genrule.Module); ok { |
| 1844 | if props, ok := g.Extra.(*GenruleExtraProperties); ok { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1845 | var coreVariantNeeded bool = false |
| 1846 | var vendorVariantNeeded bool = false |
| 1847 | var recoveryVariantNeeded bool = false |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1848 | if mctx.DeviceConfig().VndkVersion() == "" { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1849 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1850 | } else if Bool(props.Vendor_available) { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1851 | coreVariantNeeded = true |
| 1852 | vendorVariantNeeded = true |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1853 | } else if mctx.SocSpecific() || mctx.DeviceSpecific() { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1854 | vendorVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1855 | } else { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1856 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1857 | } |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1858 | if Bool(props.Recovery_available) { |
| 1859 | recoveryVariantNeeded = true |
| 1860 | } |
| 1861 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 1862 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 1863 | primaryArch := mctx.Config().DevicePrimaryArchType() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1864 | moduleArch := g.Target().Arch.ArchType |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 1865 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 1866 | recoveryVariantNeeded = false |
| 1867 | } |
| 1868 | } |
| 1869 | |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 1870 | var variants []string |
| 1871 | if coreVariantNeeded { |
| 1872 | variants = append(variants, coreMode) |
| 1873 | } |
| 1874 | if vendorVariantNeeded { |
| 1875 | variants = append(variants, vendorMode) |
| 1876 | } |
| 1877 | if recoveryVariantNeeded { |
| 1878 | variants = append(variants, recoveryMode) |
| 1879 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1880 | mod := mctx.CreateVariations(variants...) |
| 1881 | for i, v := range variants { |
| 1882 | if v == recoveryMode { |
| 1883 | m := mod[i].(*genrule.Module) |
| 1884 | m.Extra.(*GenruleExtraProperties).InRecovery = true |
| 1885 | } |
| 1886 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1887 | } |
| 1888 | } |
| 1889 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1890 | m, ok := mctx.Module().(*Module) |
| 1891 | if !ok { |
| 1892 | return |
| 1893 | } |
| 1894 | |
| 1895 | // Sanity check |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1896 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 1897 | productSpecific := mctx.ProductSpecific() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1898 | |
| 1899 | if m.VendorProperties.Vendor_available != nil && vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1900 | mctx.PropertyErrorf("vendor_available", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1901 | "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] | 1902 | return |
| 1903 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1904 | |
| 1905 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 1906 | if vndkdep.isVndk() { |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 1907 | if productSpecific { |
| 1908 | mctx.PropertyErrorf("product_specific", |
| 1909 | "product_specific must not be true when `vndk: {enabled: true}`") |
| 1910 | return |
| 1911 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1912 | if vendorSpecific { |
| 1913 | if !vndkdep.isVndkExt() { |
| 1914 | mctx.PropertyErrorf("vndk", |
| 1915 | "must set `extends: \"...\"` to vndk extension") |
| 1916 | return |
| 1917 | } |
| 1918 | } else { |
| 1919 | if vndkdep.isVndkExt() { |
| 1920 | mctx.PropertyErrorf("vndk", |
| 1921 | "must set `vendor: true` to set `extends: %q`", |
| 1922 | m.getVndkExtendsModuleName()) |
| 1923 | return |
| 1924 | } |
| 1925 | if m.VendorProperties.Vendor_available == nil { |
| 1926 | mctx.PropertyErrorf("vndk", |
| 1927 | "vendor_available must be set to either true or false when `vndk: {enabled: true}`") |
| 1928 | return |
| 1929 | } |
| 1930 | } |
| 1931 | } else { |
| 1932 | if vndkdep.isVndkSp() { |
| 1933 | mctx.PropertyErrorf("vndk", |
| 1934 | "must set `enabled: true` to set `support_system_process: true`") |
| 1935 | return |
| 1936 | } |
| 1937 | if vndkdep.isVndkExt() { |
| 1938 | mctx.PropertyErrorf("vndk", |
| 1939 | "must set `enabled: true` to set `extends: %q`", |
| 1940 | m.getVndkExtendsModuleName()) |
| 1941 | return |
| 1942 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1943 | } |
| 1944 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1945 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1946 | var coreVariantNeeded bool = false |
| 1947 | var vendorVariantNeeded bool = false |
| 1948 | var recoveryVariantNeeded bool = false |
| 1949 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1950 | if mctx.DeviceConfig().VndkVersion() == "" { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1951 | // If the device isn't compiling against the VNDK, we always |
| 1952 | // use the core mode. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1953 | coreVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1954 | } else if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 1955 | // LL-NDK stubs only exist in the vendor variant, since the |
| 1956 | // real libraries will be used in the core variant. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1957 | vendorVariantNeeded = true |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 1958 | } else if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 1959 | // ... and LL-NDK headers as well |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1960 | vendorVariantNeeded = true |
Justin Yun | 312ccb9 | 2018-01-23 12:07:46 +0900 | [diff] [blame] | 1961 | } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1962 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 1963 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1964 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1965 | } else if m.hasVendorVariant() && !vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1966 | // This will be available in both /system and /vendor |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1967 | // or a /system directory that is available to vendor. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1968 | coreVariantNeeded = true |
| 1969 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1970 | } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 1971 | // This will be available in /vendor (or /odm) only |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1972 | vendorVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1973 | } else { |
| 1974 | // This is either in /system (or similar: /data), or is a |
| 1975 | // modules built with the NDK. Modules built with the NDK |
| 1976 | // will be restricted using the existing link type checks. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1977 | coreVariantNeeded = true |
| 1978 | } |
| 1979 | |
| 1980 | if Bool(m.Properties.Recovery_available) { |
| 1981 | recoveryVariantNeeded = true |
| 1982 | } |
| 1983 | |
| 1984 | if m.ModuleBase.InstallInRecovery() { |
| 1985 | recoveryVariantNeeded = true |
| 1986 | coreVariantNeeded = false |
| 1987 | } |
| 1988 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 1989 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 1990 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 1991 | moduleArch := m.Target().Arch.ArchType |
| 1992 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 1993 | recoveryVariantNeeded = false |
| 1994 | } |
| 1995 | } |
| 1996 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1997 | var variants []string |
| 1998 | if coreVariantNeeded { |
| 1999 | variants = append(variants, coreMode) |
| 2000 | } |
| 2001 | if vendorVariantNeeded { |
| 2002 | variants = append(variants, vendorMode) |
| 2003 | } |
| 2004 | if recoveryVariantNeeded { |
| 2005 | variants = append(variants, recoveryMode) |
| 2006 | } |
| 2007 | mod := mctx.CreateVariations(variants...) |
| 2008 | for i, v := range variants { |
| 2009 | if v == vendorMode { |
| 2010 | m := mod[i].(*Module) |
| 2011 | m.Properties.UseVndk = true |
| 2012 | squashVendorSrcs(m) |
| 2013 | } else if v == recoveryMode { |
| 2014 | m := mod[i].(*Module) |
| 2015 | m.Properties.InRecovery = true |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2016 | m.MakeAsPlatform() |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2017 | squashRecoverySrcs(m) |
| 2018 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2019 | } |
| 2020 | } |
| 2021 | |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2022 | func getCurrentNdkPrebuiltVersion(ctx DepsContext) string { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2023 | if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt { |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2024 | return strconv.Itoa(config.NdkMaxPrebuiltVersionInt) |
| 2025 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2026 | return ctx.Config().PlatformSdkVersion() |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 2029 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2030 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 2031 | var BoolPtr = proptools.BoolPtr |
| 2032 | var String = proptools.String |
| 2033 | var StringPtr = proptools.StringPtr |