loadRecursive loads all the included plugins and their included plugins, etc. seen should be a cloned map because loading plugins twice is allowed if they are in different paths.
( lockfile *lock.File, seen map[string]bool, cyclePath string, )
| 232 | // seen should be a cloned map because loading plugins twice is allowed if they |
| 233 | // are in different paths. |
| 234 | func (c *Config) loadRecursive( |
| 235 | lockfile *lock.File, |
| 236 | seen map[string]bool, |
| 237 | cyclePath string, |
| 238 | ) error { |
| 239 | included := make([]*Config, 0, len(c.Root.Include)) |
| 240 | |
| 241 | for _, includeRef := range c.Root.Include { |
| 242 | pluginConfig, err := plugin.LoadConfigFromInclude( |
| 243 | includeRef, lockfile, filepath.Dir(c.Root.AbsRootPath)) |
| 244 | if err != nil { |
| 245 | return errors.WithStack(err) |
| 246 | } |
| 247 | |
| 248 | newCyclePath := fmt.Sprintf("%s -> %s", cyclePath, includeRef) |
| 249 | if seen[pluginConfig.Source.Hash()] { |
| 250 | // Note that duplicate includes are allowed if they are in different paths |
| 251 | // e.g. 2 different plugins can include the same plugin. |
| 252 | // We do not allow a single plugin to include duplicates. |
| 253 | return errors.Errorf( |
| 254 | "circular or duplicate include detected:\n%s", newCyclePath) |
| 255 | } |
| 256 | seen[pluginConfig.Source.Hash()] = true |
| 257 | |
| 258 | includable := createIncludableFromPluginConfig(pluginConfig) |
| 259 | |
| 260 | if err := includable.loadRecursive( |
| 261 | lockfile, maps.Clone(seen), newCyclePath); err != nil { |
| 262 | return errors.WithStack(err) |
| 263 | } |
| 264 | |
| 265 | included = append(included, includable) |
| 266 | } |
| 267 | |
| 268 | builtIns, err := plugin.GetBuiltinsForPackages( |
| 269 | c.Root.TopLevelPackages(), |
| 270 | lockfile, |
| 271 | ) |
| 272 | if err != nil { |
| 273 | return errors.WithStack(err) |
| 274 | } |
| 275 | |
| 276 | for _, builtIn := range builtIns { |
| 277 | includable := &Config{ |
| 278 | Root: builtIn.ConfigFile, |
| 279 | pluginData: &builtIn.PluginOnlyData, |
| 280 | } |
| 281 | newCyclePath := fmt.Sprintf("%s -> %s", cyclePath, builtIn.Source.LockfileKey()) |
| 282 | if err := includable.loadRecursive( |
| 283 | lockfile, maps.Clone(seen), newCyclePath); err != nil { |
| 284 | return errors.WithStack(err) |
| 285 | } |
| 286 | included = append(included, includable) |
| 287 | } |
| 288 | |
| 289 | c.included = included |
| 290 | return nil |
| 291 | } |
no test coverage detected