walk

package
v0.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 6

Documentation

Overview

Package walk provides customizable functionality for visiting each subdirectory in a directory tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(c *config.Config, cexts []config.Configurer, dirs []string, mode Mode, wf WalkFunc)

Walk traverses the directory tree rooted at c.RepoRoot. Walk visits subdirectories in depth-first post-order.

When Walk visits a directory, it lists the files and subdirectories within that directory. If a build file is present, Walk reads the build file and applies any directives to the configuration (a copy of the parent directory's configuration is made, and the copy is modified). After visiting subdirectories, the callback wf may be called, depending on the mode.

c is the root configuration to start with. This includes changes made by command line flags, but not by the root build file. This configuration should not be modified.

cexts is a list of configuration extensions. When visiting a directory, before visiting subdirectories, Walk makes a copy of the parent configuration and Configure for each extension on the copy. If Walk sees a directive that is not listed in KnownDirectives of any extension, an error will be logged.

dirs is a list of absolute, canonical file system paths of directories to visit.

mode determines whether subdirectories of dirs should be visited recursively, when the wf callback should be called, and when the "update" argument to the wf callback should be set.

wf is a function that may be called in each directory.

Types

type Configurer

type Configurer struct{}

func (*Configurer) CheckFlags

func (*Configurer) CheckFlags(fs *flag.FlagSet, c *config.Config) error

func (*Configurer) Configure

func (cr *Configurer) Configure(c *config.Config, rel string, f *rule.File)

func (*Configurer) KnownDirectives

func (*Configurer) KnownDirectives() []string

func (*Configurer) RegisterFlags

func (*Configurer) RegisterFlags(fs *flag.FlagSet, cmd string, c *config.Config)

type Mode

type Mode int

Mode determines which directories Walk visits and which directories should be updated.

const (
	// In VisitAllUpdateSubdirsMode, Walk visits every directory in the
	// repository. The directories given to Walk and their subdirectories are
	// updated.
	VisitAllUpdateSubdirsMode Mode = iota

	// In VisitAllUpdateDirsMode, Walk visits every directory in the repository.
	// Only the directories given to Walk are updated (not their subdirectories).
	VisitAllUpdateDirsMode

	// In UpdateDirsMode, Walk only visits and updates directories given to Walk.
	// Build files in parent directories are read in order to produce a complete
	// configuration, but the callback is not called for parent directories.
	UpdateDirsMode

	// In UpdateSubdirsMode, Walk visits and updates the directories given to Walk
	// and their subdirectories. Build files in parent directories are read in
	// order to produce a complete configuration, but the callback is not called
	// for parent directories.
	UpdateSubdirsMode
)

type UpdateFilter added in v0.39.0

type UpdateFilter struct {
	// contains filtered or unexported fields
}

An UpdateFilter tracks which directories need to be updated

INTERNAL: this is a non-public util only for use within bazel-gazelle.

func NewUpdateFilter added in v0.39.0

func NewUpdateFilter(root string, dirs []string, mode Mode) *UpdateFilter

NewUpdateFilter builds a table of prefixes, used to determine which directories to update and visit.

root and dirs must be absolute, canonical file paths. Each entry in dirs must be a subdirectory of root. The caller is responsible for checking this.

INTERNAL: this is a non-public util only for use within bazel-gazelle.

type WalkFunc

type WalkFunc func(dir, rel string, c *config.Config, update bool, f *rule.File, subdirs, regularFiles, genFiles []string)

WalkFunc is a callback called by Walk in each visited directory.

dir is the absolute file system path to the directory being visited.

rel is the relative slash-separated path to the directory from the repository root. Will be "" for the repository root directory itself.

c is the configuration for the current directory. This may have been modified by directives in the directory's build file.

update is true when the build file may be updated.

f is the existing build file in the directory. Will be nil if there was no file.

subdirs is a list of base names of subdirectories within dir, not including excluded files.

regularFiles is a list of base names of regular files within dir, not including excluded files or symlinks.

genFiles is a list of names of generated files, found by reading "out" and "outs" attributes of rules in f.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL