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