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