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