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