bazel

package
v0.50.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 289

Documentation

Overview

Package bazel provides utilities for interacting with the surrounding Bazel environment.

Index

Constants

View Source
const (
	RUNFILES_MANIFEST_FILE = "RUNFILES_MANIFEST_FILE"
	RUNFILES_DIR           = "RUNFILES_DIR"
)
View Source
const TEST_SRCDIR = "TEST_SRCDIR"
View Source
const TEST_TMPDIR = "TEST_TMPDIR"
View Source
const TEST_WORKSPACE = "TEST_WORKSPACE"

Variables

This section is empty.

Functions

func FindBinary deprecated added in v0.10.0

func FindBinary(pkg, name string) (string, bool)

FindBinary returns an absolute path to the binary built from a go_binary rule in the given package with the given name. FindBinary is similar to Runfile, but it accounts for varying configurations and file extensions, which may cause the binary to have different paths on different platforms.

FindBinary may be called from tests invoked with 'bazel test' and binaries invoked with 'bazel run'. On Windows, only tests invoked with 'bazel test' are supported.

Deprecated: Use runfiles.Rlocation instead. The path argument can be obtained by passing `$(rlocationpath //pkg:name)` to the `go_*` target via `args`, `env` or `x_defs` (the latter is also available on `go_library`). This avoids hardcoding the package and name of the binary in the source code.

func NewTmpDir

func NewTmpDir(prefix string) (string, error)

NewTmpDir creates a new temporary directory in TestTmpDir().

func Runfile deprecated

func Runfile(path string) (string, error)

Runfile returns an absolute path to the file named by "path", which should be a relative path from the workspace root to the file within the bazel workspace.

Runfile may be called from tests invoked with 'bazel test' and binaries invoked with 'bazel run'. On Windows, only tests invoked with 'bazel test' are supported.

Deprecated: Use github.com/bazelbuild/rules_go/go/runfiles instead for cross-platform support matching the behavior of the Bazel-provided runfiles libraries.

func RunfilesPath

func RunfilesPath() (string, error)

RunfilesPath return the path to the runfiles tree. It will return an error if there is no runfiles tree, for example because the executable is run on Windows or was not invoked with 'bazel test' or 'bazel run'.

func SetDefaultTestWorkspace

func SetDefaultTestWorkspace(w string)

SetDefaultTestWorkspace allows you to set a fake value for the environment variable TEST_WORKSPACE if it is not defined. This is useful when running tests on the command line and not through Bazel.

func SpliceDelimitedOSArgs added in v0.28.0

func SpliceDelimitedOSArgs(begin, end string) ([]string, error)

SpliceDelimitedOSArgs is a utility function that scans the os.Args list for entries delimited by the begin and end delimiters (typically the values "-begin_files" and "-end_files" are used). Entries between these delimiters are spliced out of from os.Args and returned to the caller. If the ordering of -begin_files or -end_files is malformed, error is returned.

func TestTmpDir

func TestTmpDir() string

TestTmpDir returns the path the Bazel test temp directory. If TEST_TMPDIR is not defined, it returns the OS default temp dir.

func TestWorkspace

func TestWorkspace() (string, error)

TestWorkspace returns the name of the Bazel workspace for this test. TestWorkspace returns an error if the TEST_WORKSPACE environment variable was not set or SetDefaultTestWorkspace was not called.

Types

type RunfileEntry deprecated added in v0.17.8

type RunfileEntry struct {
	// Workspace is the bazel workspace the file came from. For example,
	// this would be "io_bazel_rules_go" for a file in rules_go.
	Workspace string

	// ShortPath is a relative, slash-separated path from the workspace root
	// to the file. For non-binary files, this may be passed to Runfile
	// to locate a file.
	ShortPath string

	// Path is an absolute path to the file.
	Path string
}

A RunfileEntry describes a runfile.

Deprecated: See comment on ListRunfiles.

func ListRunfiles deprecated added in v0.17.8

func ListRunfiles() ([]RunfileEntry, error)

ListRunfiles returns a list of available runfiles.

Deprecated: Use fs.Glob or fs.WalkDir on the fs.FS implementation provided by runfiles.New() instead.

Jump to

Keyboard shortcuts

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