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