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