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