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