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