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