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