Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 18 | "fmt" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "path/filepath" |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 20 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 21 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 22 | "android/soong" |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 23 | "android/soong/glob" |
| 24 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 28 | func init() { |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 29 | RegisterTopDownMutator("load_hooks", loadHookMutator).Parallel() |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 30 | RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator).Parallel() |
| 31 | RegisterTopDownMutator("defaults", defaultsMutator).Parallel() |
| 32 | |
| 33 | RegisterBottomUpMutator("arch", ArchMutator).Parallel() |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 34 | RegisterTopDownMutator("arch_hooks", archHookMutator).Parallel() |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 37 | var ( |
| 38 | DeviceSharedLibrary = "shared_library" |
| 39 | DeviceStaticLibrary = "static_library" |
| 40 | DeviceExecutable = "executable" |
| 41 | HostSharedLibrary = "host_shared_library" |
| 42 | HostStaticLibrary = "host_static_library" |
| 43 | HostExecutable = "host_executable" |
| 44 | ) |
| 45 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 46 | type ModuleBuildParams struct { |
| 47 | Rule blueprint.Rule |
| 48 | Output WritablePath |
| 49 | Outputs WritablePaths |
| 50 | Input Path |
| 51 | Inputs Paths |
| 52 | Implicit Path |
| 53 | Implicits Paths |
| 54 | OrderOnly Paths |
| 55 | Default bool |
| 56 | Args map[string]string |
| 57 | } |
| 58 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 59 | type androidBaseContext interface { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 60 | Target() Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 61 | TargetPrimary() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 62 | Arch() Arch |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 63 | Os() OsType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 64 | Host() bool |
| 65 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 66 | Darwin() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 67 | Debug() bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 68 | PrimaryArch() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 69 | AConfig() Config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 70 | DeviceConfig() DeviceConfig |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 73 | type BaseContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 74 | blueprint.BaseModuleContext |
| 75 | androidBaseContext |
| 76 | } |
| 77 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 78 | type ModuleContext interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 79 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 80 | androidBaseContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 81 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 82 | // Similar to Build, but takes Paths instead of []string, |
| 83 | // and performs more verification. |
| 84 | ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 85 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 86 | ExpandSources(srcFiles, excludes []string) Paths |
| 87 | Glob(outDir, globPattern string, excludes []string) Paths |
| 88 | |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 89 | InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath |
| 90 | InstallFileName(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 91 | InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 92 | CheckbuildFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 93 | |
| 94 | AddMissingDependencies(deps []string) |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 95 | |
| 96 | Proprietary() bool |
| 97 | InstallInData() bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 100 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 101 | blueprint.Module |
| 102 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 103 | GenerateAndroidBuildActions(ModuleContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 104 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 105 | base() *ModuleBase |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 106 | Enabled() bool |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 107 | Target() Target |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 108 | InstallInData() bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 111 | type commonProperties struct { |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 112 | Name string |
| 113 | Deps []string |
| 114 | Tags []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 115 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 116 | // emit build rules for this module |
| 117 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 118 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 119 | // control whether this module compiles for 32-bit, 64-bit, or both. Possible values |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 120 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 121 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 122 | // platform |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 123 | Compile_multilib string `android:"arch_variant"` |
| 124 | |
| 125 | Target struct { |
| 126 | Host struct { |
| 127 | Compile_multilib string |
| 128 | } |
| 129 | Android struct { |
| 130 | Compile_multilib string |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | Default_multilib string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 135 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 136 | // whether this is a proprietary vendor module, and should be installed into /vendor |
| 137 | Proprietary bool |
| 138 | |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 139 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 140 | // file |
| 141 | Logtags []string |
| 142 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 143 | // init.rc files to be installed if this module is installed |
| 144 | Init_rc []string |
| 145 | |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 146 | // names of other modules to install if this module is installed |
| 147 | Required []string |
| 148 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 149 | // Set by TargetMutator |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 150 | CompileTarget Target `blueprint:"mutated"` |
| 151 | CompilePrimary bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 152 | |
| 153 | // Set by InitAndroidModule |
| 154 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
| 155 | } |
| 156 | |
| 157 | type hostAndDeviceProperties struct { |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 158 | Host_supported *bool |
| 159 | Device_supported *bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 160 | } |
| 161 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 162 | type Multilib string |
| 163 | |
| 164 | const ( |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 165 | MultilibBoth Multilib = "both" |
| 166 | MultilibFirst Multilib = "first" |
| 167 | MultilibCommon Multilib = "common" |
| 168 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 169 | ) |
| 170 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 171 | type HostOrDeviceSupported int |
| 172 | |
| 173 | const ( |
| 174 | _ HostOrDeviceSupported = iota |
| 175 | HostSupported |
| 176 | DeviceSupported |
| 177 | HostAndDeviceSupported |
| 178 | HostAndDeviceDefault |
| 179 | ) |
| 180 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 181 | func InitAndroidModule(m Module, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 182 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 183 | |
| 184 | base := m.base() |
| 185 | base.module = m |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 186 | |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 187 | propertyStructs = append(propertyStructs, &base.commonProperties, &base.variableProperties) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 188 | |
| 189 | return m, propertyStructs |
| 190 | } |
| 191 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 192 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib, |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 193 | propertyStructs ...interface{}) (blueprint.Module, []interface{}) { |
| 194 | |
| 195 | _, propertyStructs = InitAndroidModule(m, propertyStructs...) |
| 196 | |
| 197 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 198 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 199 | base.commonProperties.Default_multilib = string(defaultMultilib) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 200 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 201 | switch hod { |
| 202 | case HostAndDeviceSupported: |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 203 | // Default to module to device supported, host not supported, can override in module |
| 204 | // properties |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 205 | base.hostAndDeviceProperties.Device_supported = boolPtr(true) |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 206 | fallthrough |
| 207 | case HostAndDeviceDefault: |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 208 | propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties) |
| 209 | } |
| 210 | |
Colin Cross | cfad119 | 2015-11-02 16:43:11 -0800 | [diff] [blame] | 211 | return InitArchModule(m, propertyStructs...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // A AndroidModuleBase object contains the properties that are common to all Android |
| 215 | // modules. It should be included as an anonymous field in every module |
| 216 | // struct definition. InitAndroidModule should then be called from the module's |
| 217 | // factory function, and the return values from InitAndroidModule should be |
| 218 | // returned from the factory function. |
| 219 | // |
| 220 | // The AndroidModuleBase type is responsible for implementing the |
| 221 | // GenerateBuildActions method to support the blueprint.Module interface. This |
| 222 | // method will then call the module's GenerateAndroidBuildActions method once |
| 223 | // for each build variant that is to be built. GenerateAndroidBuildActions is |
| 224 | // passed a AndroidModuleContext rather than the usual blueprint.ModuleContext. |
| 225 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 226 | // system including details about the particular build variant that is to be |
| 227 | // generated. |
| 228 | // |
| 229 | // For example: |
| 230 | // |
| 231 | // import ( |
| 232 | // "android/soong/common" |
Colin Cross | 70b4059 | 2015-03-23 12:57:34 -0700 | [diff] [blame] | 233 | // "github.com/google/blueprint" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 234 | // ) |
| 235 | // |
| 236 | // type myModule struct { |
| 237 | // common.AndroidModuleBase |
| 238 | // properties struct { |
| 239 | // MyProperty string |
| 240 | // } |
| 241 | // } |
| 242 | // |
| 243 | // func NewMyModule() (blueprint.Module, []interface{}) { |
| 244 | // m := &myModule{} |
| 245 | // return common.InitAndroidModule(m, &m.properties) |
| 246 | // } |
| 247 | // |
| 248 | // func (m *myModule) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) { |
| 249 | // // Get the CPU architecture for the current build variant. |
| 250 | // variantArch := ctx.Arch() |
| 251 | // |
| 252 | // // ... |
| 253 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 254 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 255 | // Putting the curiously recurring thing pointing to the thing that contains |
| 256 | // the thing pattern to good use. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 257 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 258 | |
| 259 | commonProperties commonProperties |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 260 | variableProperties variableProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 261 | hostAndDeviceProperties hostAndDeviceProperties |
| 262 | generalProperties []interface{} |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 263 | archProperties []interface{} |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 264 | customizableProperties []interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 265 | |
| 266 | noAddressSanitizer bool |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 267 | installFiles Paths |
| 268 | checkbuildFiles Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 269 | |
| 270 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 271 | // Only set on the final variant of each module |
| 272 | installTarget string |
| 273 | checkbuildTarget string |
| 274 | blueprintDir string |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 275 | |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 276 | hooks hooks |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 279 | func (a *ModuleBase) base() *ModuleBase { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 280 | return a |
| 281 | } |
| 282 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 283 | func (a *ModuleBase) SetTarget(target Target, primary bool) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 284 | a.commonProperties.CompileTarget = target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 285 | a.commonProperties.CompilePrimary = primary |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 288 | func (a *ModuleBase) Target() Target { |
| 289 | return a.commonProperties.CompileTarget |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 292 | func (a *ModuleBase) TargetPrimary() bool { |
| 293 | return a.commonProperties.CompilePrimary |
| 294 | } |
| 295 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 296 | func (a *ModuleBase) Os() OsType { |
| 297 | return a.Target().Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 300 | func (a *ModuleBase) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 301 | return a.Os().Class == Host || a.Os().Class == HostCross |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 304 | func (a *ModuleBase) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 305 | return a.Target().Arch |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 308 | func (a *ModuleBase) OsClassSupported() []OsClass { |
| 309 | switch a.commonProperties.HostOrDeviceSupported { |
| 310 | case HostSupported: |
| 311 | // TODO(ccross): explicitly mark host cross support |
| 312 | return []OsClass{Host, HostCross} |
| 313 | case DeviceSupported: |
| 314 | return []OsClass{Device} |
| 315 | case HostAndDeviceSupported: |
| 316 | var supported []OsClass |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 317 | if Bool(a.hostAndDeviceProperties.Host_supported) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 318 | supported = append(supported, Host, HostCross) |
| 319 | } |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 320 | if Bool(a.hostAndDeviceProperties.Device_supported) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 321 | supported = append(supported, Device) |
| 322 | } |
| 323 | return supported |
| 324 | default: |
| 325 | return nil |
| 326 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 327 | } |
| 328 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 329 | func (a *ModuleBase) DeviceSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 330 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 331 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 332 | Bool(a.hostAndDeviceProperties.Device_supported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 333 | } |
| 334 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 335 | func (a *ModuleBase) Enabled() bool { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 336 | if a.commonProperties.Enabled == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 337 | return a.Os().Class != HostCross |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 338 | } |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 339 | return *a.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 342 | func (a *ModuleBase) computeInstallDeps( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 343 | ctx blueprint.ModuleContext) Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 344 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 345 | result := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 346 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 347 | func(m blueprint.Module) { |
| 348 | fileInstaller := m.(fileInstaller) |
| 349 | files := fileInstaller.filesToInstall() |
| 350 | result = append(result, files...) |
| 351 | }) |
| 352 | |
| 353 | return result |
| 354 | } |
| 355 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 356 | func (a *ModuleBase) filesToInstall() Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 357 | return a.installFiles |
| 358 | } |
| 359 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 360 | func (p *ModuleBase) NoAddressSanitizer() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 361 | return p.noAddressSanitizer |
| 362 | } |
| 363 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 364 | func (p *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 365 | return false |
| 366 | } |
| 367 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 368 | func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
| 369 | if a != ctx.FinalModule().(Module).base() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 370 | return |
| 371 | } |
| 372 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 373 | allInstalledFiles := Paths{} |
| 374 | allCheckbuildFiles := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 375 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 376 | a := module.(Module).base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 377 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 378 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 379 | }) |
| 380 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 381 | deps := []string{} |
| 382 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 383 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 384 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 385 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 386 | Rule: blueprint.Phony, |
| 387 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 388 | Implicits: allInstalledFiles.Strings(), |
Colin Cross | 346aa13 | 2015-12-17 17:19:51 -0800 | [diff] [blame] | 389 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 390 | }) |
| 391 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 392 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | if len(allCheckbuildFiles) > 0 { |
| 396 | name := ctx.ModuleName() + "-checkbuild" |
| 397 | ctx.Build(pctx, blueprint.BuildParams{ |
| 398 | Rule: blueprint.Phony, |
| 399 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 400 | Implicits: allCheckbuildFiles.Strings(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 401 | Optional: true, |
| 402 | }) |
| 403 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 404 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 408 | suffix := "" |
| 409 | if ctx.Config().(Config).EmbeddedInMake() { |
| 410 | suffix = "-soong" |
| 411 | } |
| 412 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 413 | ctx.Build(pctx, blueprint.BuildParams{ |
| 414 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 415 | Outputs: []string{ctx.ModuleName() + suffix}, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 416 | Implicits: deps, |
| 417 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 418 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 419 | |
| 420 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 424 | func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 425 | return androidBaseContextImpl{ |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 426 | target: a.commonProperties.CompileTarget, |
| 427 | targetPrimary: a.commonProperties.CompilePrimary, |
| 428 | config: ctx.Config().(Config), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 429 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 432 | func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 433 | androidCtx := &androidModuleContext{ |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 434 | module: a.module, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 435 | ModuleContext: ctx, |
| 436 | androidBaseContextImpl: a.androidBaseContextFactory(ctx), |
| 437 | installDeps: a.computeInstallDeps(ctx), |
| 438 | installFiles: a.installFiles, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 439 | missingDeps: ctx.GetMissingDependencies(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 442 | if !a.Enabled() { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 443 | return |
| 444 | } |
| 445 | |
| 446 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 447 | if ctx.Failed() { |
| 448 | return |
| 449 | } |
| 450 | |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 451 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 452 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
| 453 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 454 | a.generateModuleTarget(ctx) |
| 455 | if ctx.Failed() { |
| 456 | return |
| 457 | } |
| 458 | } |
| 459 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 460 | type androidBaseContextImpl struct { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 461 | target Target |
| 462 | targetPrimary bool |
| 463 | debug bool |
| 464 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 467 | type androidModuleContext struct { |
| 468 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 469 | androidBaseContextImpl |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 470 | installDeps Paths |
| 471 | installFiles Paths |
| 472 | checkbuildFiles Paths |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 473 | missingDeps []string |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 474 | module Module |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | func (a *androidModuleContext) ninjaError(outputs []string, err error) { |
| 478 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
| 479 | Rule: ErrorRule, |
| 480 | Outputs: outputs, |
| 481 | Optional: true, |
| 482 | Args: map[string]string{ |
| 483 | "error": err.Error(), |
| 484 | }, |
| 485 | }) |
| 486 | return |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 487 | } |
| 488 | |
Dan Willemsen | 14e5c2a | 2015-11-30 13:59:34 -0800 | [diff] [blame] | 489 | func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params blueprint.BuildParams) { |
Colin Cross | e2c4874 | 2016-04-27 13:47:35 -0700 | [diff] [blame] | 490 | if a.missingDeps != nil && params.Rule != globRule { |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 491 | a.ninjaError(params.Outputs, fmt.Errorf("module %s missing dependencies: %s\n", |
| 492 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
| 493 | return |
| 494 | } |
| 495 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 496 | params.Optional = true |
| 497 | a.ModuleContext.Build(pctx, params) |
| 498 | } |
| 499 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 500 | func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) { |
| 501 | bparams := blueprint.BuildParams{ |
| 502 | Rule: params.Rule, |
| 503 | Outputs: params.Outputs.Strings(), |
| 504 | Inputs: params.Inputs.Strings(), |
| 505 | Implicits: params.Implicits.Strings(), |
| 506 | OrderOnly: params.OrderOnly.Strings(), |
| 507 | Args: params.Args, |
| 508 | Optional: !params.Default, |
| 509 | } |
| 510 | |
| 511 | if params.Output != nil { |
| 512 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 513 | } |
| 514 | if params.Input != nil { |
| 515 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 516 | } |
| 517 | if params.Implicit != nil { |
| 518 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 519 | } |
| 520 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 521 | if a.missingDeps != nil { |
| 522 | a.ninjaError(bparams.Outputs, fmt.Errorf("module %s missing dependencies: %s\n", |
| 523 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
| 524 | return |
| 525 | } |
| 526 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 527 | a.ModuleContext.Build(pctx, bparams) |
| 528 | } |
| 529 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 530 | func (a *androidModuleContext) GetMissingDependencies() []string { |
| 531 | return a.missingDeps |
| 532 | } |
| 533 | |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 534 | func (a *androidModuleContext) AddMissingDependencies(deps []string) { |
| 535 | if deps != nil { |
| 536 | a.missingDeps = append(a.missingDeps, deps...) |
| 537 | } |
| 538 | } |
| 539 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 540 | func (a *androidBaseContextImpl) Target() Target { |
| 541 | return a.target |
| 542 | } |
| 543 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 544 | func (a *androidBaseContextImpl) TargetPrimary() bool { |
| 545 | return a.targetPrimary |
| 546 | } |
| 547 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 548 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 549 | return a.target.Arch |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 552 | func (a *androidBaseContextImpl) Os() OsType { |
| 553 | return a.target.Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 556 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 557 | return a.target.Os.Class == Host || a.target.Os.Class == HostCross |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 561 | return a.target.Os.Class == Device |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 564 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 565 | return a.target.Os == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 568 | func (a *androidBaseContextImpl) Debug() bool { |
| 569 | return a.debug |
| 570 | } |
| 571 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 572 | func (a *androidBaseContextImpl) PrimaryArch() bool { |
| 573 | return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType |
| 574 | } |
| 575 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 576 | func (a *androidBaseContextImpl) AConfig() Config { |
| 577 | return a.config |
| 578 | } |
| 579 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 580 | func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig { |
| 581 | return DeviceConfig{a.config.deviceConfig} |
| 582 | } |
| 583 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 584 | func (a *androidModuleContext) Proprietary() bool { |
| 585 | return a.module.base().commonProperties.Proprietary |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 588 | func (a *androidModuleContext) InstallInData() bool { |
| 589 | return a.module.InstallInData() |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | func (a *androidModuleContext) InstallFileName(installPath OutputPath, name string, srcPath Path, |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 593 | deps ...Path) OutputPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 594 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 595 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 596 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, false) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 597 | |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 598 | if a.Host() || !a.AConfig().SkipDeviceInstall() { |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 599 | deps = append(deps, a.installDeps...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 600 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 601 | a.ModuleBuild(pctx, ModuleBuildParams{ |
| 602 | Rule: Cp, |
| 603 | Output: fullInstallPath, |
| 604 | Input: srcPath, |
| 605 | OrderOnly: Paths(deps), |
Dan Willemsen | 7f730fd | 2016-01-14 11:22:23 -0800 | [diff] [blame] | 606 | Default: !a.AConfig().EmbeddedInMake(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 607 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 608 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 609 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 610 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 611 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 612 | return fullInstallPath |
| 613 | } |
| 614 | |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 615 | func (a *androidModuleContext) InstallFile(installPath OutputPath, srcPath Path, deps ...Path) OutputPath { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 616 | return a.InstallFileName(installPath, filepath.Base(srcPath.String()), srcPath, deps...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 619 | func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath { |
| 620 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 621 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, true) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 622 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 623 | if a.Host() || !a.AConfig().SkipDeviceInstall() { |
| 624 | a.ModuleBuild(pctx, ModuleBuildParams{ |
| 625 | Rule: Symlink, |
| 626 | Output: fullInstallPath, |
| 627 | OrderOnly: Paths{srcPath}, |
| 628 | Default: !a.AConfig().EmbeddedInMake(), |
| 629 | Args: map[string]string{ |
| 630 | "fromPath": srcPath.String(), |
| 631 | }, |
| 632 | }) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 633 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 634 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 635 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 636 | } |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 637 | return fullInstallPath |
| 638 | } |
| 639 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 640 | func (a *androidModuleContext) CheckbuildFile(srcPath Path) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 641 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 642 | } |
| 643 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 644 | type fileInstaller interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 645 | filesToInstall() Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | func isFileInstaller(m blueprint.Module) bool { |
| 649 | _, ok := m.(fileInstaller) |
| 650 | return ok |
| 651 | } |
| 652 | |
| 653 | func isAndroidModule(m blueprint.Module) bool { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 654 | _, ok := m.(Module) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 655 | return ok |
| 656 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 657 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 658 | func findStringInSlice(str string, slice []string) int { |
| 659 | for i, s := range slice { |
| 660 | if s == str { |
| 661 | return i |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 664 | return -1 |
| 665 | } |
| 666 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 667 | func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { |
| 668 | prefix := PathForModuleSrc(ctx).String() |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 669 | for i, e := range excludes { |
| 670 | j := findStringInSlice(e, srcFiles) |
| 671 | if j != -1 { |
| 672 | srcFiles = append(srcFiles[:j], srcFiles[j+1:]...) |
| 673 | } |
| 674 | |
| 675 | excludes[i] = filepath.Join(prefix, e) |
| 676 | } |
| 677 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 678 | globbedSrcFiles := make(Paths, 0, len(srcFiles)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 679 | for _, s := range srcFiles { |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 680 | if glob.IsGlob(s) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 681 | globbedSrcFiles = append(globbedSrcFiles, ctx.Glob("src_glob", filepath.Join(prefix, s), excludes)...) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 682 | } else { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 683 | globbedSrcFiles = append(globbedSrcFiles, PathForModuleSrc(ctx, s)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 684 | } |
| 685 | } |
| 686 | |
| 687 | return globbedSrcFiles |
| 688 | } |
| 689 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 690 | func (ctx *androidModuleContext) Glob(outDir, globPattern string, excludes []string) Paths { |
| 691 | ret, err := Glob(ctx, PathForModuleOut(ctx, outDir).String(), globPattern, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 692 | if err != nil { |
| 693 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 694 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 695 | return pathsForModuleSrcFromFullPath(ctx, ret) |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 696 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 697 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 698 | func init() { |
| 699 | soong.RegisterSingletonType("buildtarget", BuildTargetSingleton) |
| 700 | } |
| 701 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 702 | func BuildTargetSingleton() blueprint.Singleton { |
| 703 | return &buildTargetSingleton{} |
| 704 | } |
| 705 | |
| 706 | type buildTargetSingleton struct{} |
| 707 | |
| 708 | func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 709 | checkbuildDeps := []string{} |
| 710 | |
| 711 | dirModules := make(map[string][]string) |
| 712 | |
| 713 | ctx.VisitAllModules(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 714 | if a, ok := module.(Module); ok { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 715 | blueprintDir := a.base().blueprintDir |
| 716 | installTarget := a.base().installTarget |
| 717 | checkbuildTarget := a.base().checkbuildTarget |
| 718 | |
| 719 | if checkbuildTarget != "" { |
| 720 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
| 721 | dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget) |
| 722 | } |
| 723 | |
| 724 | if installTarget != "" { |
| 725 | dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget) |
| 726 | } |
| 727 | } |
| 728 | }) |
| 729 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 730 | suffix := "" |
| 731 | if ctx.Config().(Config).EmbeddedInMake() { |
| 732 | suffix = "-soong" |
| 733 | } |
| 734 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 735 | // Create a top-level checkbuild target that depends on all modules |
| 736 | ctx.Build(pctx, blueprint.BuildParams{ |
| 737 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 738 | Outputs: []string{"checkbuild" + suffix}, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 739 | Implicits: checkbuildDeps, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 740 | Optional: true, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 741 | }) |
| 742 | |
| 743 | // Create a mm/<directory> target that depends on all modules in a directory |
| 744 | dirs := sortedKeys(dirModules) |
| 745 | for _, dir := range dirs { |
| 746 | ctx.Build(pctx, blueprint.BuildParams{ |
| 747 | Rule: blueprint.Phony, |
| 748 | Outputs: []string{filepath.Join("mm", dir)}, |
| 749 | Implicits: dirModules[dir], |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 750 | // HACK: checkbuild should be an optional build, but force it |
| 751 | // enabled for now in standalone builds |
Colin Cross | 1604ecf | 2015-12-17 16:33:43 -0800 | [diff] [blame] | 752 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 753 | }) |
| 754 | } |
| 755 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 756 | |
| 757 | type AndroidModulesByName struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 758 | slice []Module |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 759 | ctx interface { |
| 760 | ModuleName(blueprint.Module) string |
| 761 | ModuleSubDir(blueprint.Module) string |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | func (s AndroidModulesByName) Len() int { return len(s.slice) } |
| 766 | func (s AndroidModulesByName) Less(i, j int) bool { |
| 767 | mi, mj := s.slice[i], s.slice[j] |
| 768 | ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj) |
| 769 | |
| 770 | if ni != nj { |
| 771 | return ni < nj |
| 772 | } else { |
| 773 | return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj) |
| 774 | } |
| 775 | } |
| 776 | func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] } |