packages

package
v0.0.0-...-c02bc0f Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package packages provides Go package traversal in a Bazel repository.

Index

Constants

View Source
const OptSeparator = "\x1D"

OptSeparator is a special character inserted between options that appeared together in a #cgo directive. This allows options to be split, modified, and escaped by other packages.

It's important to keep options grouped together in the same string. For example, if we have "-framework IOKit" together in a #cgo directive, "-framework" shouldn't be treated as a separate string for the purposes of sorting and de-duplicating.

Variables

This section is empty.

Functions

func Walk

func Walk(c *config.Config, root string, f WalkFunc)

Walk traverses a directory tree. In each directory, Walk parses existing build files. In directories that Gazelle was asked to update (c.Dirs), Walk also parses source files and infers build information.

c is the base configuration for the repository. c may be copied and modified by directives found in build files.

root is an absolute file path to the directory to traverse.

f is a function that will be called for each visited directory.

Types

type GoTarget

type GoTarget struct {
	Sources, Imports PlatformStrings
	COpts, CLinkOpts PlatformStrings
	Cgo              bool
}

GoTarget contains metadata about a buildable Go target in a package.

func (*GoTarget) HasGo

func (t *GoTarget) HasGo() bool

type Package

type Package struct {
	// Name is the symbol found in package declarations of the .go files in
	// the package. It does not include the "_test" suffix from external tests.
	Name string

	// Dir is an absolute path to the directory that contains the package.
	Dir string

	// Rel is the relative path to the package directory from the repository
	// root. If the directory is the repository root itself, Rel is empty.
	// Components in Rel are separated with slashes.
	Rel string

	// ImportPath is the string used to import this package in Go.
	ImportPath string

	Library, Binary, Test, XTest GoTarget
	Proto                        ProtoTarget

	HasTestdata bool
}

Package contains metadata about a Go package extracted from a directory. It fills a similar role to go/build.Package, but it separates files by target instead of by type, and it supports multiple platforms.

func EmptyPackage

func EmptyPackage(c *config.Config, dir, rel string) *Package

EmptyPackage returns an empty package. The package name and import path are inferred from the directory name and configuration. This is useful for deleting rules in directories which no longer have source files.

func (*Package) IsCommand

func (p *Package) IsCommand() bool

IsCommand returns true if the package name is "main".

type PlatformStrings

type PlatformStrings struct {
	// Generic is a list of strings not specific to any platform.
	Generic []string

	// OS is a map from OS name (anything in config.KnownOSs) to
	// OS-specific strings.
	OS map[string][]string

	// Arch is a map from architecture name (anything in config.KnownArchs) to
	// architecture-specific strings.
	Arch map[string][]string

	// Platform is a map from platforms to OS and architecture-specific strings.
	Platform map[config.Platform][]string
}

PlatformStrings contains a set of strings associated with a buildable Go target in a package. This is used to store source file names, import paths, and flags.

Strings are stored in four sets: generic strings, OS-specific strings, arch-specific strings, and OS-and-arch-specific strings. A string may not be duplicated within a list or across sets; however, a string may appear in more than one list within a set (e.g., in "linux" and "windows" within the OS set). Strings within each list should be sorted, though this may not be relied upon.

func (*PlatformStrings) HasGo

func (ps *PlatformStrings) HasGo() bool

func (*PlatformStrings) IsEmpty

func (ps *PlatformStrings) IsEmpty() bool

func (*PlatformStrings) MapSlice

func (ps *PlatformStrings) MapSlice(f func([]string) ([]string, error)) (PlatformStrings, []error)

MapSlice applies a function that processes slices of strings to the strings in "ps" and returns a new PlatformStrings with the results.

type ProtoTarget

type ProtoTarget struct {
	Sources, Imports PlatformStrings
	HasServices      bool

	// HasPbGo indicates whether unexcluded .pb.go files are present in the
	// same package. They will not be in this target's sources.
	HasPbGo bool
}

ProtoTarget contains metadata about proto files in a package.

func (*ProtoTarget) HasProto

func (t *ProtoTarget) HasProto() bool

type WalkFunc

type WalkFunc func(dir, rel string, c *config.Config, pkg *Package, oldFile *bf.File, isUpdateDir bool)

A 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.

pkg contains information about how to build source code in the directory. Will be nil for directories that don't contain buildable code, directories that Gazelle was not asked update, and directories where Walk encountered errors.

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

isUpdateDir is true for directories that Gazelle was asked to update.

Jump to

Keyboard shortcuts

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