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