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