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