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