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 | 2a252be | 2017-05-01 17:37:24 -0700 | [diff] [blame] | 109 | rsFlags []string // Flags that apply to renderscript source files |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 110 | LdFlags []string // Flags that apply to linker command lines |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 111 | libFlags []string // Flags to add libraries early to the link order |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 112 | TidyFlags []string // Flags that apply to clang-tidy |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 113 | SAbiFlags []string // Flags that apply to header-abi-dumper |
Colin Cross | 91e9004 | 2016-12-02 17:13:24 -0800 | [diff] [blame] | 114 | YasmFlags []string // Flags that apply to yasm assembly source files |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 115 | |
Colin Cross | c319948 | 2017-03-30 15:03:04 -0700 | [diff] [blame] | 116 | // Global include flags that apply to C, C++, and assembly source files |
| 117 | // These must be after any module include flags, which will be in GlobalFlags. |
| 118 | SystemIncludeFlags []string |
| 119 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 120 | Toolchain config.Toolchain |
Colin Cross | 2834452 | 2015-04-22 13:07:53 -0700 | [diff] [blame] | 121 | Clang bool |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 122 | Tidy bool |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 123 | Coverage bool |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 124 | SAbiDump bool |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 125 | |
| 126 | RequiredInstructionSet string |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 127 | DynamicLinker string |
| 128 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 129 | CFlagsDeps android.Paths // Files depended on by compiler flags |
Colin Cross | 18c0c5a | 2016-12-01 14:45:23 -0800 | [diff] [blame] | 130 | |
| 131 | GroupStaticLibs bool |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Colin Cross | 8141347 | 2016-04-11 14:37:39 -0700 | [diff] [blame] | 134 | type ObjectLinkerProperties struct { |
| 135 | // names of other cc_object modules to link into this module using partial linking |
| 136 | Objs []string `android:"arch_variant"` |
| 137 | } |
| 138 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 139 | // Properties used to compile all C or C++ modules |
| 140 | type BaseProperties struct { |
| 141 | // compile module with clang instead of gcc |
| 142 | Clang *bool `android:"arch_variant"` |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 143 | |
| 144 | // Minimum sdk version supported when compiling against the ndk |
| 145 | Sdk_version string |
| 146 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 147 | // don't insert default compiler flags into asflags, cflags, |
| 148 | // cppflags, conlyflags, ldflags, or include_dirs |
| 149 | No_default_compiler_flags *bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 150 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 151 | // whether this module should be allowed to install onto /vendor as |
| 152 | // well as /system. The two variants will be built separately, one |
| 153 | // like normal, and the other limited to the set of libraries and |
| 154 | // headers that are exposed to /vendor modules. |
| 155 | // |
| 156 | // The vendor variant may be used with a different (newer) /system, |
| 157 | // so it shouldn't have any unversioned runtime dependencies, or |
| 158 | // make assumptions about the system that may not be true in the |
| 159 | // future. |
| 160 | // |
| 161 | // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk |
| 162 | Vendor_available *bool |
| 163 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 164 | AndroidMkSharedLibs []string `blueprint:"mutated"` |
Colin Cross | bc6fb16 | 2016-05-24 15:39:04 -0700 | [diff] [blame] | 165 | HideFromMake bool `blueprint:"mutated"` |
Colin Cross | b0f2895 | 2016-09-19 16:46:53 -0700 | [diff] [blame] | 166 | PreventInstall bool `blueprint:"mutated"` |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 167 | |
| 168 | UseVndk bool `blueprint:"mutated"` |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 171 | type UnusedProperties struct { |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 172 | Tags []string |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 175 | type ModuleContextIntf interface { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 176 | static() bool |
| 177 | staticBinary() bool |
| 178 | clang() bool |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 179 | toolchain() config.Toolchain |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 180 | noDefaultCompilerFlags() bool |
| 181 | sdk() bool |
| 182 | sdkVersion() string |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 183 | vndk() bool |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 184 | createVndkSourceAbiDump() bool |
Dan Willemsen | 8146b2f | 2016-03-30 21:00:30 -0700 | [diff] [blame] | 185 | selectedStl() string |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 186 | baseModuleName() string |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | type ModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 190 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 191 | ModuleContextIntf |
| 192 | } |
| 193 | |
| 194 | type BaseModuleContext interface { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 195 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 196 | ModuleContextIntf |
| 197 | } |
| 198 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 199 | type DepsContext interface { |
| 200 | android.BottomUpMutatorContext |
| 201 | ModuleContextIntf |
| 202 | } |
| 203 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 204 | type feature interface { |
| 205 | begin(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 206 | deps(ctx DepsContext, deps Deps) Deps |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 207 | flags(ctx ModuleContext, flags Flags) Flags |
| 208 | props() []interface{} |
| 209 | } |
| 210 | |
| 211 | type compiler interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 212 | compilerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 213 | compilerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 214 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 215 | compilerProps() []interface{} |
| 216 | |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 217 | appendCflags([]string) |
| 218 | appendAsflags([]string) |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 219 | compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | type linker interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 223 | linkerInit(ctx BaseModuleContext) |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 224 | linkerDeps(ctx DepsContext, deps Deps) Deps |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 225 | linkerFlags(ctx ModuleContext, flags Flags) Flags |
| 226 | linkerProps() []interface{} |
| 227 | |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 228 | link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path |
Colin Cross | 76fada0 | 2016-07-27 10:31:13 -0700 | [diff] [blame] | 229 | appendLdflags([]string) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | type installer interface { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 233 | installerProps() []interface{} |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 234 | install(ctx ModuleContext, path android.Path) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 235 | inData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 236 | inSanitizerDir() bool |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 237 | hostToolPath() android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 240 | type dependencyTag struct { |
| 241 | blueprint.BaseDependencyTag |
| 242 | name string |
| 243 | library bool |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 244 | |
| 245 | reexportFlags bool |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | var ( |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 249 | sharedDepTag = dependencyTag{name: "shared", library: true} |
| 250 | sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true} |
| 251 | lateSharedDepTag = dependencyTag{name: "late shared", library: true} |
| 252 | staticDepTag = dependencyTag{name: "static", library: true} |
| 253 | staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true} |
| 254 | lateStaticDepTag = dependencyTag{name: "late static", library: true} |
| 255 | wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true} |
Colin Cross | 32ec36c | 2016-12-15 07:39:51 -0800 | [diff] [blame] | 256 | headerDepTag = dependencyTag{name: "header", library: true} |
| 257 | headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true} |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 258 | genSourceDepTag = dependencyTag{name: "gen source"} |
| 259 | genHeaderDepTag = dependencyTag{name: "gen header"} |
| 260 | genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true} |
| 261 | objDepTag = dependencyTag{name: "obj"} |
| 262 | crtBeginDepTag = dependencyTag{name: "crtbegin"} |
| 263 | crtEndDepTag = dependencyTag{name: "crtend"} |
| 264 | reuseObjTag = dependencyTag{name: "reuse objects"} |
| 265 | ndkStubDepTag = dependencyTag{name: "ndk stub", library: true} |
| 266 | ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true} |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 267 | ) |
| 268 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 269 | // Module contains the properties and members used by all C/C++ module types, and implements |
| 270 | // the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces |
| 271 | // to construct the output file. Behavior can be customized with a Customizer interface |
| 272 | type Module struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 273 | android.ModuleBase |
| 274 | android.DefaultableModule |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 275 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 276 | Properties BaseProperties |
| 277 | unused UnusedProperties |
Colin Cross | fa13879 | 2015-04-24 17:31:52 -0700 | [diff] [blame] | 278 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 279 | // initialize before calling Init |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 280 | hod android.HostOrDeviceSupported |
| 281 | multilib android.Multilib |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 282 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 283 | // delegates, initialize before calling Init |
Colin Cross | b4ce0ec | 2016-09-13 13:41:39 -0700 | [diff] [blame] | 284 | features []feature |
| 285 | compiler compiler |
| 286 | linker linker |
| 287 | installer installer |
| 288 | stl *stl |
| 289 | sanitize *sanitize |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 290 | coverage *coverage |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 291 | sabi *sabi |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 292 | |
| 293 | androidMkSharedLibDeps []string |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 294 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 295 | outputFile android.OptionalPath |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 296 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 297 | cachedToolchain config.Toolchain |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 298 | |
| 299 | subAndroidMkOnce map[subAndroidMkProvider]bool |
Fabien Sanglard | d61f1f4 | 2017-01-10 16:21:22 -0800 | [diff] [blame] | 300 | |
| 301 | // Flags used to compile this module |
| 302 | flags Flags |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 305 | func (c *Module) Init() (blueprint.Module, []interface{}) { |
| 306 | props := []interface{}{&c.Properties, &c.unused} |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 307 | if c.compiler != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 308 | props = append(props, c.compiler.compilerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 309 | } |
| 310 | if c.linker != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 311 | props = append(props, c.linker.linkerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 312 | } |
| 313 | if c.installer != nil { |
Colin Cross | 42742b8 | 2016-08-01 13:20:05 -0700 | [diff] [blame] | 314 | props = append(props, c.installer.installerProps()...) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 315 | } |
Colin Cross | a8e07cc | 2016-04-04 15:07:06 -0700 | [diff] [blame] | 316 | if c.stl != nil { |
| 317 | props = append(props, c.stl.props()...) |
| 318 | } |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 319 | if c.sanitize != nil { |
| 320 | props = append(props, c.sanitize.props()...) |
| 321 | } |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 322 | if c.coverage != nil { |
| 323 | props = append(props, c.coverage.props()...) |
| 324 | } |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 325 | if c.sabi != nil { |
| 326 | props = append(props, c.sabi.props()...) |
| 327 | } |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 328 | for _, feature := range c.features { |
| 329 | props = append(props, feature.props()...) |
| 330 | } |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 331 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 332 | _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...) |
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 | return android.InitDefaultableModule(c, c, props...) |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 337 | // Returns true for dependency roots (binaries) |
| 338 | // TODO(ccross): also handle dlopenable libraries |
| 339 | func (c *Module) isDependencyRoot() bool { |
| 340 | if root, ok := c.linker.(interface { |
| 341 | isDependencyRoot() bool |
| 342 | }); ok { |
| 343 | return root.isDependencyRoot() |
| 344 | } |
| 345 | return false |
| 346 | } |
| 347 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 348 | func (c *Module) vndk() bool { |
| 349 | return c.Properties.UseVndk |
| 350 | } |
| 351 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 352 | type baseModuleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 353 | android.BaseContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 354 | moduleContextImpl |
| 355 | } |
| 356 | |
Colin Cross | 37047f1 | 2016-12-13 17:06:13 -0800 | [diff] [blame] | 357 | type depsContext struct { |
| 358 | android.BottomUpMutatorContext |
| 359 | moduleContextImpl |
| 360 | } |
| 361 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 362 | type moduleContext struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 363 | android.ModuleContext |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 364 | moduleContextImpl |
| 365 | } |
| 366 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 367 | // Vendor returns true for vendor modules so that they get installed onto the |
| 368 | // correct partition |
| 369 | func (ctx *moduleContext) Vendor() bool { |
| 370 | return ctx.ModuleContext.Vendor() || ctx.moduleContextImpl.mod.Properties.UseVndk |
| 371 | } |
| 372 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 373 | type moduleContextImpl struct { |
| 374 | mod *Module |
| 375 | ctx BaseModuleContext |
| 376 | } |
| 377 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 378 | func (ctx *moduleContextImpl) clang() bool { |
| 379 | return ctx.mod.clang(ctx.ctx) |
| 380 | } |
| 381 | |
Colin Cross | b98c8b0 | 2016-07-29 13:44:28 -0700 | [diff] [blame] | 382 | func (ctx *moduleContextImpl) toolchain() config.Toolchain { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 383 | return ctx.mod.toolchain(ctx.ctx) |
| 384 | } |
| 385 | |
| 386 | func (ctx *moduleContextImpl) static() bool { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 387 | if static, ok := ctx.mod.linker.(interface { |
| 388 | static() bool |
| 389 | }); ok { |
| 390 | return static.static() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 391 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 392 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | func (ctx *moduleContextImpl) staticBinary() bool { |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 396 | if static, ok := ctx.mod.linker.(interface { |
| 397 | staticBinary() bool |
| 398 | }); ok { |
| 399 | return static.staticBinary() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 400 | } |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 401 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool { |
| 405 | return Bool(ctx.mod.Properties.No_default_compiler_flags) |
| 406 | } |
| 407 | |
| 408 | func (ctx *moduleContextImpl) sdk() bool { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 409 | if ctx.ctx.Device() && !ctx.vndk() { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 410 | return ctx.mod.Properties.Sdk_version != "" |
| 411 | } |
| 412 | return false |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | func (ctx *moduleContextImpl) sdkVersion() string { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 416 | if ctx.ctx.Device() { |
Dan Willemsen | 11b2614 | 2017-03-19 18:30:37 -0700 | [diff] [blame] | 417 | if ctx.vndk() { |
| 418 | return "current" |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 419 | } else { |
| 420 | return ctx.mod.Properties.Sdk_version |
| 421 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 422 | } |
| 423 | return "" |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 426 | func (ctx *moduleContextImpl) vndk() bool { |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 427 | return ctx.mod.vndk() |
Dan Willemsen | d2ede87 | 2016-11-18 14:54:24 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 430 | // Create source abi dumps if the module belongs to the list of VndkLibraries. |
| 431 | func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool { |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame^] | 432 | 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] | 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 | } |
Colin Cross | e90bfd1 | 2017-04-26 16:59:26 -0700 | [diff] [blame] | 910 | // Support exported headers from a generated_sources dependency |
| 911 | fallthrough |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 912 | case genHeaderDepTag, genHeaderExportDepTag: |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 913 | if genRule, ok := m.(genrule.SourceFileGenerator); ok { |
| 914 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, |
| 915 | genRule.GeneratedSourceFiles()...) |
Colin Cross | 5ed99c6 | 2016-11-22 12:55:55 -0800 | [diff] [blame] | 916 | flags := includeDirsToFlags(genRule.GeneratedHeaderDirs()) |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 917 | depPaths.Flags = append(depPaths.Flags, flags) |
| 918 | if tag == genHeaderExportDepTag { |
| 919 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 920 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, |
| 921 | genRule.GeneratedSourceFiles()...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame^] | 922 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
| 923 | c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags) |
| 924 | |
Dan Willemsen | b3454ab | 2016-09-28 17:34:58 -0700 | [diff] [blame] | 925 | } |
Dan Willemsen | b40aab6 | 2016-04-20 14:21:14 -0700 | [diff] [blame] | 926 | } else { |
| 927 | ctx.ModuleErrorf("module %q is not a genrule", name) |
| 928 | } |
| 929 | default: |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 930 | ctx.ModuleErrorf("depends on non-cc module %q", name) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 931 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 932 | return |
| 933 | } |
| 934 | |
| 935 | if !a.Enabled() { |
Colin Cross | a8f5e9a | 2016-12-13 12:51:11 -0800 | [diff] [blame] | 936 | if ctx.AConfig().AllowMissingDependencies() { |
| 937 | ctx.AddMissingDependencies([]string{name}) |
| 938 | } else { |
| 939 | ctx.ModuleErrorf("depends on disabled module %q", name) |
| 940 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 941 | return |
| 942 | } |
| 943 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 944 | if a.Target().Os != ctx.Os() { |
| 945 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name) |
| 946 | return |
| 947 | } |
| 948 | |
| 949 | if a.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 950 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 951 | return |
| 952 | } |
| 953 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 954 | if tag == reuseObjTag { |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 955 | if l, ok := cc.compiler.(libraryInterface); ok { |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 956 | objs, flags, deps := l.reuseObjs() |
Colin Cross | 10d2231 | 2017-05-03 11:01:58 -0700 | [diff] [blame] | 957 | depPaths.Objs = depPaths.Objs.Append(objs) |
| 958 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Colin Cross | bbc9f4d | 2017-05-03 16:24:55 -0700 | [diff] [blame] | 959 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...) |
Colin Cross | bba9904 | 2016-11-23 15:45:05 -0800 | [diff] [blame] | 960 | return |
| 961 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 962 | } |
| 963 | |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 964 | if t, ok := tag.(dependencyTag); ok && t.library { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 965 | if i, ok := cc.linker.(exportedFlagsProducer); ok { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 966 | flags := i.exportedFlags() |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 967 | deps := i.exportedFlagsDeps() |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 968 | depPaths.Flags = append(depPaths.Flags, flags...) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 969 | depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...) |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 970 | |
| 971 | if t.reexportFlags { |
Dan Willemsen | 76f0827 | 2016-07-09 00:14:08 -0700 | [diff] [blame] | 972 | depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) |
Dan Willemsen | 847dcc7 | 2016-09-29 12:13:36 -0700 | [diff] [blame] | 973 | depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...) |
Jayant Chowdhary | 715cac3 | 2017-04-20 06:53:59 -0700 | [diff] [blame^] | 974 | // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library. |
| 975 | // Re-exported flags from shared library dependencies are not included as those shared libraries |
| 976 | // will be included in the vndk set. |
| 977 | if tag == staticExportDepTag || tag == headerExportDepTag { |
| 978 | c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...) |
| 979 | } |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 980 | } |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 981 | } |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 982 | |
Dan Albert | 9e10cd4 | 2016-08-03 14:12:14 -0700 | [diff] [blame] | 983 | checkLinkType(c, cc) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 986 | var ptr *android.Paths |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 987 | var depPtr *android.Paths |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 988 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 989 | linkFile := cc.outputFile |
| 990 | depFile := android.OptionalPath{} |
| 991 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 992 | switch tag { |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 993 | case ndkStubDepTag, sharedDepTag, sharedExportDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 994 | ptr = &depPaths.SharedLibs |
| 995 | depPtr = &depPaths.SharedLibsDeps |
| 996 | depFile = cc.linker.(libraryInterface).toc() |
Dan Albert | 914449f | 2016-06-17 16:45:24 -0700 | [diff] [blame] | 997 | case lateSharedDepTag, ndkLateStubDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 998 | ptr = &depPaths.LateSharedLibs |
| 999 | depPtr = &depPaths.LateSharedLibsDeps |
| 1000 | depFile = cc.linker.(libraryInterface).toc() |
Dan Willemsen | 490a8dc | 2016-06-06 18:22:19 -0700 | [diff] [blame] | 1001 | case staticDepTag, staticExportDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1002 | ptr = &depPaths.StaticLibs |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1003 | case lateStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1004 | ptr = &depPaths.LateStaticLibs |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1005 | case wholeStaticDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1006 | ptr = &depPaths.WholeStaticLibs |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1007 | staticLib, ok := cc.linker.(libraryInterface) |
| 1008 | if !ok || !staticLib.static() { |
Dan Willemsen | a96ff64 | 2016-06-07 12:34:45 -0700 | [diff] [blame] | 1009 | ctx.ModuleErrorf("module %q not a static library", name) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1010 | return |
| 1011 | } |
| 1012 | |
| 1013 | if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { |
| 1014 | postfix := " (required by " + ctx.OtherModuleName(m) + ")" |
| 1015 | for i := range missingDeps { |
| 1016 | missingDeps[i] += postfix |
| 1017 | } |
| 1018 | ctx.AddMissingDependencies(missingDeps) |
| 1019 | } |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1020 | depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs()) |
Colin Cross | 5950f38 | 2016-12-13 12:50:57 -0800 | [diff] [blame] | 1021 | case headerDepTag: |
| 1022 | // Nothing |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1023 | case objDepTag: |
Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 1024 | depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path()) |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1025 | case crtBeginDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1026 | depPaths.CrtBegin = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1027 | case crtEndDepTag: |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1028 | depPaths.CrtEnd = linkFile |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1031 | switch tag { |
| 1032 | case staticDepTag, staticExportDepTag, lateStaticDepTag: |
| 1033 | staticLib, ok := cc.linker.(libraryInterface) |
| 1034 | if !ok || !staticLib.static() { |
| 1035 | ctx.ModuleErrorf("module %q not a static library", name) |
| 1036 | return |
| 1037 | } |
| 1038 | |
| 1039 | // When combining coverage files for shared libraries and executables, coverage files |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1040 | // in static libraries act as if they were whole static libraries. The same goes for |
| 1041 | // source based Abi dump files. |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1042 | depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles, |
| 1043 | staticLib.objs().coverageFiles...) |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1044 | depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, |
| 1045 | staticLib.objs().sAbiDumpFiles...) |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1048 | if ptr != nil { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 1049 | if !linkFile.Valid() { |
| 1050 | ctx.ModuleErrorf("module %q missing output file", name) |
| 1051 | return |
| 1052 | } |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1053 | *ptr = append(*ptr, linkFile.Path()) |
| 1054 | } |
| 1055 | |
Colin Cross | c99deeb | 2016-04-11 15:06:20 -0700 | [diff] [blame] | 1056 | if depPtr != nil { |
Colin Cross | 26c34ed | 2016-09-30 17:10:16 -0700 | [diff] [blame] | 1057 | dep := depFile |
| 1058 | if !dep.Valid() { |
| 1059 | dep = linkFile |
| 1060 | } |
| 1061 | *depPtr = append(*depPtr, dep.Path()) |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1062 | } |
| 1063 | }) |
| 1064 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1065 | // Dedup exported flags from dependencies |
| 1066 | depPaths.Flags = firstUniqueElements(depPaths.Flags) |
| 1067 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1068 | return depPaths |
| 1069 | } |
| 1070 | |
| 1071 | func (c *Module) InstallInData() bool { |
| 1072 | if c.installer == nil { |
| 1073 | return false |
| 1074 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1075 | return c.installer.inData() |
| 1076 | } |
| 1077 | |
| 1078 | func (c *Module) InstallInSanitizerDir() bool { |
| 1079 | if c.installer == nil { |
| 1080 | return false |
| 1081 | } |
| 1082 | if c.sanitize != nil && c.sanitize.inSanitizerDir() { |
Colin Cross | 9461040 | 2016-08-29 13:41:32 -0700 | [diff] [blame] | 1083 | return true |
| 1084 | } |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 1085 | return c.installer.inSanitizerDir() |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1086 | } |
| 1087 | |
Dan Willemsen | 4aa75ca | 2016-09-28 16:18:03 -0700 | [diff] [blame] | 1088 | func (c *Module) HostToolPath() android.OptionalPath { |
| 1089 | if c.installer == nil { |
| 1090 | return android.OptionalPath{} |
| 1091 | } |
| 1092 | return c.installer.hostToolPath() |
| 1093 | } |
| 1094 | |
Colin Cross | 2ba19d9 | 2015-05-07 15:44:20 -0700 | [diff] [blame] | 1095 | // |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1096 | // Defaults |
| 1097 | // |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1098 | type Defaults struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1099 | android.ModuleBase |
| 1100 | android.DefaultsModule |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1103 | func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 1106 | func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1107 | } |
| 1108 | |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1109 | func defaultsFactory() (blueprint.Module, []interface{}) { |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1110 | return DefaultsFactory() |
| 1111 | } |
| 1112 | |
| 1113 | func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1114 | module := &Defaults{} |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1115 | |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1116 | props = append(props, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1117 | &BaseProperties{}, |
| 1118 | &BaseCompilerProperties{}, |
| 1119 | &BaseLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1120 | &LibraryProperties{}, |
Colin Cross | 919281a | 2016-04-05 16:42:05 -0700 | [diff] [blame] | 1121 | &FlagExporterProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1122 | &BinaryLinkerProperties{}, |
Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 1123 | &TestProperties{}, |
| 1124 | &TestBinaryProperties{}, |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1125 | &UnusedProperties{}, |
| 1126 | &StlProperties{}, |
Colin Cross | 16b2349 | 2016-01-06 14:41:07 -0800 | [diff] [blame] | 1127 | &SanitizeProperties{}, |
Colin Cross | 665dce9 | 2016-04-28 14:50:03 -0700 | [diff] [blame] | 1128 | &StripProperties{}, |
Dan Willemsen | 7424d61 | 2016-09-01 13:45:39 -0700 | [diff] [blame] | 1129 | &InstallerProperties{}, |
Dan Willemsen | a03cf6d | 2016-09-26 15:45:04 -0700 | [diff] [blame] | 1130 | &TidyProperties{}, |
Dan Willemsen | 581341d | 2017-02-09 16:16:31 -0800 | [diff] [blame] | 1131 | &CoverageProperties{}, |
Jayant Chowdhary | 3e231fd | 2017-02-08 13:45:53 -0800 | [diff] [blame] | 1132 | &SAbiProperties{}, |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1133 | ) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1134 | |
Colin Cross | e1d764e | 2016-08-18 14:18:32 -0700 | [diff] [blame] | 1135 | return android.InitDefaultsModule(module, module, props...) |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 1136 | } |
| 1137 | |
Dan Willemsen | 4416e5d | 2017-04-06 12:43:22 -0700 | [diff] [blame] | 1138 | const ( |
| 1139 | // coreMode is the variant used for framework-private libraries, or |
| 1140 | // SDK libraries. (which framework-private libraries can use) |
| 1141 | coreMode = "core" |
| 1142 | |
| 1143 | // vendorMode is the variant used for /vendor code that compiles |
| 1144 | // against the VNDK. |
| 1145 | vendorMode = "vendor" |
| 1146 | ) |
| 1147 | |
| 1148 | func vendorMutator(mctx android.BottomUpMutatorContext) { |
| 1149 | if mctx.Os() != android.Android { |
| 1150 | return |
| 1151 | } |
| 1152 | |
| 1153 | m, ok := mctx.Module().(*Module) |
| 1154 | if !ok { |
| 1155 | return |
| 1156 | } |
| 1157 | |
| 1158 | // Sanity check |
| 1159 | if Bool(m.Properties.Vendor_available) && mctx.Vendor() { |
| 1160 | mctx.PropertyErrorf("vendor_available", |
| 1161 | "doesn't make sense at the same time as `vendor: true` or `proprietary: true`") |
| 1162 | return |
| 1163 | } |
| 1164 | |
| 1165 | if !mctx.DeviceConfig().CompileVndk() { |
| 1166 | // If the device isn't compiling against the VNDK, we always |
| 1167 | // use the core mode. |
| 1168 | mctx.CreateVariations(coreMode) |
| 1169 | } else if _, ok := m.linker.(*llndkStubDecorator); ok { |
| 1170 | // LL-NDK stubs only exist in the vendor variant, since the |
| 1171 | // real libraries will be used in the core variant. |
| 1172 | mctx.CreateVariations(vendorMode) |
| 1173 | } else if Bool(m.Properties.Vendor_available) { |
| 1174 | // This will be available in both /system and /vendor |
| 1175 | mod := mctx.CreateVariations(coreMode, vendorMode) |
| 1176 | mod[1].(*Module).Properties.UseVndk = true |
| 1177 | } else if mctx.Vendor() && m.Properties.Sdk_version == "" { |
| 1178 | // This will be available in /vendor only |
| 1179 | mod := mctx.CreateVariations(vendorMode) |
| 1180 | mod[0].(*Module).Properties.UseVndk = true |
| 1181 | } else { |
| 1182 | // This is either in /system (or similar: /data), or is a |
| 1183 | // modules built with the NDK. Modules built with the NDK |
| 1184 | // will be restricted using the existing link type checks. |
| 1185 | mctx.CreateVariations(coreMode) |
| 1186 | } |
| 1187 | } |
| 1188 | |
Colin Cross | dd84e05 | 2017-05-17 13:44:16 -0700 | [diff] [blame] | 1189 | // firstUniqueElements returns all unique elements of a slice, keeping the first copy of each |
| 1190 | // modifies the slice contents in place, and returns a subslice of the original slice |
| 1191 | func firstUniqueElements(list []string) []string { |
| 1192 | k := 0 |
| 1193 | outer: |
| 1194 | for i := 0; i < len(list); i++ { |
| 1195 | for j := 0; j < k; j++ { |
| 1196 | if list[i] == list[j] { |
| 1197 | continue outer |
| 1198 | } |
| 1199 | } |
| 1200 | list[k] = list[i] |
| 1201 | k++ |
| 1202 | } |
| 1203 | return list[:k] |
| 1204 | } |
| 1205 | |
Colin Cross | 74d1ec0 | 2015-04-28 13:30:13 -0700 | [diff] [blame] | 1206 | // lastUniqueElements returns all unique elements of a slice, keeping the last copy of each |
| 1207 | // modifies the slice contents in place, and returns a subslice of the original slice |
| 1208 | func lastUniqueElements(list []string) []string { |
| 1209 | totalSkip := 0 |
| 1210 | for i := len(list) - 1; i >= totalSkip; i-- { |
| 1211 | skip := 0 |
| 1212 | for j := i - 1; j >= totalSkip; j-- { |
| 1213 | if list[i] == list[j] { |
| 1214 | skip++ |
| 1215 | } else { |
| 1216 | list[j+skip] = list[j] |
| 1217 | } |
| 1218 | } |
| 1219 | totalSkip += skip |
| 1220 | } |
| 1221 | return list[totalSkip:] |
| 1222 | } |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1223 | |
Jayant Chowdhary | 6e8115a | 2017-05-09 10:21:52 -0700 | [diff] [blame] | 1224 | func getCurrentNdkPrebuiltVersion(ctx DepsContext) string { |
| 1225 | if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt { |
| 1226 | return strconv.Itoa(config.NdkMaxPrebuiltVersionInt) |
| 1227 | } |
| 1228 | return ctx.AConfig().PlatformSdkVersion() |
| 1229 | } |
| 1230 | |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1231 | var Bool = proptools.Bool |