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