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