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