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