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