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