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 | } |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 781 | if ctx.isNdk() { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 782 | return true |
| 783 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 784 | if ctx.isLlndkPublic(config) { |
Logan Chien | f4b79c6 | 2018-08-02 02:27:02 +0800 | [diff] [blame] | 785 | return true |
| 786 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 787 | if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) { |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 788 | // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not |
| 789 | // VNDK-private. |
Logan Chien | f6dbd9c | 2019-01-16 20:19:51 +0800 | [diff] [blame] | 790 | return true |
Logan Chien | 2f2b890 | 2018-07-10 15:01:19 +0800 | [diff] [blame] | 791 | } |
| 792 | return false |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 795 | func (ctx *moduleContextImpl) selectedStl() string { |
| 796 | if stl := ctx.mod.stl; stl != nil { |
| 797 | return stl.Properties.SelectedStl |
| 798 | } |
| 799 | return "" |
| 800 | } |
| 801 | |
Ivan Lozano | bd72126 | 2018-11-27 14:33:03 -0800 | [diff] [blame] | 802 | func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool { |
| 803 | return ctx.mod.linker.useClangLld(actx) |
| 804 | } |
| 805 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 806 | func (ctx *moduleContextImpl) baseModuleName() string { |
| 807 | return ctx.mod.ModuleBase.BaseModuleName() |
| 808 | } |
| 809 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 810 | func (ctx *moduleContextImpl) getVndkExtendsModuleName() string { |
| 811 | return ctx.mod.getVndkExtendsModuleName() |
| 812 | } |
| 813 | |
Jiyong Park | 58e364a | 2019-01-19 19:24:06 +0900 | [diff] [blame] | 814 | func (ctx *moduleContextImpl) apexName() string { |
| 815 | return ctx.mod.ApexName() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 816 | } |
| 817 | |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 818 | func (ctx *moduleContextImpl) hasStubsVariants() bool { |
| 819 | return ctx.mod.HasStubsVariants() |
| 820 | } |
| 821 | |
| 822 | func (ctx *moduleContextImpl) isStubs() bool { |
| 823 | return ctx.mod.IsStubs() |
| 824 | } |
| 825 | |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 826 | func (ctx *moduleContextImpl) bootstrap() bool { |
| 827 | return ctx.mod.bootstrap() |
| 828 | } |
| 829 | |
Pirama Arumuga Nainar | 65c95ff | 2019-03-25 10:21:31 -0700 | [diff] [blame] | 830 | func (ctx *moduleContextImpl) nativeCoverage() bool { |
| 831 | return ctx.mod.nativeCoverage() |
| 832 | } |
| 833 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 834 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 835 | return &Module{ |
| 836 | hod: hod, |
| 837 | multilib: multilib, |
| 838 | } |
| 839 | } |
| 840 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 841 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 842 | module := newBaseModule(hod, multilib) |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 843 | module.features = []feature{ |
| 844 | &tidyFeature{}, |
| 845 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 846 | module.stl = &stl{} |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 847 | module.sanitize = &sanitize{} |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 848 | module.coverage = &coverage{} |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 849 | module.sabi = &sabi{} |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 850 | module.vndkdep = &vndkdep{} |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 851 | module.lto = <o{} |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 852 | module.pgo = &pgo{} |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 853 | module.xom = &xom{} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 854 | return module |
| 855 | } |
| 856 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 857 | func (c *Module) Prebuilt() *android.Prebuilt { |
| 858 | if p, ok := c.linker.(prebuiltLinkerInterface); ok { |
| 859 | return p.prebuilt() |
| 860 | } |
| 861 | return nil |
| 862 | } |
| 863 | |
| 864 | func (c *Module) Name() string { |
| 865 | name := c.ModuleBase.Name() |
Dan Willemsen | 01a9059 | 2017-04-07 15:21:13 -0700 | [diff] [blame] | 866 | if p, ok := c.linker.(interface { |
| 867 | Name(string) string |
| 868 | }); ok { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 869 | name = p.Name(name) |
| 870 | } |
| 871 | return name |
| 872 | } |
| 873 | |
Alex Light | 3d67359 | 2019-01-18 14:37:31 -0800 | [diff] [blame] | 874 | func (c *Module) Symlinks() []string { |
| 875 | if p, ok := c.installer.(interface { |
| 876 | symlinkList() []string |
| 877 | }); ok { |
| 878 | return p.symlinkList() |
| 879 | } |
| 880 | return nil |
| 881 | } |
| 882 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 883 | // orderDeps reorders dependencies into a list such that if module A depends on B, then |
| 884 | // A will precede B in the resultant list. |
| 885 | // This is convenient for passing into a linker. |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 886 | // Note that directSharedDeps should be the analogous static library for each shared lib dep |
| 887 | 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] | 888 | // If A depends on B, then |
| 889 | // Every list containing A will also contain B later in the list |
| 890 | // So, after concatenating all lists, the final instance of B will have come from the same |
| 891 | // original list as the final instance of A |
| 892 | // So, the final instance of B will be later in the concatenation than the final A |
| 893 | // So, keeping only the final instance of A and of B ensures that A is earlier in the output |
| 894 | // list than B |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 895 | for _, dep := range directStaticDeps { |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 896 | orderedAllDeps = append(orderedAllDeps, dep) |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 897 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
| 898 | } |
| 899 | for _, dep := range directSharedDeps { |
| 900 | orderedAllDeps = append(orderedAllDeps, dep) |
| 901 | orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 904 | orderedAllDeps = android.LastUniquePaths(orderedAllDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 905 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 906 | // 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] | 907 | // intentionally exclude or replace any unwanted transitive dependencies), so we limit the |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 908 | // resultant list to only what the caller has chosen to include in directStaticDeps |
| 909 | _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 910 | |
| 911 | return orderedAllDeps, orderedDeclaredDeps |
| 912 | } |
| 913 | |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 914 | func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) { |
| 915 | // convert Module to Path |
| 916 | allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps)) |
| 917 | staticDepFiles := []android.Path{} |
| 918 | for _, dep := range staticDeps { |
| 919 | allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder |
| 920 | staticDepFiles = append(staticDepFiles, dep.outputFile.Path()) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 921 | } |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 922 | sharedDepFiles := []android.Path{} |
| 923 | for _, sharedDep := range sharedDeps { |
| 924 | staticAnalogue := sharedDep.staticVariant |
| 925 | if staticAnalogue != nil { |
| 926 | allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder |
| 927 | sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path()) |
| 928 | } |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // reorder the dependencies based on transitive dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 932 | module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 933 | |
| 934 | return results |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 937 | func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 938 | c.makeLinkType = c.getMakeLinkType(actx) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 939 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 940 | ctx := &moduleContext{ |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 941 | ModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 942 | moduleContextImpl: moduleContextImpl{ |
| 943 | mod: c, |
| 944 | }, |
| 945 | } |
| 946 | ctx.ctx = ctx |
| 947 | |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 948 | deps := c.depsToPaths(ctx) |
| 949 | if ctx.Failed() { |
| 950 | return |
| 951 | } |
| 952 | |
Dan Willemsen | 8536d6b | 2018-10-07 20:54:34 -0700 | [diff] [blame] | 953 | if c.Properties.Clang != nil && *c.Properties.Clang == false { |
| 954 | ctx.PropertyErrorf("clang", "false (GCC) is no longer supported") |
| 955 | } |
| 956 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 957 | flags := Flags{ |
| 958 | Toolchain: c.toolchain(ctx), |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 959 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 960 | if c.compiler != nil { |
Colin Cross | f18e110 | 2017-11-16 14:33:08 -0800 | [diff] [blame] | 961 | flags = c.compiler.compilerFlags(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 962 | } |
| 963 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 964 | flags = c.linker.linkerFlags(ctx, flags) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 965 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 966 | if c.stl != nil { |
| 967 | flags = c.stl.flags(ctx, flags) |
| 968 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 969 | if c.sanitize != nil { |
| 970 | flags = c.sanitize.flags(ctx, flags) |
| 971 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 972 | if c.coverage != nil { |
| 973 | flags = c.coverage.flags(ctx, flags) |
| 974 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 975 | if c.lto != nil { |
| 976 | flags = c.lto.flags(ctx, flags) |
| 977 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 978 | if c.pgo != nil { |
| 979 | flags = c.pgo.flags(ctx, flags) |
| 980 | } |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 981 | if c.xom != nil { |
| 982 | flags = c.xom.flags(ctx, flags) |
| 983 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 984 | for _, feature := range c.features { |
| 985 | flags = feature.flags(ctx, flags) |
| 986 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 987 | if ctx.Failed() { |
| 988 | return |
| 989 | } |
| 990 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 991 | flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags) |
| 992 | flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags) |
| 993 | flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 994 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 995 | flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 996 | |
| 997 | for _, dir := range deps.IncludeDirs { |
| 998 | flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir) |
| 999 | } |
| 1000 | for _, dir := range deps.SystemIncludeDirs { |
| 1001 | flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir) |
| 1002 | } |
| 1003 | |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 1004 | c.flags = flags |
Jayant Chowdhary | 9677e8c | 2017-06-15 14:45:18 -0700 | [diff] [blame] | 1005 | // We need access to all the flags seen by a source file. |
| 1006 | if c.sabi != nil { |
| 1007 | flags = c.sabi.flags(ctx, flags) |
| 1008 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1009 | // Optimization to reduce size of build.ninja |
| 1010 | // Replace the long list of flags for each file with a module-local variable |
| 1011 | ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " ")) |
| 1012 | ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " ")) |
| 1013 | ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " ")) |
| 1014 | flags.CFlags = []string{"$cflags"} |
| 1015 | flags.CppFlags = []string{"$cppflags"} |
| 1016 | flags.AsFlags = []string{"$asflags"} |
| 1017 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1018 | var objs Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1019 | if c.compiler != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1020 | objs = c.compiler.compile(ctx, flags, deps) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1021 | if ctx.Failed() { |
| 1022 | return |
| 1023 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1026 | if c.linker != nil { |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1027 | outputFile := c.linker.link(ctx, flags, deps, objs) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1028 | if ctx.Failed() { |
| 1029 | return |
| 1030 | } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1031 | c.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1032 | |
| 1033 | // If a lib is directly included in any of the APEXes, unhide the stubs |
| 1034 | // variant having the latest version gets visible to make. In addition, |
| 1035 | // the non-stubs variant is renamed to <libname>.bootstrap. This is to |
| 1036 | // force anything in the make world to link against the stubs library. |
| 1037 | // (unless it is explicitly referenced via .bootstrap suffix or the |
| 1038 | // module is marked with 'bootstrap: true'). |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 1039 | if c.HasStubsVariants() && |
| 1040 | android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && |
Pirama Arumuga Nainar | 1acd447 | 2018-12-10 15:12:40 -0800 | [diff] [blame] | 1041 | !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() && |
| 1042 | c.IsStubs() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1043 | c.Properties.HideFromMake = false // unhide |
| 1044 | // Note: this is still non-installable |
| 1045 | } |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1046 | } |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 1047 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 1048 | if c.installable() { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1049 | c.installer.install(ctx, c.outputFile.Path()) |
| 1050 | if ctx.Failed() { |
| 1051 | return |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1052 | } |
Dan Albert | c403f7c | 2015-03-18 14:01:18 -0700 | [diff] [blame] | 1053 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1056 | func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1057 | if c.cachedToolchain == nil { |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 1058 | c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1059 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1060 | return c.cachedToolchain |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1061 | } |
| 1062 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1063 | func (c *Module) begin(ctx BaseModuleContext) { |
| 1064 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1065 | c.compiler.compilerInit(ctx) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1066 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1067 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1068 | c.linker.linkerInit(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1069 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1070 | if c.stl != nil { |
| 1071 | c.stl.begin(ctx) |
| 1072 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1073 | if c.sanitize != nil { |
| 1074 | c.sanitize.begin(ctx) |
| 1075 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1076 | if c.coverage != nil { |
| 1077 | c.coverage.begin(ctx) |
| 1078 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1079 | if c.sabi != nil { |
| 1080 | c.sabi.begin(ctx) |
| 1081 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1082 | if c.vndkdep != nil { |
| 1083 | c.vndkdep.begin(ctx) |
| 1084 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1085 | if c.lto != nil { |
| 1086 | c.lto.begin(ctx) |
| 1087 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1088 | if c.pgo != nil { |
| 1089 | c.pgo.begin(ctx) |
| 1090 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1091 | for _, feature := range c.features { |
| 1092 | feature.begin(ctx) |
| 1093 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1094 | if ctx.useSdk() { |
Dan Albert | f5415d7 | 2017-08-17 16:19:59 -0700 | [diff] [blame] | 1095 | version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch()) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1096 | if err != nil { |
| 1097 | ctx.PropertyErrorf("sdk_version", err.Error()) |
| 1098 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1099 | c.Properties.Sdk_version = StringPtr(version) |
Dan Albert | 7fa7b2e | 2016-08-05 16:37:52 -0700 | [diff] [blame] | 1100 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1103 | func (c *Module) deps(ctx DepsContext) Deps { |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1104 | deps := Deps{} |
| 1105 | |
| 1106 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1107 | deps = c.compiler.compilerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1108 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1109 | // Add the PGO dependency (the clang_rt.profile runtime library), which |
| 1110 | // sometimes depends on symbols from libgcc, before libgcc gets added |
| 1111 | // in linkerDeps(). |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 1112 | if c.pgo != nil { |
| 1113 | deps = c.pgo.deps(ctx, deps) |
| 1114 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1115 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 1116 | deps = c.linker.linkerDeps(ctx, deps) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1117 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 1118 | if c.stl != nil { |
| 1119 | deps = c.stl.deps(ctx, deps) |
| 1120 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1121 | if c.sanitize != nil { |
| 1122 | deps = c.sanitize.deps(ctx, deps) |
| 1123 | } |
Pirama Arumuga Nainar | 0b882f0 | 2018-04-23 22:44:39 +0000 | [diff] [blame] | 1124 | if c.coverage != nil { |
| 1125 | deps = c.coverage.deps(ctx, deps) |
| 1126 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1127 | if c.sabi != nil { |
| 1128 | deps = c.sabi.deps(ctx, deps) |
| 1129 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 1130 | if c.vndkdep != nil { |
| 1131 | deps = c.vndkdep.deps(ctx, deps) |
| 1132 | } |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 1133 | if c.lto != nil { |
| 1134 | deps = c.lto.deps(ctx, deps) |
| 1135 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1136 | for _, feature := range c.features { |
| 1137 | deps = feature.deps(ctx, deps) |
| 1138 | } |
| 1139 | |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1140 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
| 1141 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 1142 | deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs) |
| 1143 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1144 | deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs) |
| 1145 | deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1146 | deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1147 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1148 | for _, lib := range deps.ReexportSharedLibHeaders { |
| 1149 | if !inList(lib, deps.SharedLibs) { |
| 1150 | ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib) |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | for _, lib := range deps.ReexportStaticLibHeaders { |
| 1155 | if !inList(lib, deps.StaticLibs) { |
| 1156 | ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib) |
| 1157 | } |
| 1158 | } |
| 1159 | |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1160 | for _, lib := range deps.ReexportHeaderLibHeaders { |
| 1161 | if !inList(lib, deps.HeaderLibs) { |
| 1162 | ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib) |
| 1163 | } |
| 1164 | } |
| 1165 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1166 | for _, gen := range deps.ReexportGeneratedHeaders { |
| 1167 | if !inList(gen, deps.GeneratedHeaders) { |
| 1168 | ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen) |
| 1169 | } |
| 1170 | } |
| 1171 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1172 | return deps |
| 1173 | } |
| 1174 | |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1175 | func (c *Module) beginMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1176 | ctx := &baseModuleContext{ |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 1177 | BaseModuleContext: actx, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1178 | moduleContextImpl: moduleContextImpl{ |
| 1179 | mod: c, |
| 1180 | }, |
| 1181 | } |
| 1182 | ctx.ctx = ctx |
| 1183 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1184 | c.begin(ctx) |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1187 | // Split name#version into name and version |
| 1188 | func stubsLibNameAndVersion(name string) (string, string) { |
| 1189 | if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 { |
| 1190 | version := name[sharp+1:] |
| 1191 | libname := name[:sharp] |
| 1192 | return libname, version |
| 1193 | } |
| 1194 | return name, "" |
| 1195 | } |
| 1196 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1197 | func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 1198 | ctx := &depsContext{ |
| 1199 | BottomUpMutatorContext: actx, |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1200 | moduleContextImpl: moduleContextImpl{ |
| 1201 | mod: c, |
| 1202 | }, |
| 1203 | } |
| 1204 | ctx.ctx = ctx |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1205 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1206 | deps := c.deps(ctx) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1207 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1208 | variantNdkLibs := []string{} |
| 1209 | variantLateNdkLibs := []string{} |
Dan Willemsen | b916b80 | 2017-03-19 13:44:32 -0700 | [diff] [blame] | 1210 | if ctx.Os() == android.Android { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1211 | version := ctx.sdkVersion() |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1212 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1213 | // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types |
| 1214 | // of names: |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1215 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1216 | // 1. Name of an NDK library that refers to a prebuilt module. |
| 1217 | // For each of these, it adds the name of the prebuilt module (which will be in |
| 1218 | // prebuilts/ndk) to the list of nonvariant libs. |
| 1219 | // 2. Name of an NDK library that refers to an ndk_library module. |
| 1220 | // For each of these, it adds the name of the ndk_library module to the list of |
| 1221 | // variant libs. |
| 1222 | // 3. Anything else (so anything that isn't an NDK library). |
| 1223 | // It adds these to the nonvariantLibs list. |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1224 | // |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1225 | // The caller can then know to add the variantLibs dependencies differently from the |
| 1226 | // nonvariantLibs |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1227 | |
| 1228 | llndkLibraries := llndkLibraries(actx.Config()) |
| 1229 | vendorPublicLibraries := vendorPublicLibraries(actx.Config()) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1230 | rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { |
| 1231 | variantLibs = []string{} |
| 1232 | nonvariantLibs = []string{} |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1233 | for _, entry := range list { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1234 | // strip #version suffix out |
| 1235 | name, _ := stubsLibNameAndVersion(entry) |
| 1236 | if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) { |
| 1237 | if !inList(name, ndkMigratedLibs) { |
| 1238 | nonvariantLibs = append(nonvariantLibs, name+".ndk."+version) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1239 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1240 | variantLibs = append(variantLibs, name+ndkLibrarySuffix) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1241 | } |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1242 | } else if ctx.useVndk() && inList(name, *llndkLibraries) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1243 | nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix) |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1244 | } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1245 | vendorPublicLib := name + vendorPublicLibrarySuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1246 | if actx.OtherModuleExists(vendorPublicLib) { |
| 1247 | nonvariantLibs = append(nonvariantLibs, vendorPublicLib) |
| 1248 | } else { |
| 1249 | // This can happen if vendor_public_library module is defined in a |
| 1250 | // namespace that isn't visible to the current module. In that case, |
| 1251 | // link to the original library. |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1252 | nonvariantLibs = append(nonvariantLibs, name) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1253 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1254 | } else { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1255 | // put name#version back |
Dan Willemsen | 7cbf5f8 | 2017-03-28 00:08:30 -0700 | [diff] [blame] | 1256 | nonvariantLibs = append(nonvariantLibs, entry) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1257 | } |
| 1258 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1259 | return nonvariantLibs, variantLibs |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1262 | deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs) |
| 1263 | deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs) |
Jiyong Park | 4c35af0 | 2017-07-05 13:41:55 +0900 | [diff] [blame] | 1264 | deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders) |
Dan Willemsen | 72d3993 | 2016-07-08 23:23:48 -0700 | [diff] [blame] | 1265 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1266 | |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1267 | buildStubs := false |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1268 | if c.linker != nil { |
| 1269 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 1270 | if library.buildStubs() { |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1271 | buildStubs = true |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 1276 | for _, lib := range deps.HeaderLibs { |
| 1277 | depTag := headerDepTag |
| 1278 | if inList(lib, deps.ReexportHeaderLibHeaders) { |
| 1279 | depTag = headerExportDepTag |
| 1280 | } |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1281 | if buildStubs { |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1282 | actx.AddFarVariationDependencies([]blueprint.Variation{ |
| 1283 | {Mutator: "arch", Variation: ctx.Target().String()}, |
Jiyong Park | 3b1746a | 2019-01-29 11:15:04 +0900 | [diff] [blame] | 1284 | {Mutator: "image", Variation: c.imageVariation()}, |
Jiyong Park | 7e636d0 | 2019-01-28 16:16:54 +0900 | [diff] [blame] | 1285 | }, depTag, lib) |
| 1286 | } else { |
| 1287 | actx.AddVariationDependencies(nil, depTag, lib) |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | if buildStubs { |
| 1292 | // Stubs lib does not have dependency to other static/shared libraries. |
| 1293 | // Don't proceed. |
| 1294 | return |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 1295 | } |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1296 | |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1297 | syspropImplLibraries := syspropImplLibraries(actx.Config()) |
| 1298 | |
Jiyong Park | 5d1598f | 2019-02-25 22:14:17 +0900 | [diff] [blame] | 1299 | for _, lib := range deps.WholeStaticLibs { |
| 1300 | depTag := wholeStaticDepTag |
| 1301 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1302 | lib = impl |
| 1303 | } |
| 1304 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1305 | {Mutator: "link", Variation: "static"}, |
| 1306 | }, depTag, lib) |
| 1307 | } |
| 1308 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1309 | for _, lib := range deps.StaticLibs { |
| 1310 | depTag := staticDepTag |
| 1311 | if inList(lib, deps.ReexportStaticLibHeaders) { |
| 1312 | depTag = staticExportDepTag |
| 1313 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1314 | |
| 1315 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1316 | lib = impl |
| 1317 | } |
| 1318 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1319 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1320 | {Mutator: "link", Variation: "static"}, |
| 1321 | }, depTag, lib) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1322 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1323 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1324 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1325 | {Mutator: "link", Variation: "static"}, |
| 1326 | }, lateStaticDepTag, deps.LateStaticLibs...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1327 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1328 | addSharedLibDependencies := func(depTag dependencyTag, name string, version string) { |
| 1329 | var variations []blueprint.Variation |
| 1330 | variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"}) |
Jiyong Park | 0fefdea | 2018-12-13 12:01:31 +0900 | [diff] [blame] | 1331 | versionVariantAvail := !ctx.useVndk() && !c.inRecovery() |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1332 | if version != "" && versionVariantAvail { |
| 1333 | // Version is explicitly specified. i.e. libFoo#30 |
| 1334 | variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version}) |
| 1335 | depTag.explicitlyVersioned = true |
| 1336 | } |
| 1337 | actx.AddVariationDependencies(variations, depTag, name) |
| 1338 | |
| 1339 | // If the version is not specified, add dependency to the latest stubs library. |
| 1340 | // The stubs library will be used when the depending module is built for APEX and |
| 1341 | // the dependent module is not in the same APEX. |
| 1342 | latestVersion := latestStubsVersionFor(actx.Config(), name) |
| 1343 | if version == "" && latestVersion != "" && versionVariantAvail { |
| 1344 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1345 | {Mutator: "link", Variation: "shared"}, |
| 1346 | {Mutator: "version", Variation: latestVersion}, |
| 1347 | }, depTag, name) |
| 1348 | // Note that depTag.explicitlyVersioned is false in this case. |
| 1349 | } |
| 1350 | } |
| 1351 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1352 | // shared lib names without the #version suffix |
| 1353 | var sharedLibNames []string |
| 1354 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1355 | for _, lib := range deps.SharedLibs { |
| 1356 | depTag := sharedDepTag |
| 1357 | if inList(lib, deps.ReexportSharedLibHeaders) { |
| 1358 | depTag = sharedExportDepTag |
| 1359 | } |
Inseob Kim | c0907f1 | 2019-02-08 21:00:45 +0900 | [diff] [blame] | 1360 | |
| 1361 | if impl, ok := syspropImplLibraries[lib]; ok { |
| 1362 | lib = impl |
| 1363 | } |
| 1364 | |
| 1365 | name, version := stubsLibNameAndVersion(lib) |
| 1366 | sharedLibNames = append(sharedLibNames, name) |
| 1367 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1368 | addSharedLibDependencies(depTag, name, version) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1369 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1370 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1371 | for _, lib := range deps.LateSharedLibs { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1372 | if inList(lib, sharedLibNames) { |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1373 | // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...) |
| 1374 | // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be |
| 1375 | // linking against both the stubs lib and the non-stubs lib at the same time. |
| 1376 | continue |
| 1377 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1378 | addSharedLibDependencies(lateSharedDepTag, lib, "") |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 1379 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1380 | |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1381 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1382 | {Mutator: "link", Variation: "shared"}, |
| 1383 | }, runtimeDepTag, deps.RuntimeLibs...) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1384 | |
Colin Cross | 6886183 | 2016-07-08 10:41:41 -0700 | [diff] [blame] | 1385 | actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1386 | |
| 1387 | for _, gen := range deps.GeneratedHeaders { |
| 1388 | depTag := genHeaderDepTag |
| 1389 | if inList(gen, deps.ReexportGeneratedHeaders) { |
| 1390 | depTag = genHeaderExportDepTag |
| 1391 | } |
| 1392 | actx.AddDependency(c, depTag, gen) |
| 1393 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1394 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1395 | actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1396 | |
| 1397 | if deps.CrtBegin != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1398 | actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1399 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1400 | if deps.CrtEnd != "" { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 1401 | actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd) |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1402 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1403 | if deps.LinkerFlagsFile != "" { |
| 1404 | actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile) |
| 1405 | } |
| 1406 | if deps.DynamicLinker != "" { |
| 1407 | actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1408 | } |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1409 | |
| 1410 | version := ctx.sdkVersion() |
| 1411 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1412 | {Mutator: "ndk_api", Variation: version}, |
| 1413 | {Mutator: "link", Variation: "shared"}, |
| 1414 | }, ndkStubDepTag, variantNdkLibs...) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 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 | }, ndkLateStubDepTag, variantLateNdkLibs...) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1419 | |
| 1420 | if vndkdep := c.vndkdep; vndkdep != nil { |
| 1421 | if vndkdep.isVndkExt() { |
| 1422 | baseModuleMode := vendorMode |
| 1423 | if actx.DeviceConfig().VndkVersion() == "" { |
| 1424 | baseModuleMode = coreMode |
| 1425 | } |
| 1426 | actx.AddVariationDependencies([]blueprint.Variation{ |
Dan Willemsen | 59339a2 | 2018-07-22 21:18:45 -0700 | [diff] [blame] | 1427 | {Mutator: "image", Variation: baseModuleMode}, |
| 1428 | {Mutator: "link", Variation: "shared"}, |
| 1429 | }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName()) |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1430 | } |
| 1431 | } |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 1432 | } |
Colin Cross | 21b9a24 | 2015-03-24 14:15:58 -0700 | [diff] [blame] | 1433 | |
Colin Cross | e40b4ea | 2018-10-02 22:25:58 -0700 | [diff] [blame] | 1434 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
Dan Albert | 7e9d295 | 2016-08-04 13:02:36 -0700 | [diff] [blame] | 1435 | if c, ok := ctx.Module().(*Module); ok && c.Enabled() { |
| 1436 | c.beginMutator(ctx) |
| 1437 | } |
| 1438 | } |
| 1439 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1440 | // Whether a module can link to another module, taking into |
| 1441 | // account NDK linking. |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1442 | func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1443 | if from.Target().Os != android.Android { |
| 1444 | // Host code is not restricted |
| 1445 | return |
| 1446 | } |
| 1447 | if from.Properties.UseVndk { |
| 1448 | // Though vendor code is limited by the vendor mutator, |
| 1449 | // each vendor-available module needs to check |
| 1450 | // link-type for VNDK. |
| 1451 | if from.vndkdep != nil { |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1452 | from.vndkdep.vndkCheckLinkType(ctx, to, tag) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1453 | } |
| 1454 | return |
| 1455 | } |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1456 | if String(from.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1457 | // Platform code can link to anything |
| 1458 | return |
| 1459 | } |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1460 | if from.inRecovery() { |
| 1461 | // Recovery code is not NDK |
| 1462 | return |
| 1463 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1464 | if _, ok := to.linker.(*toolchainLibraryDecorator); ok { |
| 1465 | // These are always allowed |
| 1466 | return |
| 1467 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1468 | if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { |
| 1469 | // These are allowed, but they don't set sdk_version |
| 1470 | return |
| 1471 | } |
| 1472 | if _, ok := to.linker.(*stubDecorator); ok { |
| 1473 | // These aren't real libraries, but are the stub shared libraries that are included in |
| 1474 | // the NDK. |
| 1475 | return |
| 1476 | } |
Logan Chien | 834b9a6 | 2019-01-14 15:39:03 +0800 | [diff] [blame] | 1477 | |
| 1478 | if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" { |
| 1479 | // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version) |
| 1480 | // to link to libc++ (non-NDK and without sdk_version). |
| 1481 | return |
| 1482 | } |
| 1483 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 1484 | if String(to.Properties.Sdk_version) == "" { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1485 | // NDK code linking to platform code is never okay. |
| 1486 | ctx.ModuleErrorf("depends on non-NDK-built library %q", |
| 1487 | ctx.OtherModuleName(to)) |
Dan Willemsen | 155d17c | 2019-02-06 18:30:02 -0800 | [diff] [blame] | 1488 | return |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | // At this point we know we have two NDK libraries, but we need to |
| 1492 | // check that we're not linking against anything built against a higher |
| 1493 | // API level, as it is only valid to link against older or equivalent |
| 1494 | // APIs. |
| 1495 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1496 | // Current can link against anything. |
| 1497 | if String(from.Properties.Sdk_version) != "current" { |
| 1498 | // Otherwise we need to check. |
| 1499 | if String(to.Properties.Sdk_version) == "current" { |
| 1500 | // Current can't be linked against by anything else. |
| 1501 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1502 | ctx.OtherModuleName(to), "current") |
| 1503 | } else { |
| 1504 | fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version)) |
| 1505 | if err != nil { |
| 1506 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1507 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1508 | String(from.Properties.Sdk_version)) |
| 1509 | } |
| 1510 | toApi, err := strconv.Atoi(String(to.Properties.Sdk_version)) |
| 1511 | if err != nil { |
| 1512 | ctx.PropertyErrorf("sdk_version", |
Inseob Kim | 34b2283 | 2018-04-11 10:13:16 +0900 | [diff] [blame] | 1513 | "Invalid sdk_version value (must be int or current): %q", |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1514 | String(to.Properties.Sdk_version)) |
| 1515 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1516 | |
Inseob Kim | 01a2872 | 2018-04-11 09:48:45 +0900 | [diff] [blame] | 1517 | if toApi > fromApi { |
| 1518 | ctx.ModuleErrorf("links %q built against newer API version %q", |
| 1519 | ctx.OtherModuleName(to), String(to.Properties.Sdk_version)) |
| 1520 | } |
| 1521 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1522 | } |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1523 | |
| 1524 | // Also check that the two STL choices are compatible. |
| 1525 | fromStl := from.stl.Properties.SelectedStl |
| 1526 | toStl := to.stl.Properties.SelectedStl |
| 1527 | if fromStl == "" || toStl == "" { |
| 1528 | // Libraries that don't use the STL are unrestricted. |
Inseob Kim | da2171a | 2018-04-11 15:41:38 +0900 | [diff] [blame] | 1529 | } else if fromStl == "ndk_system" || toStl == "ndk_system" { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1530 | // We can be permissive with the system "STL" since it is only the C++ |
| 1531 | // ABI layer, but in the future we should make sure that everyone is |
| 1532 | // using either libc++ or nothing. |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1533 | } else if getNdkStlFamily(from) != getNdkStlFamily(to) { |
Dan Albert | 202fe49 | 2017-12-15 13:56:59 -0800 | [diff] [blame] | 1534 | ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q", |
| 1535 | from.stl.Properties.SelectedStl, ctx.OtherModuleName(to), |
| 1536 | to.stl.Properties.SelectedStl) |
| 1537 | } |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1540 | // 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] | 1541 | // If a library has a vendor variant and is a (transitive) dependency of an LLNDK library, |
| 1542 | // 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] | 1543 | // or as vndk-sp (vndk: { enabled: true, support_system_process: true}). |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1544 | func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1545 | llndkLibraries := llndkLibraries(ctx.Config()) |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1546 | check := func(child, parent android.Module) bool { |
| 1547 | to, ok := child.(*Module) |
| 1548 | if !ok { |
| 1549 | // follow thru cc.Defaults, etc. |
| 1550 | return true |
| 1551 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1552 | |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1553 | if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() { |
| 1554 | return false |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1555 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1556 | |
| 1557 | // if target lib has no vendor variant, keep checking dependency graph |
| 1558 | if !to.hasVendorVariant() { |
| 1559 | return true |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1560 | } |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1561 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1562 | if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1563 | return false |
| 1564 | } |
| 1565 | |
| 1566 | var stringPath []string |
| 1567 | for _, m := range ctx.GetWalkPath() { |
| 1568 | stringPath = append(stringPath, m.Name()) |
| 1569 | } |
| 1570 | ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+ |
| 1571 | "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+ |
| 1572 | "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> ")) |
| 1573 | return false |
| 1574 | } |
| 1575 | if module, ok := ctx.Module().(*Module); ok { |
| 1576 | if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() { |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1577 | if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) { |
Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 1578 | ctx.WalkDeps(check) |
| 1579 | } |
Jiyong Park | 5fb8c10 | 2018-04-09 12:03:06 +0900 | [diff] [blame] | 1580 | } |
| 1581 | } |
| 1582 | } |
| 1583 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1584 | // Convert dependencies to paths. Returns a PathDeps containing paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1585 | func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1586 | var depPaths PathDeps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1587 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1588 | directStaticDeps := []*Module{} |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1589 | directSharedDeps := []*Module{} |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1590 | |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1591 | llndkLibraries := llndkLibraries(ctx.Config()) |
| 1592 | vendorPublicLibraries := vendorPublicLibraries(ctx.Config()) |
| 1593 | |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1594 | reexportExporter := func(exporter exportedFlagsProducer) { |
| 1595 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...) |
| 1596 | depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...) |
| 1597 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...) |
| 1598 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...) |
| 1599 | } |
| 1600 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1601 | ctx.VisitDirectDeps(func(dep android.Module) { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1602 | depName := ctx.OtherModuleName(dep) |
| 1603 | depTag := ctx.OtherModuleDependencyTag(dep) |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 1604 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1605 | ccDep, _ := dep.(*Module) |
| 1606 | if ccDep == nil { |
| 1607 | // handling for a few module types that aren't cc Module but that are also supported |
| 1608 | switch depTag { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1609 | case genSourceDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1610 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1611 | depPaths.GeneratedSources = append(depPaths.GeneratedSources, |
| 1612 | genRule.GeneratedSourceFiles()...) |
| 1613 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1614 | ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1615 | } |
Colin Cross | e90bfd1 | 2017-04-26 16:59:26 -0700 | [diff] [blame] | 1616 | // Support exported headers from a generated_sources dependency |
| 1617 | fallthrough |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1618 | case genHeaderDepTag, genHeaderExportDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1619 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1620 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
Dan Willemsen | 9da9d49 | 2018-02-21 18:28:18 -0800 | [diff] [blame] | 1621 | genRule.GeneratedDeps()...) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1622 | dirs := genRule.GeneratedHeaderDirs().Strings() |
| 1623 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1624 | if depTag == genHeaderExportDepTag { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1625 | depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...) |
| 1626 | depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1627 | // 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^] | 1628 | c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1629 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 1630 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1631 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1632 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 1633 | } |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1634 | case linkerFlagsDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1635 | if genRule, ok := dep.(genrule.SourceFileGenerator); ok { |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1636 | files := genRule.GeneratedSourceFiles() |
| 1637 | if len(files) == 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1638 | depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0]) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1639 | } else if len(files) > 1 { |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1640 | 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] | 1641 | } |
| 1642 | } else { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1643 | ctx.ModuleErrorf("module %q is not a genrule", depName) |
Dan Willemsen | c77a0b3 | 2017-09-18 23:19:12 -0700 | [diff] [blame] | 1644 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1645 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1646 | return |
| 1647 | } |
| 1648 | |
Colin Cross | fe17f6f | 2019-03-28 19:30:56 -0700 | [diff] [blame] | 1649 | if depTag == android.ProtoPluginDepTag { |
| 1650 | return |
| 1651 | } |
| 1652 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1653 | if dep.Target().Os != ctx.Os() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1654 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1655 | return |
| 1656 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 1657 | if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1658 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1659 | return |
| 1660 | } |
| 1661 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1662 | // re-exporting flags |
| 1663 | if depTag == reuseObjTag { |
| 1664 | if l, ok := ccDep.compiler.(libraryInterface); ok { |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1665 | c.staticVariant = ccDep |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1666 | objs, exporter := l.reuseObjs() |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 1667 | depPaths.Objs = depPaths.Objs.Append(objs) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1668 | reexportExporter(exporter) |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 1669 | return |
| 1670 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1671 | } |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1672 | |
Jiyong Park | e4bb986 | 2019-02-01 00:31:10 +0900 | [diff] [blame] | 1673 | if depTag == staticVariantTag { |
| 1674 | if _, ok := ccDep.compiler.(libraryInterface); ok { |
| 1675 | c.staticVariant = ccDep |
| 1676 | return |
| 1677 | } |
| 1678 | } |
| 1679 | |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1680 | // Extract explicitlyVersioned field from the depTag and reset it inside the struct. |
| 1681 | // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true |
| 1682 | // won't be matched to sharedDepTag and lateSharedDepTag. |
| 1683 | explicitlyVersioned := false |
| 1684 | if t, ok := depTag.(dependencyTag); ok { |
| 1685 | explicitlyVersioned = t.explicitlyVersioned |
| 1686 | t.explicitlyVersioned = false |
| 1687 | depTag = t |
| 1688 | } |
| 1689 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1690 | if t, ok := depTag.(dependencyTag); ok && t.library { |
Jiyong Park | 16e91a0 | 2018-12-20 18:18:08 +0900 | [diff] [blame] | 1691 | depIsStatic := false |
| 1692 | switch depTag { |
| 1693 | case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag: |
| 1694 | depIsStatic = true |
| 1695 | } |
| 1696 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic { |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1697 | depIsStubs := dependentLibrary.buildStubs() |
| 1698 | depHasStubs := ccDep.HasStubsVariants() |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1699 | depInSameApex := android.DirectlyInApex(c.ApexName(), depName) |
Nicolas Geoffray | c22c1bf | 2019-01-15 19:53:23 +0000 | [diff] [blame] | 1700 | depInPlatform := !android.DirectlyInAnyApex(ctx, depName) |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1701 | |
| 1702 | var useThisDep bool |
| 1703 | if depIsStubs && explicitlyVersioned { |
| 1704 | // Always respect dependency to the versioned stubs (i.e. libX#10) |
| 1705 | useThisDep = true |
| 1706 | } else if !depHasStubs { |
| 1707 | // Use non-stub variant if that is the only choice |
| 1708 | // (i.e. depending on a lib without stubs.version property) |
| 1709 | useThisDep = true |
| 1710 | } else if c.IsForPlatform() { |
| 1711 | // If not building for APEX, use stubs only when it is from |
| 1712 | // an APEX (and not from platform) |
| 1713 | useThisDep = (depInPlatform != depIsStubs) |
Jiyong Park | a4b9dd0 | 2019-01-16 22:53:13 +0900 | [diff] [blame] | 1714 | if c.inRecovery() || c.bootstrap() { |
Jiyong Park | b078857 | 2018-12-20 22:10:17 +0900 | [diff] [blame] | 1715 | // However, for recovery or bootstrap modules, |
Jiyong Park | 25fc6a9 | 2018-11-18 18:02:45 +0900 | [diff] [blame] | 1716 | // always link to non-stub variant |
| 1717 | useThisDep = !depIsStubs |
| 1718 | } |
| 1719 | } else { |
| 1720 | // If building for APEX, use stubs only when it is not from |
| 1721 | // the same APEX |
| 1722 | useThisDep = (depInSameApex != depIsStubs) |
| 1723 | } |
| 1724 | |
| 1725 | if !useThisDep { |
| 1726 | return // stop processing this dep |
| 1727 | } |
| 1728 | } |
| 1729 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1730 | if i, ok := ccDep.linker.(exportedFlagsProducer); ok { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1731 | depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...) |
| 1732 | depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...) |
| 1733 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...) |
| 1734 | depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1735 | |
| 1736 | if t.reexportFlags { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1737 | reexportExporter(i) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame] | 1738 | // 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] | 1739 | // Re-exported shared library headers must be included as well since they can help us with type information |
| 1740 | // about template instantiations (instantiated from their headers). |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1741 | // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version |
| 1742 | // scripts. |
| 1743 | c.sabi.Properties.ReexportedIncludes = append( |
| 1744 | c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1745 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1746 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1747 | |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 1748 | checkLinkType(ctx, c, ccDep, t) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1751 | var ptr *android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1752 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1753 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1754 | linkFile := ccDep.outputFile |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1755 | depFile := android.OptionalPath{} |
| 1756 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1757 | switch depTag { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1758 | case ndkStubDepTag, sharedDepTag, sharedExportDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1759 | ptr = &depPaths.SharedLibs |
| 1760 | depPtr = &depPaths.SharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1761 | depFile = ccDep.linker.(libraryInterface).toc() |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1762 | directSharedDeps = append(directSharedDeps, ccDep) |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 1763 | case earlySharedDepTag: |
| 1764 | ptr = &depPaths.EarlySharedLibs |
| 1765 | depPtr = &depPaths.EarlySharedLibsDeps |
| 1766 | depFile = ccDep.linker.(libraryInterface).toc() |
| 1767 | directSharedDeps = append(directSharedDeps, ccDep) |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 1768 | case lateSharedDepTag, ndkLateStubDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1769 | ptr = &depPaths.LateSharedLibs |
| 1770 | depPtr = &depPaths.LateSharedLibsDeps |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1771 | depFile = ccDep.linker.(libraryInterface).toc() |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1772 | case staticDepTag, staticExportDepTag: |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1773 | ptr = nil |
| 1774 | directStaticDeps = append(directStaticDeps, ccDep) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1775 | case lateStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1776 | ptr = &depPaths.LateStaticLibs |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1777 | case wholeStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1778 | ptr = &depPaths.WholeStaticLibs |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1779 | staticLib, ok := ccDep.linker.(libraryInterface) |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1780 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1781 | ctx.ModuleErrorf("module %q not a static library", depName) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1782 | return |
| 1783 | } |
| 1784 | |
| 1785 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1786 | postfix := " (required by " + ctx.OtherModuleName(dep) + ")" |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1787 | for i := range missingDeps { |
| 1788 | missingDeps[i] += postfix |
| 1789 | } |
| 1790 | ctx.AddMissingDependencies(missingDeps) |
| 1791 | } |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1792 | depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs()) |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1793 | case headerDepTag: |
| 1794 | // Nothing |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1795 | case objDepTag: |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1796 | depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1797 | case crtBeginDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1798 | depPaths.CrtBegin = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1799 | case crtEndDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1800 | depPaths.CrtEnd = linkFile |
Dan Willemsen | a0790e3 | 2018-10-12 00:24:23 -0700 | [diff] [blame] | 1801 | case dynamicLinkerDepTag: |
| 1802 | depPaths.DynamicLinker = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1805 | switch depTag { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1806 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1807 | staticLib, ok := ccDep.linker.(libraryInterface) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1808 | if !ok || !staticLib.static() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1809 | ctx.ModuleErrorf("module %q not a static library", depName) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1810 | return |
| 1811 | } |
| 1812 | |
| 1813 | // When combining coverage files for shared libraries and executables, coverage files |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1814 | // in static libraries act as if they were whole static libraries. The same goes for |
| 1815 | // source based Abi dump files. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1816 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 1817 | staticLib.objs().coverageFiles...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1818 | depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, |
| 1819 | staticLib.objs().sAbiDumpFiles...) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1820 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1823 | if ptr != nil { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1824 | if !linkFile.Valid() { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1825 | ctx.ModuleErrorf("module %q missing output file", depName) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1826 | return |
| 1827 | } |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1828 | *ptr = append(*ptr, linkFile.Path()) |
| 1829 | } |
| 1830 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1831 | if depPtr != nil { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1832 | dep := depFile |
| 1833 | if !dep.Valid() { |
| 1834 | dep = linkFile |
| 1835 | } |
| 1836 | *depPtr = append(*depPtr, dep.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1837 | } |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1838 | |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1839 | makeLibName := func(depName string) string { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1840 | libName := strings.TrimSuffix(depName, llndkLibrarySuffix) |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1841 | libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1842 | libName = strings.TrimPrefix(libName, "prebuilt_") |
Inseob Kim | 9516ee9 | 2019-05-09 10:56:13 +0900 | [diff] [blame] | 1843 | isLLndk := inList(libName, *llndkLibraries) |
| 1844 | isVendorPublicLib := inList(libName, *vendorPublicLibraries) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1845 | bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 1846 | |
| 1847 | if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() { |
| 1848 | // The vendor module is a no-vendor-variant VNDK library. Depend on the |
| 1849 | // core module instead. |
| 1850 | return libName |
| 1851 | } else if c.useVndk() && bothVendorAndCoreVariantsExist { |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1852 | // The vendor module in Make will have been renamed to not conflict with the core |
| 1853 | // module, so update the dependency name here accordingly. |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1854 | return libName + vendorSuffix |
Jiyong Park | 374510b | 2018-03-19 18:23:01 +0900 | [diff] [blame] | 1855 | } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1856 | return libName + vendorPublicLibrarySuffix |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1857 | } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() { |
| 1858 | return libName + recoverySuffix |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1859 | } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled { |
dimitry | 4320449 | 2019-05-23 13:24:38 +0200 | [diff] [blame] | 1860 | return libName + nativeBridgeSuffix |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1861 | } else { |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1862 | return libName |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1863 | } |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | // Export the shared libs to Make. |
| 1867 | switch depTag { |
Jiyong Park | 64a44f2 | 2019-01-18 14:37:08 +0900 | [diff] [blame] | 1868 | case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag: |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1869 | if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok { |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1870 | if dependentLibrary.buildStubs() && android.InAnyApex(depName) { |
Logan Chien | 09106e1 | 2019-01-18 14:57:48 +0800 | [diff] [blame] | 1871 | // Add the dependency to the APEX(es) providing the library so that |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1872 | // m <module> can trigger building the APEXes as well. |
Jiyong Park | 0ddfcd1 | 2018-12-11 01:35:25 +0900 | [diff] [blame] | 1873 | for _, an := range android.GetApexesForModule(depName) { |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1874 | c.Properties.ApexesProvidingSharedLibs = append( |
| 1875 | c.Properties.ApexesProvidingSharedLibs, an) |
| 1876 | } |
Jiyong Park | de866cb | 2018-12-07 23:08:36 +0900 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1880 | // Note: the order of libs in this list is not important because |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 1881 | // 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] | 1882 | c.Properties.AndroidMkSharedLibs = append( |
| 1883 | c.Properties.AndroidMkSharedLibs, makeLibName(depName)) |
Logan Chien | c7f797e | 2019-01-14 15:35:08 +0800 | [diff] [blame] | 1884 | case ndkStubDepTag, ndkLateStubDepTag: |
| 1885 | ndkStub := ccDep.linker.(*stubDecorator) |
| 1886 | c.Properties.AndroidMkSharedLibs = append( |
| 1887 | c.Properties.AndroidMkSharedLibs, |
| 1888 | depName+"."+ndkStub.properties.ApiLevel) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1889 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
| 1890 | c.Properties.AndroidMkStaticLibs = append( |
| 1891 | c.Properties.AndroidMkStaticLibs, makeLibName(depName)) |
Logan Chien | 43d34c3 | 2017-12-20 01:17:32 +0800 | [diff] [blame] | 1892 | case runtimeDepTag: |
| 1893 | c.Properties.AndroidMkRuntimeLibs = append( |
| 1894 | c.Properties.AndroidMkRuntimeLibs, makeLibName(depName)) |
Jaewoong Jung | 16c7d3d | 2018-11-16 01:19:56 +0000 | [diff] [blame] | 1895 | case wholeStaticDepTag: |
| 1896 | c.Properties.AndroidMkWholeStaticLibs = append( |
| 1897 | c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName)) |
Jiyong Park | 27b188b | 2017-07-18 13:23:39 +0900 | [diff] [blame] | 1898 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1899 | }) |
| 1900 | |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1901 | // use the ordered dependencies as this module's dependencies |
Jeff Gaston | f5b6e8f | 2017-11-27 15:48:57 -0800 | [diff] [blame] | 1902 | depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...) |
Jeff Gaston | 294356f | 2017-09-27 17:05:30 -0700 | [diff] [blame] | 1903 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1904 | // Dedup exported flags from dependencies |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1905 | depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1906 | depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs) |
| 1907 | depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1908 | depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1909 | depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs) |
| 1910 | depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs) |
Colin Cross | b671544 | 2017-10-24 11:13:31 -0700 | [diff] [blame] | 1911 | depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags) |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1912 | depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1913 | |
| 1914 | if c.sabi != nil { |
Inseob Kim | 6937844 | 2019-06-03 19:10:47 +0900 | [diff] [blame^] | 1915 | c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes) |
Dan Willemsen | fe92c96 | 2017-08-29 12:28:37 -0700 | [diff] [blame] | 1916 | } |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1917 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1918 | return depPaths |
| 1919 | } |
| 1920 | |
| 1921 | func (c *Module) InstallInData() bool { |
| 1922 | if c.installer == nil { |
| 1923 | return false |
| 1924 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1925 | return c.installer.inData() |
| 1926 | } |
| 1927 | |
| 1928 | func (c *Module) InstallInSanitizerDir() bool { |
| 1929 | if c.installer == nil { |
| 1930 | return false |
| 1931 | } |
| 1932 | if c.sanitize != nil && c.sanitize.inSanitizerDir() { |
Colin Cross | 9461040 | 2016-08-29 13:41:32 -0700 | [diff] [blame] | 1933 | return true |
| 1934 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1935 | return c.installer.inSanitizerDir() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1936 | } |
| 1937 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 1938 | func (c *Module) InstallInRecovery() bool { |
| 1939 | return c.inRecovery() |
| 1940 | } |
| 1941 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 1942 | func (c *Module) HostToolPath() android.OptionalPath { |
| 1943 | if c.installer == nil { |
| 1944 | return android.OptionalPath{} |
| 1945 | } |
| 1946 | return c.installer.hostToolPath() |
| 1947 | } |
| 1948 | |
Nan Zhang | d4e641b | 2017-07-12 12:55:28 -0700 | [diff] [blame] | 1949 | func (c *Module) IntermPathForModuleOut() android.OptionalPath { |
| 1950 | return c.outputFile |
| 1951 | } |
| 1952 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 1953 | func (c *Module) OutputFiles(tag string) (android.Paths, error) { |
| 1954 | switch tag { |
| 1955 | case "": |
| 1956 | if c.outputFile.Valid() { |
| 1957 | return android.Paths{c.outputFile.Path()}, nil |
| 1958 | } |
| 1959 | return android.Paths{}, nil |
| 1960 | default: |
| 1961 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1962 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Vishwath Mohan | b743e9c | 2017-11-01 09:20:21 +0000 | [diff] [blame] | 1965 | func (c *Module) static() bool { |
| 1966 | if static, ok := c.linker.(interface { |
| 1967 | static() bool |
| 1968 | }); ok { |
| 1969 | return static.static() |
| 1970 | } |
| 1971 | return false |
| 1972 | } |
| 1973 | |
Jiyong Park | 379de2f | 2018-12-19 02:47:14 +0900 | [diff] [blame] | 1974 | func (c *Module) staticBinary() bool { |
| 1975 | if static, ok := c.linker.(interface { |
| 1976 | staticBinary() bool |
| 1977 | }); ok { |
| 1978 | return static.staticBinary() |
| 1979 | } |
| 1980 | return false |
| 1981 | } |
| 1982 | |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1983 | func (c *Module) getMakeLinkType(actx android.ModuleContext) string { |
| 1984 | name := actx.ModuleName() |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1985 | if c.useVndk() { |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1986 | if lib, ok := c.linker.(*llndkStubDecorator); ok { |
| 1987 | if Bool(lib.Properties.Vendor_available) { |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1988 | return "native:vndk" |
| 1989 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1990 | return "native:vndk_private" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1991 | } |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 1992 | if c.isVndk() && !c.isVndkExt() { |
| 1993 | if Bool(c.VendorProperties.Vendor_available) { |
| 1994 | return "native:vndk" |
| 1995 | } |
| 1996 | return "native:vndk_private" |
| 1997 | } |
| 1998 | return "native:vendor" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 1999 | } else if c.inRecovery() { |
| 2000 | return "native:recovery" |
| 2001 | } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" { |
| 2002 | return "native:ndk:none:none" |
| 2003 | // TODO(b/114741097): use the correct ndk stl once build errors have been fixed |
| 2004 | //family, link := getNdkStlFamilyAndLinkType(c) |
| 2005 | //return fmt.Sprintf("native:ndk:%s:%s", family, link) |
Jooyung Han | 3800291 | 2019-05-16 04:01:54 +0900 | [diff] [blame] | 2006 | } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) { |
Vic Yang | efd249e | 2018-11-12 20:19:56 -0800 | [diff] [blame] | 2007 | return "native:platform_vndk" |
Colin Cross | b60190a | 2018-09-04 16:28:17 -0700 | [diff] [blame] | 2008 | } else { |
| 2009 | return "native:platform" |
| 2010 | } |
| 2011 | } |
| 2012 | |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2013 | // Overrides ApexModule.IsInstallabeToApex() |
| 2014 | // Only shared libraries are installable to APEX. |
| 2015 | func (c *Module) IsInstallableToApex() bool { |
| 2016 | if shared, ok := c.linker.(interface { |
| 2017 | shared() bool |
| 2018 | }); ok { |
| 2019 | return shared.shared() |
| 2020 | } |
| 2021 | return false |
| 2022 | } |
| 2023 | |
Inseob Kim | 1f086e2 | 2019-05-09 13:29:15 +0900 | [diff] [blame] | 2024 | func (c *Module) installable() bool { |
| 2025 | return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() |
| 2026 | } |
| 2027 | |
Jiyong Park | 3b1746a | 2019-01-29 11:15:04 +0900 | [diff] [blame] | 2028 | func (c *Module) imageVariation() string { |
| 2029 | variation := "core" |
| 2030 | if c.useVndk() { |
| 2031 | variation = "vendor" |
| 2032 | } else if c.inRecovery() { |
| 2033 | variation = "recovery" |
| 2034 | } |
| 2035 | return variation |
| 2036 | } |
| 2037 | |
bralee | 3f49f4d | 2019-03-04 06:58:15 +0800 | [diff] [blame] | 2038 | func (c *Module) IDEInfo(dpInfo *android.IdeInfo) { |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 2039 | outputFiles, err := c.OutputFiles("") |
| 2040 | if err != nil { |
| 2041 | panic(err) |
| 2042 | } |
| 2043 | dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...) |
bralee | 3f49f4d | 2019-03-04 06:58:15 +0800 | [diff] [blame] | 2044 | } |
| 2045 | |
Logan Chien | 41eabe6 | 2019-04-10 13:33:58 +0800 | [diff] [blame] | 2046 | func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) { |
| 2047 | if c.linker != nil { |
| 2048 | if library, ok := c.linker.(*libraryDecorator); ok { |
| 2049 | library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w) |
| 2050 | } |
| 2051 | } |
| 2052 | } |
| 2053 | |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 2054 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2055 | // Defaults |
| 2056 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2057 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2058 | android.ModuleBase |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 2059 | android.DefaultsModuleBase |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2060 | android.ApexModuleBase |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2061 | } |
| 2062 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 2063 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2064 | } |
| 2065 | |
Patrice Arruda | c249c71 | 2019-03-19 17:00:29 -0700 | [diff] [blame] | 2066 | // cc_defaults provides a set of properties that can be inherited by other cc |
| 2067 | // modules. A module can use the properties from a cc_defaults using |
| 2068 | // `defaults: ["<:default_module_name>"]`. Properties of both modules are |
| 2069 | // merged (when possible) by prepending the default module's values to the |
| 2070 | // depending module's values. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2071 | func defaultsFactory() android.Module { |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 2072 | return DefaultsFactory() |
| 2073 | } |
| 2074 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2075 | func DefaultsFactory(props ...interface{}) android.Module { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2076 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2077 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2078 | module.AddProperties(props...) |
| 2079 | module.AddProperties( |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2080 | &BaseProperties{}, |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2081 | &VendorProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2082 | &BaseCompilerProperties{}, |
| 2083 | &BaseLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 2084 | &LibraryProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 2085 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2086 | &BinaryLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 2087 | &TestProperties{}, |
| 2088 | &TestBinaryProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 2089 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 2090 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 2091 | &StripProperties{}, |
Dan Willemsen | 7424d61 | 2016-09-01 13:45:39 -0700 | [diff] [blame] | 2092 | &InstallerProperties{}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 2093 | &TidyProperties{}, |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 2094 | &CoverageProperties{}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 2095 | &SAbiProperties{}, |
Justin Yun | 4b2382f | 2017-07-26 14:22:10 +0900 | [diff] [blame] | 2096 | &VndkProperties{}, |
Stephen Crane | ba090d1 | 2017-05-09 15:44:35 -0700 | [diff] [blame] | 2097 | <OProperties{}, |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 2098 | &PgoProperties{}, |
Ivan Lozano | 074ec48 | 2018-11-21 08:59:37 -0800 | [diff] [blame] | 2099 | &XomProperties{}, |
Dan Willemsen | 6424d17 | 2018-03-08 13:27:59 -0800 | [diff] [blame] | 2100 | &android.ProtoProperties{}, |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 2101 | ) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2102 | |
Colin Cross | 1f44a3a | 2017-07-07 14:33:33 -0700 | [diff] [blame] | 2103 | android.InitDefaultsModule(module) |
Jiyong Park | 9d45299 | 2018-10-03 00:38:19 +0900 | [diff] [blame] | 2104 | android.InitApexModule(module) |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 2105 | |
| 2106 | return module |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 2107 | } |
| 2108 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2109 | const ( |
| 2110 | // coreMode is the variant used for framework-private libraries, or |
| 2111 | // SDK libraries. (which framework-private libraries can use) |
| 2112 | coreMode = "core" |
| 2113 | |
| 2114 | // vendorMode is the variant used for /vendor code that compiles |
| 2115 | // against the VNDK. |
| 2116 | vendorMode = "vendor" |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2117 | |
| 2118 | recoveryMode = "recovery" |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2119 | ) |
| 2120 | |
Jiyong Park | 6a43f04 | 2017-10-12 23:05:00 +0900 | [diff] [blame] | 2121 | func squashVendorSrcs(m *Module) { |
| 2122 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 2123 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 2124 | lib.baseCompiler.Properties.Target.Vendor.Srcs...) |
| 2125 | |
| 2126 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 2127 | lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...) |
| 2128 | } |
| 2129 | } |
| 2130 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2131 | func squashRecoverySrcs(m *Module) { |
| 2132 | if lib, ok := m.compiler.(*libraryDecorator); ok { |
| 2133 | lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs, |
| 2134 | lib.baseCompiler.Properties.Target.Recovery.Srcs...) |
| 2135 | |
| 2136 | lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs, |
| 2137 | lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...) |
| 2138 | } |
| 2139 | } |
| 2140 | |
Jiyong Park | da6eb59 | 2018-12-19 17:12:36 +0900 | [diff] [blame] | 2141 | func ImageMutator(mctx android.BottomUpMutatorContext) { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2142 | if mctx.Os() != android.Android { |
| 2143 | return |
| 2144 | } |
| 2145 | |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2146 | if g, ok := mctx.Module().(*genrule.Module); ok { |
| 2147 | if props, ok := g.Extra.(*GenruleExtraProperties); ok { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2148 | var coreVariantNeeded bool = false |
| 2149 | var vendorVariantNeeded bool = false |
| 2150 | var recoveryVariantNeeded bool = false |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2151 | if mctx.DeviceConfig().VndkVersion() == "" { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2152 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2153 | } else if Bool(props.Vendor_available) { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2154 | coreVariantNeeded = true |
| 2155 | vendorVariantNeeded = true |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2156 | } else if mctx.SocSpecific() || mctx.DeviceSpecific() { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2157 | vendorVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2158 | } else { |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2159 | coreVariantNeeded = true |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2160 | } |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2161 | if Bool(props.Recovery_available) { |
| 2162 | recoveryVariantNeeded = true |
| 2163 | } |
| 2164 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2165 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2166 | primaryArch := mctx.Config().DevicePrimaryArchType() |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2167 | moduleArch := g.Target().Arch.ArchType |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2168 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2169 | recoveryVariantNeeded = false |
| 2170 | } |
| 2171 | } |
| 2172 | |
Jiyong Park | 3f736c9 | 2018-05-24 13:36:56 +0900 | [diff] [blame] | 2173 | var variants []string |
| 2174 | if coreVariantNeeded { |
| 2175 | variants = append(variants, coreMode) |
| 2176 | } |
| 2177 | if vendorVariantNeeded { |
| 2178 | variants = append(variants, vendorMode) |
| 2179 | } |
| 2180 | if recoveryVariantNeeded { |
| 2181 | variants = append(variants, recoveryMode) |
| 2182 | } |
Jiyong Park | 7ed9de3 | 2018-10-15 22:25:07 +0900 | [diff] [blame] | 2183 | mod := mctx.CreateVariations(variants...) |
| 2184 | for i, v := range variants { |
| 2185 | if v == recoveryMode { |
| 2186 | m := mod[i].(*genrule.Module) |
| 2187 | m.Extra.(*GenruleExtraProperties).InRecovery = true |
| 2188 | } |
| 2189 | } |
Dan Willemsen | 3e5bdf2 | 2017-09-13 18:37:08 -0700 | [diff] [blame] | 2190 | } |
| 2191 | } |
| 2192 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2193 | m, ok := mctx.Module().(*Module) |
| 2194 | if !ok { |
| 2195 | return |
| 2196 | } |
| 2197 | |
| 2198 | // Sanity check |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2199 | vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific() |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 2200 | productSpecific := mctx.ProductSpecific() |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2201 | |
| 2202 | if m.VendorProperties.Vendor_available != nil && vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2203 | mctx.PropertyErrorf("vendor_available", |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2204 | "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] | 2205 | return |
| 2206 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2207 | |
| 2208 | if vndkdep := m.vndkdep; vndkdep != nil { |
| 2209 | if vndkdep.isVndk() { |
Justin Yun | 9357f4a | 2018-11-28 15:14:47 +0900 | [diff] [blame] | 2210 | if productSpecific { |
| 2211 | mctx.PropertyErrorf("product_specific", |
| 2212 | "product_specific must not be true when `vndk: {enabled: true}`") |
| 2213 | return |
| 2214 | } |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2215 | if vendorSpecific { |
| 2216 | if !vndkdep.isVndkExt() { |
| 2217 | mctx.PropertyErrorf("vndk", |
| 2218 | "must set `extends: \"...\"` to vndk extension") |
| 2219 | return |
| 2220 | } |
| 2221 | } else { |
| 2222 | if vndkdep.isVndkExt() { |
| 2223 | mctx.PropertyErrorf("vndk", |
| 2224 | "must set `vendor: true` to set `extends: %q`", |
| 2225 | m.getVndkExtendsModuleName()) |
| 2226 | return |
| 2227 | } |
| 2228 | if m.VendorProperties.Vendor_available == nil { |
| 2229 | mctx.PropertyErrorf("vndk", |
| 2230 | "vendor_available must be set to either true or false when `vndk: {enabled: true}`") |
| 2231 | return |
| 2232 | } |
| 2233 | } |
| 2234 | } else { |
| 2235 | if vndkdep.isVndkSp() { |
| 2236 | mctx.PropertyErrorf("vndk", |
| 2237 | "must set `enabled: true` to set `support_system_process: true`") |
| 2238 | return |
| 2239 | } |
| 2240 | if vndkdep.isVndkExt() { |
| 2241 | mctx.PropertyErrorf("vndk", |
| 2242 | "must set `enabled: true` to set `extends: %q`", |
| 2243 | m.getVndkExtendsModuleName()) |
| 2244 | return |
| 2245 | } |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 2246 | } |
| 2247 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2248 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2249 | var coreVariantNeeded bool = false |
| 2250 | var vendorVariantNeeded bool = false |
| 2251 | var recoveryVariantNeeded bool = false |
| 2252 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2253 | if mctx.DeviceConfig().VndkVersion() == "" { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2254 | // If the device isn't compiling against the VNDK, we always |
| 2255 | // use the core mode. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2256 | coreVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2257 | } else if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 2258 | // LL-NDK stubs only exist in the vendor variant, since the |
| 2259 | // real libraries will be used in the core variant. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2260 | vendorVariantNeeded = true |
Jiyong Park | 2a45412 | 2017-10-19 15:59:33 +0900 | [diff] [blame] | 2261 | } else if _, ok := m.linker.(*llndkHeadersDecorator); ok { |
| 2262 | // ... and LL-NDK headers as well |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2263 | vendorVariantNeeded = true |
Justin Yun | 312ccb9 | 2018-01-23 12:07:46 +0900 | [diff] [blame] | 2264 | } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 2265 | // Make vendor variants only for the versions in BOARD_VNDK_VERSION and |
| 2266 | // PRODUCT_EXTRA_VNDK_VERSIONS. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2267 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2268 | } else if m.hasVendorVariant() && !vendorSpecific { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2269 | // This will be available in both /system and /vendor |
Justin Yun | 8effde4 | 2017-06-23 19:24:43 +0900 | [diff] [blame] | 2270 | // or a /system directory that is available to vendor. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2271 | coreVariantNeeded = true |
| 2272 | vendorVariantNeeded = true |
Logan Chien | f351174 | 2017-10-31 18:04:35 +0800 | [diff] [blame] | 2273 | } else if vendorSpecific && String(m.Properties.Sdk_version) == "" { |
Jiyong Park | 2db7692 | 2017-11-08 16:03:48 +0900 | [diff] [blame] | 2274 | // This will be available in /vendor (or /odm) only |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2275 | vendorVariantNeeded = true |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2276 | } else { |
| 2277 | // This is either in /system (or similar: /data), or is a |
| 2278 | // modules built with the NDK. Modules built with the NDK |
| 2279 | // will be restricted using the existing link type checks. |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2280 | coreVariantNeeded = true |
| 2281 | } |
| 2282 | |
| 2283 | if Bool(m.Properties.Recovery_available) { |
| 2284 | recoveryVariantNeeded = true |
| 2285 | } |
| 2286 | |
| 2287 | if m.ModuleBase.InstallInRecovery() { |
| 2288 | recoveryVariantNeeded = true |
| 2289 | coreVariantNeeded = false |
| 2290 | } |
| 2291 | |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2292 | if recoveryVariantNeeded { |
Jiyong Park | 8d52f86 | 2018-07-07 18:02:07 +0900 | [diff] [blame] | 2293 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 2294 | moduleArch := m.Target().Arch.ArchType |
| 2295 | if moduleArch != primaryArch { |
Jiyong Park | 413cc74 | 2018-06-19 01:46:06 +0900 | [diff] [blame] | 2296 | recoveryVariantNeeded = false |
| 2297 | } |
| 2298 | } |
| 2299 | |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2300 | var variants []string |
| 2301 | if coreVariantNeeded { |
| 2302 | variants = append(variants, coreMode) |
| 2303 | } |
| 2304 | if vendorVariantNeeded { |
| 2305 | variants = append(variants, vendorMode) |
| 2306 | } |
| 2307 | if recoveryVariantNeeded { |
| 2308 | variants = append(variants, recoveryMode) |
| 2309 | } |
| 2310 | mod := mctx.CreateVariations(variants...) |
| 2311 | for i, v := range variants { |
| 2312 | if v == vendorMode { |
| 2313 | m := mod[i].(*Module) |
| 2314 | m.Properties.UseVndk = true |
| 2315 | squashVendorSrcs(m) |
| 2316 | } else if v == recoveryMode { |
| 2317 | m := mod[i].(*Module) |
| 2318 | m.Properties.InRecovery = true |
Jiyong Park | 5baac54 | 2018-08-28 09:55:37 +0900 | [diff] [blame] | 2319 | m.MakeAsPlatform() |
Jiyong Park | f9332f1 | 2018-02-01 00:54:12 +0900 | [diff] [blame] | 2320 | squashRecoverySrcs(m) |
| 2321 | } |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 2322 | } |
| 2323 | } |
| 2324 | |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2325 | func getCurrentNdkPrebuiltVersion(ctx DepsContext) string { |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2326 | if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt { |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2327 | return strconv.Itoa(config.NdkMaxPrebuiltVersionInt) |
| 2328 | } |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 2329 | return ctx.Config().PlatformSdkVersion() |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 2332 | var Bool = proptools.Bool |
Colin Cross | 38b40df | 2018-04-10 16:14:46 -0700 | [diff] [blame] | 2333 | var BoolDefault = proptools.BoolDefault |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 2334 | var BoolPtr = proptools.BoolPtr |
| 2335 | var String = proptools.String |
| 2336 | var StringPtr = proptools.StringPtr |