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