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