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