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