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