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