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