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