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