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