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 | |
| 22 | "github.com/google/blueprint" |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/pathtools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | var ( |
| 27 | DeviceSharedLibrary = "shared_library" |
| 28 | DeviceStaticLibrary = "static_library" |
| 29 | DeviceExecutable = "executable" |
| 30 | HostSharedLibrary = "host_shared_library" |
| 31 | HostStaticLibrary = "host_static_library" |
| 32 | HostExecutable = "host_executable" |
| 33 | ) |
| 34 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 35 | type BuildParams struct { |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 36 | Rule blueprint.Rule |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 37 | Deps blueprint.Deps |
| 38 | Depfile WritablePath |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 39 | Description string |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 40 | Output WritablePath |
| 41 | Outputs WritablePaths |
| 42 | ImplicitOutput WritablePath |
| 43 | ImplicitOutputs WritablePaths |
| 44 | Input Path |
| 45 | Inputs Paths |
| 46 | Implicit Path |
| 47 | Implicits Paths |
| 48 | OrderOnly Paths |
| 49 | Default bool |
| 50 | Args map[string]string |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 53 | type ModuleBuildParams BuildParams |
| 54 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 55 | type androidBaseContext interface { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 56 | Target() Target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 57 | TargetPrimary() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 58 | Arch() Arch |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 59 | Os() OsType |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 60 | Host() bool |
| 61 | Device() bool |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 62 | Darwin() bool |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 63 | Windows() bool |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 64 | Debug() bool |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 65 | PrimaryArch() bool |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 66 | InstallOnVendorPartition() bool |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 67 | AConfig() Config |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 68 | DeviceConfig() DeviceConfig |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 71 | type BaseContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 72 | blueprint.BaseModuleContext |
| 73 | androidBaseContext |
| 74 | } |
| 75 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 76 | type ModuleContext interface { |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 77 | androidBaseContext |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 78 | blueprint.BaseModuleContext |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 79 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 80 | // Deprecated: use ModuleContext.Build instead. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 81 | ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 82 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 83 | ExpandSources(srcFiles, excludes []string) Paths |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 84 | ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 85 | Glob(globPattern string, excludes []string) Paths |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 86 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 87 | InstallExecutable(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
| 88 | InstallFile(installPath OutputPath, name string, srcPath Path, deps ...Path) OutputPath |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 89 | InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 90 | CheckbuildFile(srcPath Path) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 91 | |
| 92 | AddMissingDependencies(deps []string) |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 93 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 94 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 95 | InstallInSanitizerDir() bool |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 96 | |
| 97 | RequiredModuleNames() []string |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 98 | |
| 99 | // android.ModuleContext methods |
| 100 | // These are duplicated instead of embedded so that can eventually be wrapped to take an |
| 101 | // android.Module instead of a blueprint.Module |
| 102 | OtherModuleName(m blueprint.Module) string |
| 103 | OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) |
| 104 | OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag |
| 105 | |
| 106 | GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module |
| 107 | GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) |
| 108 | |
| 109 | ModuleSubDir() string |
| 110 | |
Colin Cross | 35143d0 | 2017-11-16 00:11:20 -0800 | [diff] [blame^] | 111 | VisitDirectDepsBlueprint(visit func(blueprint.Module)) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 112 | VisitDirectDeps(visit func(Module)) |
| 113 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 114 | VisitDepsDepthFirst(visit func(Module)) |
| 115 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
| 116 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 117 | |
| 118 | Variable(pctx blueprint.PackageContext, name, value string) |
| 119 | Rule(pctx blueprint.PackageContext, name string, params blueprint.RuleParams, argNames ...string) blueprint.Rule |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 120 | // Similar to blueprint.ModuleContext.Build, but takes Paths instead of []string, |
| 121 | // and performs more verification. |
| 122 | Build(pctx blueprint.PackageContext, params BuildParams) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 123 | |
| 124 | PrimaryModule() blueprint.Module |
| 125 | FinalModule() blueprint.Module |
| 126 | VisitAllModuleVariants(visit func(blueprint.Module)) |
| 127 | |
| 128 | GetMissingDependencies() []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 131 | type Module interface { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 132 | blueprint.Module |
| 133 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 134 | // GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions, |
| 135 | // but GenerateAndroidBuildActions also has access to Android-specific information. |
| 136 | // For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 137 | GenerateAndroidBuildActions(ModuleContext) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 138 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 139 | DepsMutator(BottomUpMutatorContext) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 140 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 141 | base() *ModuleBase |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 142 | Enabled() bool |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 143 | Target() Target |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 144 | InstallInData() bool |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 145 | InstallInSanitizerDir() bool |
Colin Cross | a2f296f | 2016-11-29 15:16:18 -0800 | [diff] [blame] | 146 | SkipInstall() |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 147 | |
| 148 | AddProperties(props ...interface{}) |
| 149 | GetProperties() []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 150 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 151 | BuildParamsForTests() []BuildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 154 | type nameProperties struct { |
| 155 | // The name of the module. Must be unique across all modules. |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 156 | Name *string |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | type commonProperties struct { |
Colin Cross | c77f9d1 | 2015-04-02 13:54:39 -0700 | [diff] [blame] | 160 | Tags []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 161 | |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 162 | // emit build rules for this module |
| 163 | Enabled *bool `android:"arch_variant"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 164 | |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 165 | // 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] | 166 | // are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both |
| 167 | // architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit |
| 168 | // platform |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 169 | Compile_multilib *string `android:"arch_variant"` |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 170 | |
| 171 | Target struct { |
| 172 | Host struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 173 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 174 | } |
| 175 | Android struct { |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 176 | Compile_multilib *string |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | Default_multilib string `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 181 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 182 | // whether this is a proprietary vendor module, and should be installed into /vendor |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 183 | Proprietary *bool |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 184 | |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 185 | // vendor who owns this module |
Dan Willemsen | efac4a8 | 2017-07-18 19:42:09 -0700 | [diff] [blame] | 186 | Owner *string |
Colin Cross | 55708f3 | 2017-03-20 13:23:34 -0700 | [diff] [blame] | 187 | |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 188 | // whether this module is device specific and should be installed into /vendor |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 189 | Vendor *bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 190 | |
Dan Willemsen | 0fda89f | 2016-06-01 15:25:32 -0700 | [diff] [blame] | 191 | // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags |
| 192 | // file |
| 193 | Logtags []string |
| 194 | |
Dan Willemsen | 2277bcb | 2016-07-25 20:27:39 -0700 | [diff] [blame] | 195 | // init.rc files to be installed if this module is installed |
| 196 | Init_rc []string |
| 197 | |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 198 | // names of other modules to install if this module is installed |
Colin Cross | c602b7d | 2017-05-05 13:36:36 -0700 | [diff] [blame] | 199 | Required []string `android:"arch_variant"` |
Chris Wolfe | 998306e | 2016-08-15 14:47:23 -0400 | [diff] [blame] | 200 | |
Colin Cross | 5aac362 | 2017-08-31 15:07:09 -0700 | [diff] [blame] | 201 | // relative path to a file to include in the list of notices for the device |
| 202 | Notice *string |
| 203 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 204 | // Set by TargetMutator |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 205 | CompileTarget Target `blueprint:"mutated"` |
| 206 | CompilePrimary bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 207 | |
| 208 | // Set by InitAndroidModule |
| 209 | HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 210 | ArchSpecific bool `blueprint:"mutated"` |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 211 | |
| 212 | SkipInstall bool `blueprint:"mutated"` |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | type hostAndDeviceProperties struct { |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 216 | Host_supported *bool |
| 217 | Device_supported *bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 220 | type Multilib string |
| 221 | |
| 222 | const ( |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 223 | MultilibBoth Multilib = "both" |
| 224 | MultilibFirst Multilib = "first" |
| 225 | MultilibCommon Multilib = "common" |
| 226 | MultilibDefault Multilib = "" |
Colin Cross | c472d57 | 2015-03-17 15:06:21 -0700 | [diff] [blame] | 227 | ) |
| 228 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 229 | type HostOrDeviceSupported int |
| 230 | |
| 231 | const ( |
| 232 | _ HostOrDeviceSupported = iota |
| 233 | HostSupported |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 234 | HostSupportedNoCross |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 235 | DeviceSupported |
| 236 | HostAndDeviceSupported |
| 237 | HostAndDeviceDefault |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 238 | NeitherHostNorDeviceSupported |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 239 | ) |
| 240 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 241 | func InitAndroidModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 242 | base := m.base() |
| 243 | base.module = m |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 244 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 245 | m.AddProperties( |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 246 | &base.nameProperties, |
| 247 | &base.commonProperties, |
| 248 | &base.variableProperties) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 251 | func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { |
| 252 | InitAndroidModule(m) |
Colin Cross | 5049f02 | 2015-03-18 13:28:46 -0700 | [diff] [blame] | 253 | |
| 254 | base := m.base() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 255 | base.commonProperties.HostOrDeviceSupported = hod |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 256 | base.commonProperties.Default_multilib = string(defaultMultilib) |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 257 | base.commonProperties.ArchSpecific = true |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 258 | |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 259 | switch hod { |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 260 | case HostAndDeviceSupported, HostAndDeviceDefault: |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 261 | m.AddProperties(&base.hostAndDeviceProperties) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 264 | InitArchModule(m) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 267 | // A ModuleBase object contains the properties that are common to all Android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 268 | // modules. It should be included as an anonymous field in every module |
| 269 | // struct definition. InitAndroidModule should then be called from the module's |
| 270 | // factory function, and the return values from InitAndroidModule should be |
| 271 | // returned from the factory function. |
| 272 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 273 | // The ModuleBase type is responsible for implementing the GenerateBuildActions |
| 274 | // method to support the blueprint.Module interface. This method will then call |
| 275 | // the module's GenerateAndroidBuildActions method once for each build variant |
| 276 | // that is to be built. GenerateAndroidBuildActions is passed a |
| 277 | // AndroidModuleContext rather than the usual blueprint.ModuleContext. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 278 | // AndroidModuleContext exposes extra functionality specific to the Android build |
| 279 | // system including details about the particular build variant that is to be |
| 280 | // generated. |
| 281 | // |
| 282 | // For example: |
| 283 | // |
| 284 | // import ( |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 285 | // "android/soong/android" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 286 | // ) |
| 287 | // |
| 288 | // type myModule struct { |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 289 | // android.ModuleBase |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 290 | // properties struct { |
| 291 | // MyProperty string |
| 292 | // } |
| 293 | // } |
| 294 | // |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 295 | // func NewMyModule() android.Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 296 | // m := &myModule{} |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 297 | // m.AddProperties(&m.properties) |
| 298 | // android.InitAndroidModule(m) |
| 299 | // return m |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 300 | // } |
| 301 | // |
Nan Zhang | b9eeb1d | 2017-02-02 10:46:07 -0800 | [diff] [blame] | 302 | // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 303 | // // Get the CPU architecture for the current build variant. |
| 304 | // variantArch := ctx.Arch() |
| 305 | // |
| 306 | // // ... |
| 307 | // } |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 308 | type ModuleBase struct { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 309 | // Putting the curiously recurring thing pointing to the thing that contains |
| 310 | // the thing pattern to good use. |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 311 | // TODO: remove this |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 312 | module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 313 | |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 314 | nameProperties nameProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 315 | commonProperties commonProperties |
Colin Cross | 7f64b6d | 2015-07-09 13:57:48 -0700 | [diff] [blame] | 316 | variableProperties variableProperties |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 317 | hostAndDeviceProperties hostAndDeviceProperties |
| 318 | generalProperties []interface{} |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 319 | archProperties []interface{} |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 320 | customizableProperties []interface{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 321 | |
| 322 | noAddressSanitizer bool |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 323 | installFiles Paths |
| 324 | checkbuildFiles Paths |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 325 | |
| 326 | // Used by buildTargetSingleton to create checkbuild and per-directory build targets |
| 327 | // Only set on the final variant of each module |
| 328 | installTarget string |
| 329 | checkbuildTarget string |
| 330 | blueprintDir string |
Colin Cross | a120ec1 | 2016-08-19 16:07:38 -0700 | [diff] [blame] | 331 | |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 332 | hooks hooks |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 333 | |
| 334 | registerProps []interface{} |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 335 | |
| 336 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 337 | buildParams []BuildParams |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | func (a *ModuleBase) AddProperties(props ...interface{}) { |
| 341 | a.registerProps = append(a.registerProps, props...) |
| 342 | } |
| 343 | |
| 344 | func (a *ModuleBase) GetProperties() []interface{} { |
| 345 | return a.registerProps |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 348 | func (a *ModuleBase) BuildParamsForTests() []BuildParams { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 349 | return a.buildParams |
| 350 | } |
| 351 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 352 | // Name returns the name of the module. It may be overridden by individual module types, for |
| 353 | // example prebuilts will prepend prebuilt_ to the name. |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 354 | func (a *ModuleBase) Name() string { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 355 | return String(a.nameProperties.Name) |
Colin Cross | fc75458 | 2016-05-17 16:34:16 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 358 | // BaseModuleName returns the name of the module as specified in the blueprints file. |
| 359 | func (a *ModuleBase) BaseModuleName() string { |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 360 | return String(a.nameProperties.Name) |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 363 | func (a *ModuleBase) base() *ModuleBase { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 364 | return a |
| 365 | } |
| 366 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 367 | func (a *ModuleBase) SetTarget(target Target, primary bool) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 368 | a.commonProperties.CompileTarget = target |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 369 | a.commonProperties.CompilePrimary = primary |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 372 | func (a *ModuleBase) Target() Target { |
| 373 | return a.commonProperties.CompileTarget |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 376 | func (a *ModuleBase) TargetPrimary() bool { |
| 377 | return a.commonProperties.CompilePrimary |
| 378 | } |
| 379 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 380 | func (a *ModuleBase) Os() OsType { |
| 381 | return a.Target().Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 384 | func (a *ModuleBase) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 385 | return a.Os().Class == Host || a.Os().Class == HostCross |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 388 | func (a *ModuleBase) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 389 | return a.Target().Arch |
Dan Willemsen | 9775052 | 2016-02-09 17:43:51 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Dan Willemsen | 0b24c74 | 2016-10-04 15:13:37 -0700 | [diff] [blame] | 392 | func (a *ModuleBase) ArchSpecific() bool { |
| 393 | return a.commonProperties.ArchSpecific |
| 394 | } |
| 395 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 396 | func (a *ModuleBase) OsClassSupported() []OsClass { |
| 397 | switch a.commonProperties.HostOrDeviceSupported { |
| 398 | case HostSupported: |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 399 | return []OsClass{Host, HostCross} |
Dan Albert | c6345fb | 2016-10-20 01:36:11 -0700 | [diff] [blame] | 400 | case HostSupportedNoCross: |
| 401 | return []OsClass{Host} |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 402 | case DeviceSupported: |
| 403 | return []OsClass{Device} |
| 404 | case HostAndDeviceSupported: |
| 405 | var supported []OsClass |
Colin Cross | a4190c1 | 2016-07-12 13:11:25 -0700 | [diff] [blame] | 406 | if Bool(a.hostAndDeviceProperties.Host_supported) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 407 | supported = append(supported, Host, HostCross) |
| 408 | } |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 409 | if a.hostAndDeviceProperties.Device_supported == nil || |
| 410 | *a.hostAndDeviceProperties.Device_supported { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 411 | supported = append(supported, Device) |
| 412 | } |
| 413 | return supported |
| 414 | default: |
| 415 | return nil |
| 416 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 419 | func (a *ModuleBase) DeviceSupported() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 420 | return a.commonProperties.HostOrDeviceSupported == DeviceSupported || |
| 421 | a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && |
Nan Zhang | 1a0f09b | 2017-07-05 10:35:11 -0700 | [diff] [blame] | 422 | (a.hostAndDeviceProperties.Device_supported == nil || |
| 423 | *a.hostAndDeviceProperties.Device_supported) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 424 | } |
| 425 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 426 | func (a *ModuleBase) Enabled() bool { |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 427 | if a.commonProperties.Enabled == nil { |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 428 | return !a.Os().DefaultDisabled |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 429 | } |
Dan Willemsen | 0effe06 | 2015-11-30 16:06:01 -0800 | [diff] [blame] | 430 | return *a.commonProperties.Enabled |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 431 | } |
| 432 | |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 433 | func (a *ModuleBase) SkipInstall() { |
| 434 | a.commonProperties.SkipInstall = true |
| 435 | } |
| 436 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 437 | func (a *ModuleBase) computeInstallDeps( |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 438 | ctx blueprint.ModuleContext) Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 439 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 440 | result := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 441 | ctx.VisitDepsDepthFirstIf(isFileInstaller, |
| 442 | func(m blueprint.Module) { |
| 443 | fileInstaller := m.(fileInstaller) |
| 444 | files := fileInstaller.filesToInstall() |
| 445 | result = append(result, files...) |
| 446 | }) |
| 447 | |
| 448 | return result |
| 449 | } |
| 450 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 451 | func (a *ModuleBase) filesToInstall() Paths { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 452 | return a.installFiles |
| 453 | } |
| 454 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 455 | func (p *ModuleBase) NoAddressSanitizer() bool { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 456 | return p.noAddressSanitizer |
| 457 | } |
| 458 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 459 | func (p *ModuleBase) InstallInData() bool { |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 460 | return false |
| 461 | } |
| 462 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 463 | func (p *ModuleBase) InstallInSanitizerDir() bool { |
| 464 | return false |
| 465 | } |
| 466 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 467 | func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 468 | allInstalledFiles := Paths{} |
| 469 | allCheckbuildFiles := Paths{} |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 470 | ctx.VisitAllModuleVariants(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 471 | a := module.(Module).base() |
Colin Cross | c940435 | 2015-03-26 16:10:12 -0700 | [diff] [blame] | 472 | allInstalledFiles = append(allInstalledFiles, a.installFiles...) |
| 473 | allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 474 | }) |
| 475 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 476 | deps := []string{} |
| 477 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 478 | if len(allInstalledFiles) > 0 { |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 479 | name := ctx.ModuleName() + "-install" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 480 | ctx.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 481 | Rule: blueprint.Phony, |
| 482 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 483 | Implicits: allInstalledFiles.Strings(), |
Colin Cross | 346aa13 | 2015-12-17 17:19:51 -0800 | [diff] [blame] | 484 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 485 | }) |
| 486 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 487 | a.installTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | if len(allCheckbuildFiles) > 0 { |
| 491 | name := ctx.ModuleName() + "-checkbuild" |
| 492 | ctx.Build(pctx, blueprint.BuildParams{ |
| 493 | Rule: blueprint.Phony, |
| 494 | Outputs: []string{name}, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 495 | Implicits: allCheckbuildFiles.Strings(), |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 496 | Optional: true, |
| 497 | }) |
| 498 | deps = append(deps, name) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 499 | a.checkbuildTarget = name |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | if len(deps) > 0 { |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 503 | suffix := "" |
| 504 | if ctx.Config().(Config).EmbeddedInMake() { |
| 505 | suffix = "-soong" |
| 506 | } |
| 507 | |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 508 | ctx.Build(pctx, blueprint.BuildParams{ |
| 509 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 510 | Outputs: []string{ctx.ModuleName() + suffix}, |
Colin Cross | 9454bfa | 2015-03-17 13:24:18 -0700 | [diff] [blame] | 511 | Implicits: deps, |
| 512 | Optional: true, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 513 | }) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 514 | |
| 515 | a.blueprintDir = ctx.ModuleDir() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 519 | func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 520 | return androidBaseContextImpl{ |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 521 | target: a.commonProperties.CompileTarget, |
| 522 | targetPrimary: a.commonProperties.CompilePrimary, |
Colin Cross | 7d716ba | 2017-11-01 10:38:29 -0700 | [diff] [blame] | 523 | vendor: Bool(a.commonProperties.Proprietary) || Bool(a.commonProperties.Vendor), |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 524 | config: ctx.Config().(Config), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 525 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 528 | func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 529 | androidCtx := &androidModuleContext{ |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 530 | module: a.module, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 531 | ModuleContext: ctx, |
| 532 | androidBaseContextImpl: a.androidBaseContextFactory(ctx), |
| 533 | installDeps: a.computeInstallDeps(ctx), |
| 534 | installFiles: a.installFiles, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 535 | missingDeps: ctx.GetMissingDependencies(), |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 536 | } |
| 537 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 538 | desc := "//" + ctx.ModuleDir() + ":" + ctx.ModuleName() + " " |
| 539 | var suffix []string |
| 540 | if androidCtx.Os().Class != Device && androidCtx.Os().Class != Generic { |
| 541 | suffix = append(suffix, androidCtx.Os().String()) |
| 542 | } |
| 543 | if !androidCtx.PrimaryArch() { |
| 544 | suffix = append(suffix, androidCtx.Arch().ArchType.String()) |
| 545 | } |
| 546 | |
| 547 | ctx.Variable(pctx, "moduleDesc", desc) |
| 548 | |
| 549 | s := "" |
| 550 | if len(suffix) > 0 { |
| 551 | s = " [" + strings.Join(suffix, " ") + "]" |
| 552 | } |
| 553 | ctx.Variable(pctx, "moduleDescSuffix", s) |
| 554 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 555 | if a.Enabled() { |
| 556 | a.module.GenerateAndroidBuildActions(androidCtx) |
| 557 | if ctx.Failed() { |
| 558 | return |
| 559 | } |
| 560 | |
| 561 | a.installFiles = append(a.installFiles, androidCtx.installFiles...) |
| 562 | a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Colin Cross | 9b1d13d | 2016-09-19 15:18:11 -0700 | [diff] [blame] | 565 | if a == ctx.FinalModule().(Module).base() { |
| 566 | a.generateModuleTarget(ctx) |
| 567 | if ctx.Failed() { |
| 568 | return |
| 569 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 570 | } |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 571 | |
| 572 | a.buildParams = androidCtx.buildParams |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 573 | } |
| 574 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 575 | type androidBaseContextImpl struct { |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 576 | target Target |
| 577 | targetPrimary bool |
| 578 | debug bool |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 579 | vendor bool |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 580 | config Config |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 583 | type androidModuleContext struct { |
| 584 | blueprint.ModuleContext |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 585 | androidBaseContextImpl |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 586 | installDeps Paths |
| 587 | installFiles Paths |
| 588 | checkbuildFiles Paths |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 589 | missingDeps []string |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 590 | module Module |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 591 | |
| 592 | // For tests |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 593 | buildParams []BuildParams |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 594 | } |
| 595 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 596 | func (a *androidModuleContext) ninjaError(desc string, outputs []string, err error) { |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 597 | a.ModuleContext.Build(pctx, blueprint.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 598 | Rule: ErrorRule, |
| 599 | Description: desc, |
| 600 | Outputs: outputs, |
| 601 | Optional: true, |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 602 | Args: map[string]string{ |
| 603 | "error": err.Error(), |
| 604 | }, |
| 605 | }) |
| 606 | return |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 607 | } |
| 608 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 609 | func (a *androidModuleContext) ModuleBuild(pctx blueprint.PackageContext, params ModuleBuildParams) { |
| 610 | a.Build(pctx, BuildParams(params)) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 613 | func (a *androidModuleContext) Build(pctx blueprint.PackageContext, params BuildParams) { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 614 | if a.config.captureBuild { |
| 615 | a.buildParams = append(a.buildParams, params) |
| 616 | } |
| 617 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 618 | bparams := blueprint.BuildParams{ |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 619 | Rule: params.Rule, |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 620 | Deps: params.Deps, |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 621 | Outputs: params.Outputs.Strings(), |
| 622 | ImplicitOutputs: params.ImplicitOutputs.Strings(), |
| 623 | Inputs: params.Inputs.Strings(), |
| 624 | Implicits: params.Implicits.Strings(), |
| 625 | OrderOnly: params.OrderOnly.Strings(), |
| 626 | Args: params.Args, |
| 627 | Optional: !params.Default, |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 630 | if params.Description != "" { |
| 631 | bparams.Description = "${moduleDesc}" + params.Description + "${moduleDescSuffix}" |
| 632 | } |
| 633 | |
Colin Cross | 33bfb0a | 2016-11-21 17:23:08 -0800 | [diff] [blame] | 634 | if params.Depfile != nil { |
| 635 | bparams.Depfile = params.Depfile.String() |
| 636 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 637 | if params.Output != nil { |
| 638 | bparams.Outputs = append(bparams.Outputs, params.Output.String()) |
| 639 | } |
Dan Willemsen | 9f3c574 | 2016-11-03 14:28:31 -0700 | [diff] [blame] | 640 | if params.ImplicitOutput != nil { |
| 641 | bparams.ImplicitOutputs = append(bparams.ImplicitOutputs, params.ImplicitOutput.String()) |
| 642 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 643 | if params.Input != nil { |
| 644 | bparams.Inputs = append(bparams.Inputs, params.Input.String()) |
| 645 | } |
| 646 | if params.Implicit != nil { |
| 647 | bparams.Implicits = append(bparams.Implicits, params.Implicit.String()) |
| 648 | } |
| 649 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 650 | if a.missingDeps != nil { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 651 | a.ninjaError(bparams.Description, bparams.Outputs, |
| 652 | fmt.Errorf("module %s missing dependencies: %s\n", |
| 653 | a.ModuleName(), strings.Join(a.missingDeps, ", "))) |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 654 | return |
| 655 | } |
| 656 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 657 | a.ModuleContext.Build(pctx, bparams) |
| 658 | } |
| 659 | |
Colin Cross | 6ff5138 | 2015-12-17 16:39:19 -0800 | [diff] [blame] | 660 | func (a *androidModuleContext) GetMissingDependencies() []string { |
| 661 | return a.missingDeps |
| 662 | } |
| 663 | |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 664 | func (a *androidModuleContext) AddMissingDependencies(deps []string) { |
| 665 | if deps != nil { |
| 666 | a.missingDeps = append(a.missingDeps, deps...) |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 667 | a.missingDeps = FirstUniqueStrings(a.missingDeps) |
Dan Willemsen | 6553f5e | 2016-03-10 18:14:25 -0800 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 671 | func (a *androidModuleContext) validateAndroidModule(module blueprint.Module) Module { |
| 672 | aModule, _ := module.(Module) |
| 673 | if aModule == nil { |
| 674 | a.ModuleErrorf("module %q not an android module", a.OtherModuleName(aModule)) |
| 675 | return nil |
| 676 | } |
| 677 | |
| 678 | if !aModule.Enabled() { |
| 679 | if a.AConfig().AllowMissingDependencies() { |
| 680 | a.AddMissingDependencies([]string{a.OtherModuleName(aModule)}) |
| 681 | } else { |
| 682 | a.ModuleErrorf("depends on disabled module %q", a.OtherModuleName(aModule)) |
| 683 | } |
| 684 | return nil |
| 685 | } |
| 686 | |
| 687 | return aModule |
| 688 | } |
| 689 | |
Colin Cross | 35143d0 | 2017-11-16 00:11:20 -0800 | [diff] [blame^] | 690 | func (a *androidModuleContext) VisitDirectDepsBlueprint(visit func(blueprint.Module)) { |
| 691 | a.ModuleContext.VisitDirectDeps(visit) |
| 692 | } |
| 693 | |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 694 | func (a *androidModuleContext) VisitDirectDeps(visit func(Module)) { |
| 695 | a.ModuleContext.VisitDirectDeps(func(module blueprint.Module) { |
| 696 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 697 | visit(aModule) |
| 698 | } |
| 699 | }) |
| 700 | } |
| 701 | |
| 702 | func (a *androidModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 703 | a.ModuleContext.VisitDirectDepsIf( |
| 704 | // pred |
| 705 | func(module blueprint.Module) bool { |
| 706 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 707 | return pred(aModule) |
| 708 | } else { |
| 709 | return false |
| 710 | } |
| 711 | }, |
| 712 | // visit |
| 713 | func(module blueprint.Module) { |
| 714 | visit(module.(Module)) |
| 715 | }) |
| 716 | } |
| 717 | |
| 718 | func (a *androidModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
| 719 | a.ModuleContext.VisitDepsDepthFirst(func(module blueprint.Module) { |
| 720 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 721 | visit(aModule) |
| 722 | } |
| 723 | }) |
| 724 | } |
| 725 | |
| 726 | func (a *androidModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { |
| 727 | a.ModuleContext.VisitDepsDepthFirstIf( |
| 728 | // pred |
| 729 | func(module blueprint.Module) bool { |
| 730 | if aModule := a.validateAndroidModule(module); aModule != nil { |
| 731 | return pred(aModule) |
| 732 | } else { |
| 733 | return false |
| 734 | } |
| 735 | }, |
| 736 | // visit |
| 737 | func(module blueprint.Module) { |
| 738 | visit(module.(Module)) |
| 739 | }) |
| 740 | } |
| 741 | |
| 742 | func (a *androidModuleContext) WalkDeps(visit func(Module, Module) bool) { |
| 743 | a.ModuleContext.WalkDeps(func(child, parent blueprint.Module) bool { |
| 744 | childAndroidModule := a.validateAndroidModule(child) |
| 745 | parentAndroidModule := a.validateAndroidModule(parent) |
| 746 | if childAndroidModule != nil && parentAndroidModule != nil { |
| 747 | return visit(childAndroidModule, parentAndroidModule) |
| 748 | } else { |
| 749 | return false |
| 750 | } |
| 751 | }) |
| 752 | } |
| 753 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 754 | func (a *androidBaseContextImpl) Target() Target { |
| 755 | return a.target |
| 756 | } |
| 757 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 758 | func (a *androidBaseContextImpl) TargetPrimary() bool { |
| 759 | return a.targetPrimary |
| 760 | } |
| 761 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 762 | func (a *androidBaseContextImpl) Arch() Arch { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 763 | return a.target.Arch |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 766 | func (a *androidBaseContextImpl) Os() OsType { |
| 767 | return a.target.Os |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 768 | } |
| 769 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 770 | func (a *androidBaseContextImpl) Host() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 771 | return a.target.Os.Class == Host || a.target.Os.Class == HostCross |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | func (a *androidBaseContextImpl) Device() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 775 | return a.target.Os.Class == Device |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 778 | func (a *androidBaseContextImpl) Darwin() bool { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 779 | return a.target.Os == Darwin |
Colin Cross | 0af4b84 | 2015-04-30 16:36:18 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Colin Cross | 3edeee1 | 2017-04-04 12:59:48 -0700 | [diff] [blame] | 782 | func (a *androidBaseContextImpl) Windows() bool { |
| 783 | return a.target.Os == Windows |
| 784 | } |
| 785 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 786 | func (a *androidBaseContextImpl) Debug() bool { |
| 787 | return a.debug |
| 788 | } |
| 789 | |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 790 | func (a *androidBaseContextImpl) PrimaryArch() bool { |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 791 | if len(a.config.Targets[a.target.Os.Class]) <= 1 { |
| 792 | return true |
| 793 | } |
Colin Cross | 1e7d370 | 2016-08-24 15:25:47 -0700 | [diff] [blame] | 794 | return a.target.Arch.ArchType == a.config.Targets[a.target.Os.Class][0].Arch.ArchType |
| 795 | } |
| 796 | |
Colin Cross | 1332b00 | 2015-04-07 17:11:30 -0700 | [diff] [blame] | 797 | func (a *androidBaseContextImpl) AConfig() Config { |
| 798 | return a.config |
| 799 | } |
| 800 | |
Colin Cross | 9272ade | 2016-08-17 15:24:12 -0700 | [diff] [blame] | 801 | func (a *androidBaseContextImpl) DeviceConfig() DeviceConfig { |
| 802 | return DeviceConfig{a.config.deviceConfig} |
| 803 | } |
| 804 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 805 | func (a *androidBaseContextImpl) InstallOnVendorPartition() bool { |
Dan Willemsen | aa118f9 | 2017-04-06 12:49:58 -0700 | [diff] [blame] | 806 | return a.vendor |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Colin Cross | 8d8f8e2 | 2016-08-03 11:57:50 -0700 | [diff] [blame] | 809 | func (a *androidModuleContext) InstallInData() bool { |
| 810 | return a.module.InstallInData() |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 811 | } |
| 812 | |
Vishwath Mohan | 1dd8839 | 2017-03-29 22:00:18 -0700 | [diff] [blame] | 813 | func (a *androidModuleContext) InstallInSanitizerDir() bool { |
| 814 | return a.module.InstallInSanitizerDir() |
| 815 | } |
| 816 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 817 | func (a *androidModuleContext) skipInstall(fullInstallPath OutputPath) bool { |
| 818 | if a.module.base().commonProperties.SkipInstall { |
| 819 | return true |
| 820 | } |
| 821 | |
| 822 | if a.Device() { |
| 823 | if a.AConfig().SkipDeviceInstall() { |
| 824 | return true |
| 825 | } |
| 826 | |
| 827 | if a.AConfig().SkipMegaDeviceInstall(fullInstallPath.String()) { |
| 828 | return true |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | return false |
| 833 | } |
| 834 | |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 835 | func (a *androidModuleContext) InstallFile(installPath OutputPath, name string, srcPath Path, |
Colin Cross | a234466 | 2016-03-24 13:14:12 -0700 | [diff] [blame] | 836 | deps ...Path) OutputPath { |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 837 | return a.installFile(installPath, name, srcPath, Cp, deps) |
| 838 | } |
| 839 | |
| 840 | func (a *androidModuleContext) InstallExecutable(installPath OutputPath, name string, srcPath Path, |
| 841 | deps ...Path) OutputPath { |
| 842 | return a.installFile(installPath, name, srcPath, CpExecutable, deps) |
| 843 | } |
| 844 | |
| 845 | func (a *androidModuleContext) installFile(installPath OutputPath, name string, srcPath Path, |
| 846 | rule blueprint.Rule, deps []Path) OutputPath { |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 847 | |
Dan Willemsen | 782a2d1 | 2015-12-21 14:55:28 -0800 | [diff] [blame] | 848 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 849 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, false) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 850 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 851 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 852 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 853 | deps = append(deps, a.installDeps...) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 854 | |
Colin Cross | 89562dc | 2016-10-03 17:47:19 -0700 | [diff] [blame] | 855 | var implicitDeps, orderOnlyDeps Paths |
| 856 | |
| 857 | if a.Host() { |
| 858 | // Installed host modules might be used during the build, depend directly on their |
| 859 | // dependencies so their timestamp is updated whenever their dependency is updated |
| 860 | implicitDeps = deps |
| 861 | } else { |
| 862 | orderOnlyDeps = deps |
| 863 | } |
| 864 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 865 | a.Build(pctx, BuildParams{ |
Colin Cross | 5c51792 | 2017-08-31 12:29:17 -0700 | [diff] [blame] | 866 | Rule: rule, |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 867 | Description: "install " + fullInstallPath.Base(), |
| 868 | Output: fullInstallPath, |
| 869 | Input: srcPath, |
| 870 | Implicits: implicitDeps, |
| 871 | OrderOnly: orderOnlyDeps, |
| 872 | Default: !a.AConfig().EmbeddedInMake(), |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 873 | }) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 874 | |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 875 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 876 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 877 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
Colin Cross | 35cec12 | 2015-04-02 14:37:16 -0700 | [diff] [blame] | 878 | return fullInstallPath |
| 879 | } |
| 880 | |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 881 | func (a *androidModuleContext) InstallSymlink(installPath OutputPath, name string, srcPath OutputPath) OutputPath { |
| 882 | fullInstallPath := installPath.Join(a, name) |
Colin Cross | 178a509 | 2016-09-13 13:42:32 -0700 | [diff] [blame] | 883 | a.module.base().hooks.runInstallHooks(a, fullInstallPath, true) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 884 | |
Colin Cross | 893d816 | 2017-04-26 17:34:03 -0700 | [diff] [blame] | 885 | if !a.skipInstall(fullInstallPath) { |
Colin Cross | ce75d2c | 2016-10-06 16:12:58 -0700 | [diff] [blame] | 886 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 887 | a.Build(pctx, BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 888 | Rule: Symlink, |
| 889 | Description: "install symlink " + fullInstallPath.Base(), |
| 890 | Output: fullInstallPath, |
| 891 | OrderOnly: Paths{srcPath}, |
| 892 | Default: !a.AConfig().EmbeddedInMake(), |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 893 | Args: map[string]string{ |
| 894 | "fromPath": srcPath.String(), |
| 895 | }, |
| 896 | }) |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 897 | |
Colin Cross | 12fc497 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 898 | a.installFiles = append(a.installFiles, fullInstallPath) |
| 899 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 900 | } |
Colin Cross | 3854a60 | 2016-01-11 12:49:11 -0800 | [diff] [blame] | 901 | return fullInstallPath |
| 902 | } |
| 903 | |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 904 | func (a *androidModuleContext) CheckbuildFile(srcPath Path) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 905 | a.checkbuildFiles = append(a.checkbuildFiles, srcPath) |
| 906 | } |
| 907 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 908 | type fileInstaller interface { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 909 | filesToInstall() Paths |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | func isFileInstaller(m blueprint.Module) bool { |
| 913 | _, ok := m.(fileInstaller) |
| 914 | return ok |
| 915 | } |
| 916 | |
| 917 | func isAndroidModule(m blueprint.Module) bool { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 918 | _, ok := m.(Module) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 919 | return ok |
| 920 | } |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 921 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 922 | func findStringInSlice(str string, slice []string) int { |
| 923 | for i, s := range slice { |
| 924 | if s == str { |
| 925 | return i |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 926 | } |
| 927 | } |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 928 | return -1 |
| 929 | } |
| 930 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 931 | func SrcIsModule(s string) string { |
| 932 | if len(s) > 1 && s[0] == ':' { |
| 933 | return s[1:] |
| 934 | } |
| 935 | return "" |
| 936 | } |
| 937 | |
| 938 | type sourceDependencyTag struct { |
| 939 | blueprint.BaseDependencyTag |
| 940 | } |
| 941 | |
| 942 | var SourceDepTag sourceDependencyTag |
| 943 | |
| 944 | // Returns a list of modules that must be depended on to satisfy filegroup or generated sources |
| 945 | // modules listed in srcFiles using ":module" syntax |
| 946 | func ExtractSourcesDeps(ctx BottomUpMutatorContext, srcFiles []string) { |
| 947 | var deps []string |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 948 | set := make(map[string]bool) |
| 949 | |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 950 | for _, s := range srcFiles { |
| 951 | if m := SrcIsModule(s); m != "" { |
Nan Zhang | 2439eb7 | 2017-04-10 11:27:50 -0700 | [diff] [blame] | 952 | if _, found := set[m]; found { |
| 953 | ctx.ModuleErrorf("found source dependency duplicate: %q!", m) |
| 954 | } else { |
| 955 | set[m] = true |
| 956 | deps = append(deps, m) |
| 957 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | |
| 961 | ctx.AddDependency(ctx.Module(), SourceDepTag, deps...) |
| 962 | } |
| 963 | |
| 964 | type SourceFileProducer interface { |
| 965 | Srcs() Paths |
| 966 | } |
| 967 | |
| 968 | // Returns a list of paths expanded from globs and modules referenced using ":module" syntax. |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 969 | // ExtractSourcesDeps must have already been called during the dependency resolution phase. |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 970 | func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) Paths { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 971 | return ctx.ExpandSourcesSubDir(srcFiles, excludes, "") |
| 972 | } |
| 973 | |
| 974 | func (ctx *androidModuleContext) ExpandSourcesSubDir(srcFiles, excludes []string, subDir string) Paths { |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 975 | prefix := PathForModuleSrc(ctx).String() |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 976 | |
Dan Willemsen | 2ef08f4 | 2015-06-30 18:15:24 -0700 | [diff] [blame] | 977 | for i, e := range excludes { |
| 978 | j := findStringInSlice(e, srcFiles) |
| 979 | if j != -1 { |
| 980 | srcFiles = append(srcFiles[:j], srcFiles[j+1:]...) |
| 981 | } |
| 982 | |
| 983 | excludes[i] = filepath.Join(prefix, e) |
| 984 | } |
| 985 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 986 | expandedSrcFiles := make(Paths, 0, len(srcFiles)) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 987 | for _, s := range srcFiles { |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 988 | if m := SrcIsModule(s); m != "" { |
| 989 | module := ctx.GetDirectDepWithTag(m, SourceDepTag) |
Colin Cross | 0617bb8 | 2017-10-24 13:01:18 -0700 | [diff] [blame] | 990 | if module == nil { |
| 991 | // Error will have been handled by ExtractSourcesDeps |
| 992 | continue |
| 993 | } |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 994 | if srcProducer, ok := module.(SourceFileProducer); ok { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 995 | expandedSrcFiles = append(expandedSrcFiles, srcProducer.Srcs()...) |
Colin Cross | 068e0fe | 2016-12-13 15:23:47 -0800 | [diff] [blame] | 996 | } else { |
| 997 | ctx.ModuleErrorf("srcs dependency %q is not a source file producing module", m) |
| 998 | } |
| 999 | } else if pathtools.IsGlob(s) { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1000 | globbedSrcFiles := ctx.Glob(filepath.Join(prefix, s), excludes) |
Colin Cross | 05a39cb | 2017-10-09 13:35:19 -0700 | [diff] [blame] | 1001 | for i, s := range globbedSrcFiles { |
| 1002 | globbedSrcFiles[i] = s.(ModuleSrcPath).WithSubDir(ctx, subDir) |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1003 | } |
Colin Cross | 05a39cb | 2017-10-09 13:35:19 -0700 | [diff] [blame] | 1004 | expandedSrcFiles = append(expandedSrcFiles, globbedSrcFiles...) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1005 | } else { |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1006 | s := PathForModuleSrc(ctx, s).WithSubDir(ctx, subDir) |
| 1007 | expandedSrcFiles = append(expandedSrcFiles, s) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | |
Colin Cross | faeb7aa | 2017-02-01 14:12:44 -0800 | [diff] [blame] | 1011 | return expandedSrcFiles |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
Nan Zhang | 6d34b30 | 2017-02-04 17:47:46 -0800 | [diff] [blame] | 1014 | func (ctx *androidModuleContext) RequiredModuleNames() []string { |
| 1015 | return ctx.module.base().commonProperties.Required |
| 1016 | } |
| 1017 | |
Colin Cross | 7f19f37 | 2016-11-01 11:10:25 -0700 | [diff] [blame] | 1018 | func (ctx *androidModuleContext) Glob(globPattern string, excludes []string) Paths { |
| 1019 | ret, err := ctx.GlobWithDeps(globPattern, excludes) |
Colin Cross | 8f101b4 | 2015-06-17 15:09:06 -0700 | [diff] [blame] | 1020 | if err != nil { |
| 1021 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 1022 | } |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 1023 | return pathsForModuleSrcFromFullPath(ctx, ret) |
Colin Cross | fce5327 | 2015-04-08 11:21:40 -0700 | [diff] [blame] | 1024 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1025 | |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 1026 | func init() { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 1027 | RegisterSingletonType("buildtarget", BuildTargetSingleton) |
Colin Cross | 463a90e | 2015-06-17 14:20:06 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1030 | func BuildTargetSingleton() blueprint.Singleton { |
| 1031 | return &buildTargetSingleton{} |
| 1032 | } |
| 1033 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1034 | func parentDir(dir string) string { |
| 1035 | dir, _ = filepath.Split(dir) |
| 1036 | return filepath.Clean(dir) |
| 1037 | } |
| 1038 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1039 | type buildTargetSingleton struct{} |
| 1040 | |
| 1041 | func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { |
| 1042 | checkbuildDeps := []string{} |
| 1043 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1044 | mmTarget := func(dir string) string { |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1045 | return "MODULES-IN-" + strings.Replace(filepath.Clean(dir), "/", "-", -1) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | modulesInDir := make(map[string][]string) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1049 | |
| 1050 | ctx.VisitAllModules(func(module blueprint.Module) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1051 | if a, ok := module.(Module); ok { |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1052 | blueprintDir := a.base().blueprintDir |
| 1053 | installTarget := a.base().installTarget |
| 1054 | checkbuildTarget := a.base().checkbuildTarget |
| 1055 | |
| 1056 | if checkbuildTarget != "" { |
| 1057 | checkbuildDeps = append(checkbuildDeps, checkbuildTarget) |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1058 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | if installTarget != "" { |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1062 | modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget) |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | }) |
| 1066 | |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1067 | suffix := "" |
| 1068 | if ctx.Config().(Config).EmbeddedInMake() { |
| 1069 | suffix = "-soong" |
| 1070 | } |
| 1071 | |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1072 | // Create a top-level checkbuild target that depends on all modules |
| 1073 | ctx.Build(pctx, blueprint.BuildParams{ |
| 1074 | Rule: blueprint.Phony, |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1075 | Outputs: []string{"checkbuild" + suffix}, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1076 | Implicits: checkbuildDeps, |
Dan Willemsen | 218f656 | 2015-07-08 18:13:11 -0700 | [diff] [blame] | 1077 | Optional: true, |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1078 | }) |
| 1079 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1080 | // Make will generate the MODULES-IN-* targets |
| 1081 | if ctx.Config().(Config).EmbeddedInMake() { |
| 1082 | return |
| 1083 | } |
| 1084 | |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1085 | // Ensure ancestor directories are in modulesInDir |
| 1086 | dirs := sortedKeys(modulesInDir) |
| 1087 | for _, dir := range dirs { |
| 1088 | dir := parentDir(dir) |
| 1089 | for dir != "." && dir != "/" { |
| 1090 | if _, exists := modulesInDir[dir]; exists { |
| 1091 | break |
| 1092 | } |
| 1093 | modulesInDir[dir] = nil |
| 1094 | dir = parentDir(dir) |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | // Make directories build their direct subdirectories |
| 1099 | dirs = sortedKeys(modulesInDir) |
| 1100 | for _, dir := range dirs { |
| 1101 | p := parentDir(dir) |
| 1102 | if p != "." && p != "/" { |
| 1103 | modulesInDir[p] = append(modulesInDir[p], mmTarget(dir)) |
| 1104 | } |
| 1105 | } |
| 1106 | |
Dan Willemsen | d2e95fb | 2017-09-20 14:30:50 -0700 | [diff] [blame] | 1107 | // Create a MODULES-IN-<directory> target that depends on all modules in a directory, and |
| 1108 | // depends on the MODULES-IN-* targets of all of its subdirectories that contain Android.bp |
| 1109 | // files. |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1110 | for _, dir := range dirs { |
| 1111 | ctx.Build(pctx, blueprint.BuildParams{ |
| 1112 | Rule: blueprint.Phony, |
Colin Cross | 87d8b56 | 2017-04-25 10:01:55 -0700 | [diff] [blame] | 1113 | Outputs: []string{mmTarget(dir)}, |
| 1114 | Implicits: modulesInDir[dir], |
Dan Willemsen | 5ba07e8 | 2015-12-11 13:51:06 -0800 | [diff] [blame] | 1115 | // HACK: checkbuild should be an optional build, but force it |
| 1116 | // enabled for now in standalone builds |
Colin Cross | 1604ecf | 2015-12-17 16:33:43 -0800 | [diff] [blame] | 1117 | Optional: ctx.Config().(Config).EmbeddedInMake(), |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1118 | }) |
| 1119 | } |
Dan Willemsen | 61d88b8 | 2017-09-20 17:29:08 -0700 | [diff] [blame] | 1120 | |
| 1121 | // Create (host|host-cross|target)-<OS> phony rules to build a reduced checkbuild. |
| 1122 | osDeps := map[OsType]Paths{} |
| 1123 | ctx.VisitAllModules(func(module blueprint.Module) { |
| 1124 | if a, ok := module.(Module); ok { |
| 1125 | if a.Enabled() { |
| 1126 | os := a.Target().Os |
| 1127 | osDeps[os] = append(osDeps[os], a.base().checkbuildFiles...) |
| 1128 | } |
| 1129 | } |
| 1130 | }) |
| 1131 | |
| 1132 | osClass := make(map[string][]string) |
| 1133 | for os, deps := range osDeps { |
| 1134 | var className string |
| 1135 | |
| 1136 | switch os.Class { |
| 1137 | case Host: |
| 1138 | className = "host" |
| 1139 | case HostCross: |
| 1140 | className = "host-cross" |
| 1141 | case Device: |
| 1142 | className = "target" |
| 1143 | default: |
| 1144 | continue |
| 1145 | } |
| 1146 | |
| 1147 | name := className + "-" + os.Name |
| 1148 | osClass[className] = append(osClass[className], name) |
| 1149 | |
| 1150 | ctx.Build(pctx, blueprint.BuildParams{ |
| 1151 | Rule: blueprint.Phony, |
| 1152 | Outputs: []string{name}, |
| 1153 | Implicits: deps.Strings(), |
| 1154 | Optional: true, |
| 1155 | }) |
| 1156 | } |
| 1157 | |
| 1158 | // Wrap those into host|host-cross|target phony rules |
| 1159 | osClasses := sortedKeys(osClass) |
| 1160 | for _, class := range osClasses { |
| 1161 | ctx.Build(pctx, blueprint.BuildParams{ |
| 1162 | Rule: blueprint.Phony, |
| 1163 | Outputs: []string{class}, |
| 1164 | Implicits: osClass[class], |
| 1165 | Optional: true, |
| 1166 | }) |
| 1167 | } |
Colin Cross | 1f8c52b | 2015-06-16 16:38:17 -0700 | [diff] [blame] | 1168 | } |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1169 | |
| 1170 | type AndroidModulesByName struct { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 1171 | slice []Module |
Colin Cross | d779da4 | 2015-12-17 18:00:23 -0800 | [diff] [blame] | 1172 | ctx interface { |
| 1173 | ModuleName(blueprint.Module) string |
| 1174 | ModuleSubDir(blueprint.Module) string |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | func (s AndroidModulesByName) Len() int { return len(s.slice) } |
| 1179 | func (s AndroidModulesByName) Less(i, j int) bool { |
| 1180 | mi, mj := s.slice[i], s.slice[j] |
| 1181 | ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj) |
| 1182 | |
| 1183 | if ni != nj { |
| 1184 | return ni < nj |
| 1185 | } else { |
| 1186 | return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj) |
| 1187 | } |
| 1188 | } |
| 1189 | func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] } |