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