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