Colin Cross | 69452e1 | 2023-11-15 11:20:53 -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 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 19 | "regexp" |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 20 | "slices" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 21 | "strings" |
Cole Faust | bdd8aee | 2024-03-14 14:33:02 -0700 | [diff] [blame] | 22 | |
| 23 | "github.com/google/blueprint" |
Cole Faust | fdbf5d4 | 2024-04-10 15:01:23 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint/proptools" |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | // BaseModuleContext is the same as blueprint.BaseModuleContext except that Config() returns |
| 28 | // a Config instead of an interface{}, and some methods have been wrapped to use an android.Module |
| 29 | // instead of a blueprint.Module, plus some extra methods that return Android-specific information |
| 30 | // about the current module. |
| 31 | type BaseModuleContext interface { |
Colin Cross | 1d3d9f1 | 2024-01-18 14:30:22 -0800 | [diff] [blame] | 32 | ArchModuleContext |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 33 | EarlyModuleContext |
| 34 | |
| 35 | blueprintBaseModuleContext() blueprint.BaseModuleContext |
| 36 | |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 37 | EqualModules(m1, m2 Module) bool |
| 38 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 39 | // OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information. |
| 40 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
| 41 | OtherModuleName(m blueprint.Module) string |
| 42 | |
| 43 | // OtherModuleDir returns the directory of another Module. See BaseModuleContext.ModuleDir for more information. |
| 44 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
| 45 | OtherModuleDir(m blueprint.Module) string |
| 46 | |
| 47 | // OtherModuleErrorf reports an error on another Module. See BaseModuleContext.ModuleErrorf for more information. |
| 48 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
| 49 | OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) |
| 50 | |
| 51 | // OtherModuleDependencyTag returns the dependency tag used to depend on a module, or nil if there is no dependency |
| 52 | // on the module. When called inside a Visit* method with current module being visited, and there are multiple |
| 53 | // dependencies on the module being visited, it returns the dependency tag used for the current dependency. |
| 54 | OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag |
| 55 | |
Jihoon Kang | f50d2e6 | 2025-02-19 00:47:23 +0000 | [diff] [blame^] | 56 | // OtherModuleSubDir returns the string representing the variations of a module. |
| 57 | OtherModuleSubDir(m blueprint.Module) string |
| 58 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 59 | // OtherModuleExists returns true if a module with the specified name exists, as determined by the NameInterface |
| 60 | // passed to Context.SetNameInterface, or SimpleNameInterface if it was not called. |
| 61 | OtherModuleExists(name string) bool |
| 62 | |
| 63 | // OtherModuleDependencyVariantExists returns true if a module with the |
| 64 | // specified name and variant exists. The variant must match the given |
| 65 | // variations. It must also match all the non-local variations of the current |
| 66 | // module. In other words, it checks for the module that AddVariationDependencies |
| 67 | // would add a dependency on with the same arguments. |
| 68 | OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool |
| 69 | |
| 70 | // OtherModuleFarDependencyVariantExists returns true if a module with the |
| 71 | // specified name and variant exists. The variant must match the given |
| 72 | // variations, but not the non-local variations of the current module. In |
| 73 | // other words, it checks for the module that AddFarVariationDependencies |
| 74 | // would add a dependency on with the same arguments. |
| 75 | OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool |
| 76 | |
| 77 | // OtherModuleReverseDependencyVariantExists returns true if a module with the |
| 78 | // specified name exists with the same variations as the current module. In |
| 79 | // other words, it checks for the module that AddReverseDependency would add a |
| 80 | // dependency on with the same argument. |
| 81 | OtherModuleReverseDependencyVariantExists(name string) bool |
| 82 | |
| 83 | // OtherModuleType returns the type of another Module. See BaseModuleContext.ModuleType for more information. |
| 84 | // It is intended for use inside the visit functions of Visit* and WalkDeps. |
| 85 | OtherModuleType(m blueprint.Module) string |
| 86 | |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 87 | // otherModuleProvider returns the value for a provider for the given module. If the value is |
| 88 | // not set it returns nil and false. The value returned may be a deep copy of the value originally |
| 89 | // passed to SetProvider. |
| 90 | // |
| 91 | // This method shouldn't be used directly, prefer the type-safe android.OtherModuleProvider instead. |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 92 | otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 93 | |
Jihoon Kang | 2a7bf75 | 2024-11-01 21:21:25 +0000 | [diff] [blame] | 94 | // OtherModuleIsAutoGenerated returns true if the module is auto generated by another module |
| 95 | // instead of being defined in Android.bp file. |
| 96 | OtherModuleIsAutoGenerated(m blueprint.Module) bool |
| 97 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 98 | // Provider returns the value for a provider for the current module. If the value is |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 99 | // not set it returns nil and false. It panics if called before the appropriate |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 100 | // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep |
| 101 | // copy of the value originally passed to SetProvider. |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 102 | // |
| 103 | // This method shouldn't be used directly, prefer the type-safe android.ModuleProvider instead. |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 104 | provider(provider blueprint.AnyProviderKey) (any, bool) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 105 | |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 106 | // setProvider sets the value for a provider for the current module. It panics if not called |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 107 | // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value |
| 108 | // is not of the appropriate type, or if the value has already been set. The value should not |
| 109 | // be modified after being passed to SetProvider. |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 110 | // |
| 111 | // This method shouldn't be used directly, prefer the type-safe android.SetProvider instead. |
| 112 | setProvider(provider blueprint.AnyProviderKey, value any) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 113 | |
| 114 | GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module |
| 115 | |
Yu Liu | f432c2e | 2024-12-17 00:09:15 +0000 | [diff] [blame] | 116 | GetDirectDepsProxyWithTag(tag blueprint.DependencyTag) []ModuleProxy |
| 117 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 118 | // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if |
| 119 | // none exists. It panics if the dependency does not have the specified tag. It skips any |
| 120 | // dependencies that are not an android.Module. |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 121 | GetDirectDepWithTag(name string, tag blueprint.DependencyTag) Module |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 122 | |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 123 | GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy |
| 124 | |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 125 | // VisitDirectDeps calls visit for each direct dependency. If there are multiple |
| 126 | // direct dependencies on the same module visit will be called multiple times on that module |
| 127 | // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the |
| 128 | // dependencies are disabled. |
| 129 | // |
| 130 | // The Module passed to the visit function should not be retained outside of the visit |
| 131 | // function, it may be invalidated by future mutators. |
| 132 | VisitDirectDeps(visit func(Module)) |
| 133 | |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 134 | // VisitDirectDepsProxy calls visit for each direct dependency. If there are multiple |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 135 | // direct dependencies on the same module visit will be called multiple times on that module |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 136 | // and OtherModuleDependencyTag will return a different tag for each. It raises an error if any of the |
| 137 | // dependencies are disabled. |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 138 | // |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 139 | // The ModuleProxy passed to the visit function should not be retained outside of the visit |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 140 | // function, it may be invalidated by future mutators. |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 141 | VisitDirectDepsProxy(visit func(proxy ModuleProxy)) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 142 | |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 143 | // VisitDirectDepsProxyAllowDisabled calls visit for each direct dependency. If there are |
| 144 | // multiple direct dependencies on the same module visit will be called multiple times on |
| 145 | // that module and OtherModuleDependencyTag will return a different tag for each. |
| 146 | // |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 147 | // The ModuleProxy passed to the visit function should not be retained outside of the visit function, it may be |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 148 | // invalidated by future mutators. |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 149 | VisitDirectDepsProxyAllowDisabled(visit func(proxy ModuleProxy)) |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 150 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 151 | VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) |
| 152 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 153 | VisitDirectDepsProxyWithTag(tag blueprint.DependencyTag, visit func(proxy ModuleProxy)) |
| 154 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 155 | // VisitDirectDepsIf calls pred for each direct dependency, and if pred returns true calls visit. If there are |
| 156 | // multiple direct dependencies on the same module pred and visit will be called multiple times on that module and |
| 157 | // OtherModuleDependencyTag will return a different tag for each. It skips any |
| 158 | // dependencies that are not an android.Module. |
| 159 | // |
| 160 | // The Module passed to the visit function should not be retained outside of the visit function, it may be |
| 161 | // invalidated by future mutators. |
| 162 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 163 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
| 164 | VisitDepsDepthFirst(visit func(Module)) |
| 165 | // Deprecated: use WalkDeps instead to support multiple dependency tags on the same module |
| 166 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
| 167 | |
| 168 | // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may |
| 169 | // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the |
| 170 | // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited |
| 171 | // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips |
| 172 | // any dependencies that are not an android.Module. |
| 173 | // |
| 174 | // The Modules passed to the visit function should not be retained outside of the visit function, they may be |
| 175 | // invalidated by future mutators. |
| 176 | WalkDeps(visit func(child, parent Module) bool) |
| 177 | |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 178 | // WalkDeps calls visit for each transitive dependency, traversing the dependency tree in top down order. visit may |
| 179 | // be called multiple times for the same (child, parent) pair if there are multiple direct dependencies between the |
| 180 | // child and parent with different tags. OtherModuleDependencyTag will return the tag for the currently visited |
| 181 | // (child, parent) pair. If visit returns false WalkDeps will not continue recursing down to child. It skips |
| 182 | // any dependencies that are not an android.Module. |
| 183 | // |
| 184 | // The Modules passed to the visit function should not be retained outside of the visit function, they may be |
| 185 | // invalidated by future mutators. |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 186 | WalkDepsProxy(visit func(child, parent ModuleProxy) bool) |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 187 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 188 | // GetWalkPath is supposed to be called in visit function passed in WalkDeps() |
| 189 | // and returns a top-down dependency path from a start module to current child module. |
| 190 | GetWalkPath() []Module |
| 191 | |
| 192 | // PrimaryModule returns the first variant of the current module. Variants of a module are always visited in |
| 193 | // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the |
| 194 | // Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are |
| 195 | // only done once for all variants of a module. |
| 196 | PrimaryModule() Module |
| 197 | |
| 198 | // FinalModule returns the last variant of the current module. Variants of a module are always visited in |
| 199 | // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all |
| 200 | // variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform |
| 201 | // singleton actions that are only done once for all variants of a module. |
| 202 | FinalModule() Module |
| 203 | |
Yu Liu | 88ea9ff | 2024-11-07 19:19:42 +0000 | [diff] [blame] | 204 | // IsFinalModule returns if the current module is the last variant. Variants of a module are always visited in |
| 205 | // order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all |
| 206 | // variants using VisitAllModuleVariants if the current module is the last one. This can be used to perform |
| 207 | // singleton actions that are only done once for all variants of a module. |
| 208 | IsFinalModule(module Module) bool |
| 209 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 210 | // VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always |
| 211 | // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read |
Yu Liu | 88ea9ff | 2024-11-07 19:19:42 +0000 | [diff] [blame] | 212 | // from all variants if the current module is the last one. Otherwise, care must be taken to not access any |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 213 | // data modified by the current mutator. |
| 214 | VisitAllModuleVariants(visit func(Module)) |
| 215 | |
Yu Liu | b527532 | 2024-11-13 18:40:43 +0000 | [diff] [blame] | 216 | // VisitAllModuleVariantProxies calls visit for each variant of the current module. Variants of a module are always |
| 217 | // visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read |
| 218 | // from all variants if the current module is the last one. Otherwise, care must be taken to not access any |
| 219 | // data modified by the current mutator. |
| 220 | VisitAllModuleVariantProxies(visit func(proxy ModuleProxy)) |
| 221 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 222 | // GetTagPath is supposed to be called in visit function passed in WalkDeps() |
| 223 | // and returns a top-down dependency tags path from a start module to current child module. |
| 224 | // It has one less entry than GetWalkPath() as it contains the dependency tags that |
| 225 | // exist between each adjacent pair of modules in the GetWalkPath(). |
| 226 | // GetTagPath()[i] is the tag between GetWalkPath()[i] and GetWalkPath()[i+1] |
| 227 | GetTagPath() []blueprint.DependencyTag |
| 228 | |
| 229 | // GetPathString is supposed to be called in visit function passed in WalkDeps() |
| 230 | // and returns a multi-line string showing the modules and dependency tags |
| 231 | // among them along the top-down dependency path from a start module to current child module. |
| 232 | // skipFirst when set to true, the output doesn't include the start module, |
| 233 | // which is already printed when this function is used along with ModuleErrorf(). |
| 234 | GetPathString(skipFirst bool) string |
| 235 | |
| 236 | AddMissingDependencies(missingDeps []string) |
| 237 | |
| 238 | // getMissingDependencies returns the list of missing dependencies. |
| 239 | // Calling this function prevents adding new dependencies. |
| 240 | getMissingDependencies() []string |
Cole Faust | bdd8aee | 2024-03-14 14:33:02 -0700 | [diff] [blame] | 241 | |
| 242 | // EvaluateConfiguration makes ModuleContext a valid proptools.ConfigurableEvaluator, so this context |
| 243 | // can be used to evaluate the final value of Configurable properties. |
Cole Faust | fdbf5d4 | 2024-04-10 15:01:23 -0700 | [diff] [blame] | 244 | EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | type baseModuleContext struct { |
| 248 | bp blueprint.BaseModuleContext |
| 249 | earlyModuleContext |
Colin Cross | 1d3d9f1 | 2024-01-18 14:30:22 -0800 | [diff] [blame] | 250 | archModuleContext |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 251 | |
| 252 | walkPath []Module |
| 253 | tagPath []blueprint.DependencyTag |
| 254 | |
| 255 | strictVisitDeps bool // If true, enforce that all dependencies are enabled |
| 256 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 259 | func getWrappedModule(module blueprint.Module) blueprint.Module { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 260 | if mp, isProxy := module.(*ModuleProxy); isProxy { |
| 261 | return mp.module |
| 262 | } |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 263 | if mp, isProxy := module.(ModuleProxy); isProxy { |
| 264 | return mp.module |
| 265 | } |
| 266 | return module |
| 267 | } |
| 268 | |
| 269 | func (b *baseModuleContext) EqualModules(m1, m2 Module) bool { |
| 270 | return b.bp.EqualModules(getWrappedModule(m1), getWrappedModule(m2)) |
| 271 | } |
| 272 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 273 | func (b *baseModuleContext) OtherModuleName(m blueprint.Module) string { |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 274 | return b.bp.OtherModuleName(getWrappedModule(m)) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 275 | } |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 276 | func (b *baseModuleContext) OtherModuleDir(m blueprint.Module) string { |
| 277 | return b.bp.OtherModuleDir(getWrappedModule(m)) |
| 278 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 279 | func (b *baseModuleContext) OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) { |
Yu Liu | ac483e0 | 2024-11-11 22:29:30 +0000 | [diff] [blame] | 280 | b.bp.OtherModuleErrorf(getWrappedModule(m), fmt, args...) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 281 | } |
| 282 | func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag { |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 283 | return b.bp.OtherModuleDependencyTag(getWrappedModule(m)) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 284 | } |
Jihoon Kang | f50d2e6 | 2025-02-19 00:47:23 +0000 | [diff] [blame^] | 285 | func (b *baseModuleContext) OtherModuleSubDir(m blueprint.Module) string { |
| 286 | return b.bp.OtherModuleSubDir(getWrappedModule(m)) |
| 287 | } |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 288 | func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) } |
| 289 | func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool { |
| 290 | return b.bp.OtherModuleDependencyVariantExists(variations, name) |
| 291 | } |
| 292 | func (b *baseModuleContext) OtherModuleFarDependencyVariantExists(variations []blueprint.Variation, name string) bool { |
| 293 | return b.bp.OtherModuleFarDependencyVariantExists(variations, name) |
| 294 | } |
| 295 | func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool { |
| 296 | return b.bp.OtherModuleReverseDependencyVariantExists(name) |
| 297 | } |
| 298 | func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { |
Yu Liu | b1bfa9d | 2024-12-05 18:57:51 +0000 | [diff] [blame] | 299 | return b.bp.OtherModuleType(getWrappedModule(m)) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 300 | } |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 301 | |
| 302 | func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { |
Cole Faust | 19eb09d | 2025-01-14 13:27:00 -0800 | [diff] [blame] | 303 | return b.bp.OtherModuleProvider(getWrappedModule(m), provider) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 304 | } |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 305 | |
Jihoon Kang | 2a7bf75 | 2024-11-01 21:21:25 +0000 | [diff] [blame] | 306 | func (b *baseModuleContext) OtherModuleIsAutoGenerated(m blueprint.Module) bool { |
| 307 | return b.bp.OtherModuleIsAutoGenerated(m) |
| 308 | } |
| 309 | |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 310 | func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 311 | return b.bp.Provider(provider) |
| 312 | } |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 313 | |
Colin Cross | 24c1cbe | 2023-12-21 23:42:56 +0000 | [diff] [blame] | 314 | func (b *baseModuleContext) setProvider(provider blueprint.AnyProviderKey, value any) { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 315 | b.bp.SetProvider(provider, value) |
| 316 | } |
| 317 | |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 318 | func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) Module { |
| 319 | if module := b.bp.GetDirectDepWithTag(name, tag); module != nil { |
| 320 | return module.(Module) |
| 321 | } |
| 322 | return nil |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 325 | func (b *baseModuleContext) GetDirectDepProxyWithTag(name string, tag blueprint.DependencyTag) *ModuleProxy { |
| 326 | if module := b.bp.GetDirectDepProxyWithTag(name, tag); module != nil { |
| 327 | return &ModuleProxy{*module} |
| 328 | } |
| 329 | return nil |
| 330 | } |
| 331 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 332 | func (b *baseModuleContext) blueprintBaseModuleContext() blueprint.BaseModuleContext { |
| 333 | return b.bp |
| 334 | } |
| 335 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 336 | func (b *baseModuleContext) AddMissingDependencies(deps []string) { |
| 337 | if deps != nil { |
| 338 | missingDeps := &b.Module().base().commonProperties.MissingDeps |
| 339 | *missingDeps = append(*missingDeps, deps...) |
| 340 | *missingDeps = FirstUniqueStrings(*missingDeps) |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | func (b *baseModuleContext) checkedMissingDeps() bool { |
| 345 | return b.Module().base().commonProperties.CheckedMissingDeps |
| 346 | } |
| 347 | |
| 348 | func (b *baseModuleContext) getMissingDependencies() []string { |
| 349 | checked := &b.Module().base().commonProperties.CheckedMissingDeps |
| 350 | *checked = true |
| 351 | var missingDeps []string |
| 352 | missingDeps = append(missingDeps, b.Module().base().commonProperties.MissingDeps...) |
| 353 | missingDeps = append(missingDeps, b.bp.EarlyGetMissingDependencies()...) |
| 354 | missingDeps = FirstUniqueStrings(missingDeps) |
| 355 | return missingDeps |
| 356 | } |
| 357 | |
| 358 | type AllowDisabledModuleDependency interface { |
| 359 | blueprint.DependencyTag |
| 360 | AllowDisabledModuleDependency(target Module) bool |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 361 | AllowDisabledModuleDependencyProxy(ctx OtherModuleProviderContext, target ModuleProxy) bool |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Jiyong Park | 8bcf3c6 | 2024-03-18 18:37:10 +0900 | [diff] [blame] | 364 | type AlwaysAllowDisabledModuleDependencyTag struct{} |
| 365 | |
| 366 | func (t AlwaysAllowDisabledModuleDependencyTag) AllowDisabledModuleDependency(Module) bool { |
| 367 | return true |
| 368 | } |
| 369 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 370 | func (t AlwaysAllowDisabledModuleDependencyTag) AllowDisabledModuleDependencyProxy(OtherModuleProviderContext, ModuleProxy) bool { |
| 371 | return true |
| 372 | } |
| 373 | |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 374 | func (b *baseModuleContext) validateAndroidModule(module blueprint.Module, tag blueprint.DependencyTag, strict bool) Module { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 375 | aModule, _ := module.(Module) |
| 376 | |
| 377 | if !strict { |
| 378 | return aModule |
| 379 | } |
| 380 | |
| 381 | if aModule == nil { |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 382 | panic(fmt.Errorf("module %q (%#v) not an android module", b.OtherModuleName(module), tag)) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 385 | if !aModule.Enabled(b) { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 386 | if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) { |
| 387 | if b.Config().AllowMissingDependencies() { |
| 388 | b.AddMissingDependencies([]string{b.OtherModuleName(aModule)}) |
| 389 | } else { |
| 390 | b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule)) |
| 391 | } |
| 392 | } |
| 393 | return nil |
| 394 | } |
| 395 | return aModule |
| 396 | } |
| 397 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 398 | func (b *baseModuleContext) validateAndroidModuleProxy( |
| 399 | module blueprint.ModuleProxy, tag blueprint.DependencyTag, strict bool) *ModuleProxy { |
| 400 | aModule := ModuleProxy{module: module} |
| 401 | |
| 402 | if !strict { |
| 403 | return &aModule |
| 404 | } |
| 405 | |
Yu Liu | b527532 | 2024-11-13 18:40:43 +0000 | [diff] [blame] | 406 | if !OtherModuleProviderOrDefault(b, module, CommonModuleInfoKey).Enabled { |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 407 | if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependencyProxy(b, aModule) { |
| 408 | if b.Config().AllowMissingDependencies() { |
| 409 | b.AddMissingDependencies([]string{b.OtherModuleName(aModule)}) |
| 410 | } else { |
| 411 | b.ModuleErrorf("depends on disabled module %q", b.OtherModuleName(aModule)) |
| 412 | } |
| 413 | } |
| 414 | return nil |
| 415 | } |
| 416 | |
| 417 | return &aModule |
| 418 | } |
| 419 | |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 420 | func (b *baseModuleContext) getDirectDepsInternal(name string, tag blueprint.DependencyTag) []Module { |
| 421 | var deps []Module |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 422 | b.VisitDirectDeps(func(module Module) { |
| 423 | if module.base().BaseModuleName() == name { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 424 | returnedTag := b.bp.OtherModuleDependencyTag(module) |
| 425 | if tag == nil || returnedTag == tag { |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 426 | deps = append(deps, module) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | }) |
| 430 | return deps |
| 431 | } |
| 432 | |
Yu Liu | 3ae9665 | 2024-12-17 22:27:38 +0000 | [diff] [blame] | 433 | func (b *baseModuleContext) getDirectDepsProxyInternal(name string, tag blueprint.DependencyTag) []ModuleProxy { |
| 434 | var deps []ModuleProxy |
| 435 | b.VisitDirectDepsProxy(func(module ModuleProxy) { |
| 436 | if OtherModuleProviderOrDefault(b, module, CommonModuleInfoKey).BaseModuleName == name { |
| 437 | returnedTag := b.OtherModuleDependencyTag(module) |
| 438 | if tag == nil || returnedTag == tag { |
| 439 | deps = append(deps, module) |
| 440 | } |
| 441 | } |
| 442 | }) |
| 443 | return deps |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 446 | func (b *baseModuleContext) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module { |
| 447 | var deps []Module |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 448 | b.VisitDirectDeps(func(module Module) { |
| 449 | if b.bp.OtherModuleDependencyTag(module) == tag { |
| 450 | deps = append(deps, module) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 451 | } |
| 452 | }) |
| 453 | return deps |
| 454 | } |
| 455 | |
Yu Liu | f432c2e | 2024-12-17 00:09:15 +0000 | [diff] [blame] | 456 | func (b *baseModuleContext) GetDirectDepsProxyWithTag(tag blueprint.DependencyTag) []ModuleProxy { |
| 457 | var deps []ModuleProxy |
| 458 | b.VisitDirectDepsProxy(func(module ModuleProxy) { |
| 459 | if b.OtherModuleDependencyTag(module) == tag { |
| 460 | deps = append(deps, module) |
| 461 | } |
| 462 | }) |
| 463 | return deps |
| 464 | } |
| 465 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 466 | func (b *baseModuleContext) VisitDirectDeps(visit func(Module)) { |
| 467 | b.bp.VisitDirectDeps(func(module blueprint.Module) { |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 468 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 469 | visit(aModule) |
| 470 | } |
| 471 | }) |
| 472 | } |
| 473 | |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 474 | func (b *baseModuleContext) VisitDirectDepsProxy(visit func(ModuleProxy)) { |
| 475 | b.bp.VisitDirectDepsProxy(func(module blueprint.ModuleProxy) { |
| 476 | if aModule := b.validateAndroidModuleProxy(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
| 477 | visit(*aModule) |
| 478 | } |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 479 | }) |
| 480 | } |
| 481 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 482 | func (b *baseModuleContext) VisitDirectDepsProxyAllowDisabled(visit func(proxy ModuleProxy)) { |
Yu Liu | d3228ac | 2024-11-08 23:11:47 +0000 | [diff] [blame] | 483 | b.bp.VisitDirectDepsProxy(visitProxyAdaptor(visit)) |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 486 | func (b *baseModuleContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) { |
| 487 | b.bp.VisitDirectDeps(func(module blueprint.Module) { |
| 488 | if b.bp.OtherModuleDependencyTag(module) == tag { |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 489 | if aModule := b.validateAndroidModule(module, tag, b.strictVisitDeps); aModule != nil { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 490 | visit(aModule) |
| 491 | } |
| 492 | } |
| 493 | }) |
| 494 | } |
| 495 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 496 | func (b *baseModuleContext) VisitDirectDepsProxyWithTag(tag blueprint.DependencyTag, visit func(proxy ModuleProxy)) { |
| 497 | b.bp.VisitDirectDepsProxy(func(module blueprint.ModuleProxy) { |
| 498 | if b.bp.OtherModuleDependencyTag(module) == tag { |
| 499 | if aModule := b.validateAndroidModuleProxy(module, tag, b.strictVisitDeps); aModule != nil { |
| 500 | visit(*aModule) |
| 501 | } |
| 502 | } |
| 503 | }) |
| 504 | } |
| 505 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 506 | func (b *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 507 | b.bp.VisitDirectDepsIf( |
| 508 | // pred |
| 509 | func(module blueprint.Module) bool { |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 510 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 511 | return pred(aModule) |
| 512 | } else { |
| 513 | return false |
| 514 | } |
| 515 | }, |
| 516 | // visit |
| 517 | func(module blueprint.Module) { |
| 518 | visit(module.(Module)) |
| 519 | }) |
| 520 | } |
| 521 | |
| 522 | func (b *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
| 523 | b.bp.VisitDepsDepthFirst(func(module blueprint.Module) { |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 524 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 525 | visit(aModule) |
| 526 | } |
| 527 | }) |
| 528 | } |
| 529 | |
| 530 | func (b *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { |
| 531 | b.bp.VisitDepsDepthFirstIf( |
| 532 | // pred |
| 533 | func(module blueprint.Module) bool { |
Colin Cross | 648daea | 2024-09-12 14:35:29 -0700 | [diff] [blame] | 534 | if aModule := b.validateAndroidModule(module, b.bp.OtherModuleDependencyTag(module), b.strictVisitDeps); aModule != nil { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 535 | return pred(aModule) |
| 536 | } else { |
| 537 | return false |
| 538 | } |
| 539 | }, |
| 540 | // visit |
| 541 | func(module blueprint.Module) { |
| 542 | visit(module.(Module)) |
| 543 | }) |
| 544 | } |
| 545 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 546 | func (b *baseModuleContext) WalkDeps(visit func(Module, Module) bool) { |
| 547 | b.walkPath = []Module{b.Module()} |
| 548 | b.tagPath = []blueprint.DependencyTag{} |
| 549 | b.bp.WalkDeps(func(child, parent blueprint.Module) bool { |
| 550 | childAndroidModule, _ := child.(Module) |
| 551 | parentAndroidModule, _ := parent.(Module) |
| 552 | if childAndroidModule != nil && parentAndroidModule != nil { |
| 553 | // record walkPath before visit |
| 554 | for b.walkPath[len(b.walkPath)-1] != parentAndroidModule { |
| 555 | b.walkPath = b.walkPath[0 : len(b.walkPath)-1] |
| 556 | b.tagPath = b.tagPath[0 : len(b.tagPath)-1] |
| 557 | } |
| 558 | b.walkPath = append(b.walkPath, childAndroidModule) |
| 559 | b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule)) |
| 560 | return visit(childAndroidModule, parentAndroidModule) |
| 561 | } else { |
| 562 | return false |
| 563 | } |
| 564 | }) |
| 565 | } |
| 566 | |
Yu Liu | d2a9595 | 2024-10-10 00:15:26 +0000 | [diff] [blame] | 567 | func (b *baseModuleContext) WalkDepsProxy(visit func(ModuleProxy, ModuleProxy) bool) { |
Yu Liu | dd9ccb4 | 2024-10-07 17:07:44 +0000 | [diff] [blame] | 568 | b.walkPath = []Module{ModuleProxy{blueprint.CreateModuleProxy(b.Module())}} |
| 569 | b.tagPath = []blueprint.DependencyTag{} |
| 570 | b.bp.WalkDepsProxy(func(child, parent blueprint.ModuleProxy) bool { |
| 571 | childAndroidModule := ModuleProxy{child} |
| 572 | parentAndroidModule := ModuleProxy{parent} |
| 573 | // record walkPath before visit |
| 574 | for b.walkPath[len(b.walkPath)-1] != parentAndroidModule { |
| 575 | b.walkPath = b.walkPath[0 : len(b.walkPath)-1] |
| 576 | b.tagPath = b.tagPath[0 : len(b.tagPath)-1] |
| 577 | } |
| 578 | b.walkPath = append(b.walkPath, childAndroidModule) |
| 579 | b.tagPath = append(b.tagPath, b.OtherModuleDependencyTag(childAndroidModule)) |
| 580 | return visit(childAndroidModule, parentAndroidModule) |
| 581 | }) |
| 582 | } |
| 583 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 584 | func (b *baseModuleContext) GetWalkPath() []Module { |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 585 | return slices.Clone(b.walkPath) |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | func (b *baseModuleContext) GetTagPath() []blueprint.DependencyTag { |
| 589 | return b.tagPath |
| 590 | } |
| 591 | |
| 592 | func (b *baseModuleContext) VisitAllModuleVariants(visit func(Module)) { |
| 593 | b.bp.VisitAllModuleVariants(func(module blueprint.Module) { |
| 594 | visit(module.(Module)) |
| 595 | }) |
| 596 | } |
| 597 | |
Yu Liu | b527532 | 2024-11-13 18:40:43 +0000 | [diff] [blame] | 598 | func (b *baseModuleContext) VisitAllModuleVariantProxies(visit func(ModuleProxy)) { |
| 599 | b.bp.VisitAllModuleVariantProxies(visitProxyAdaptor(visit)) |
| 600 | } |
| 601 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 602 | func (b *baseModuleContext) PrimaryModule() Module { |
| 603 | return b.bp.PrimaryModule().(Module) |
| 604 | } |
| 605 | |
| 606 | func (b *baseModuleContext) FinalModule() Module { |
| 607 | return b.bp.FinalModule().(Module) |
| 608 | } |
| 609 | |
Yu Liu | 88ea9ff | 2024-11-07 19:19:42 +0000 | [diff] [blame] | 610 | func (b *baseModuleContext) IsFinalModule(module Module) bool { |
| 611 | return b.bp.IsFinalModule(module) |
| 612 | } |
| 613 | |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 614 | // IsMetaDependencyTag returns true for cross-cutting metadata dependencies. |
| 615 | func IsMetaDependencyTag(tag blueprint.DependencyTag) bool { |
| 616 | if tag == licenseKindTag { |
| 617 | return true |
| 618 | } else if tag == licensesTag { |
| 619 | return true |
Jihoon Kang | a3a0546 | 2024-04-05 00:36:44 +0000 | [diff] [blame] | 620 | } else if tag == AcDepTag { |
Colin Cross | 69452e1 | 2023-11-15 11:20:53 -0800 | [diff] [blame] | 621 | return true |
| 622 | } |
| 623 | return false |
| 624 | } |
| 625 | |
| 626 | // A regexp for removing boilerplate from BaseDependencyTag from the string representation of |
| 627 | // a dependency tag. |
| 628 | var tagCleaner = regexp.MustCompile(`\QBaseDependencyTag:{}\E(, )?`) |
| 629 | |
| 630 | // PrettyPrintTag returns string representation of the tag, but prefers |
| 631 | // custom String() method if available. |
| 632 | func PrettyPrintTag(tag blueprint.DependencyTag) string { |
| 633 | // Use tag's custom String() method if available. |
| 634 | if stringer, ok := tag.(fmt.Stringer); ok { |
| 635 | return stringer.String() |
| 636 | } |
| 637 | |
| 638 | // Otherwise, get a default string representation of the tag's struct. |
| 639 | tagString := fmt.Sprintf("%T: %+v", tag, tag) |
| 640 | |
| 641 | // Remove the boilerplate from BaseDependencyTag as it adds no value. |
| 642 | tagString = tagCleaner.ReplaceAllString(tagString, "") |
| 643 | return tagString |
| 644 | } |
| 645 | |
| 646 | func (b *baseModuleContext) GetPathString(skipFirst bool) string { |
| 647 | sb := strings.Builder{} |
| 648 | tagPath := b.GetTagPath() |
| 649 | walkPath := b.GetWalkPath() |
| 650 | if !skipFirst { |
| 651 | sb.WriteString(walkPath[0].String()) |
| 652 | } |
| 653 | for i, m := range walkPath[1:] { |
| 654 | sb.WriteString("\n") |
| 655 | sb.WriteString(fmt.Sprintf(" via tag %s\n", PrettyPrintTag(tagPath[i]))) |
| 656 | sb.WriteString(fmt.Sprintf(" -> %s", m.String())) |
| 657 | } |
| 658 | return sb.String() |
| 659 | } |
Cole Faust | bdd8aee | 2024-03-14 14:33:02 -0700 | [diff] [blame] | 660 | |
Cole Faust | fdbf5d4 | 2024-04-10 15:01:23 -0700 | [diff] [blame] | 661 | func (m *baseModuleContext) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue { |
| 662 | return m.Module().ConfigurableEvaluator(m).EvaluateConfiguration(condition, property) |
Cole Faust | bdd8aee | 2024-03-14 14:33:02 -0700 | [diff] [blame] | 663 | } |