Documentation
¶
Overview ¶
Package core contains the core Bazelisk logic, as well as abstractions for Bazel repositories.
Index ¶
- Constants
- Variables
- func BuildURLFromFormat(config config.Config, formatURL, version string) (string, error)
- func ExecBazelisk(args []string, repos *Repositories) (int, error)
- func ExecBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error)
- func ExecBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, config config.Config) (int, error)
- func GetBazelVersion(config config.Config) (string, error)
- func MakeDefaultConfig() config.Config
- func RunBazelisk(args []string, repos *Repositories) (int, error)
- func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error)
- func RunBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, config config.Config) (int, error)
- func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositories, config config.Config, stdout io.Writer) (int, error)
- func RunBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repositories, config config.Config, ...) (int, error)
- func RunOrExecBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repositories, config config.Config, ...) (int, error)
- type ArgsFunc
- type BazelInstallation
- type CommitRepo
- type DownloadFunc
- type FilterOpts
- type ForkRepo
- type LTSFilter
- type LTSRepo
- type Repositories
- func (r *Repositories) DownloadFromBaseURL(baseURL, version, destDir, destFile string, config config.Config) (string, error)
- func (r *Repositories) DownloadFromFormatURL(config config.Config, formatURL, version, destDir, destFile string) (string, error)
- func (r *Repositories) ResolveVersion(bazeliskHome, fork, version string, config config.Config) (string, DownloadFunc, error)
- type RollingRepo
Constants ¶
const ( // BaseURLEnv is the name of the environment variable that stores the base URL for downloads. BaseURLEnv = "BAZELISK_BASE_URL" // FormatURLEnv is the name of the environment variable that stores the format string to generate URLs for downloads. FormatURLEnv = "BAZELISK_FORMAT_URL" )
Variables ¶
var (
// BazeliskVersion is filled in via x_defs when building a release.
BazeliskVersion = "development"
)
var IsCandidate = func(version string) bool { return strings.Contains(version, "rc") }
IsCandidate returns whether a version string is for a release candidate.
var IsRelease = func(version string) bool { return !strings.Contains(version, "rc") }
IsRelease returns whether a version string is for a final release.
Functions ¶
func BuildURLFromFormat ¶ added in v1.17.0
BuildURLFromFormat returns a Bazel download URL based on formatURL.
func ExecBazelisk ¶ added in v1.29.0
func ExecBazelisk(args []string, repos *Repositories) (int, error)
ExecBazelisk runs the main Bazelisk logic for the given arguments and Bazel repositories.
If possible (i.e. on non-Windows platforms), this will replace the current process with Bazel and will not return. On Windows, this will execute Bazel in a new process and return its exit code.
func ExecBazeliskWithArgsFunc ¶ added in v1.29.0
func ExecBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error)
ExecBazeliskWithArgsFunc runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories.
If possible (i.e. on non-Windows platforms), this will replace the current process with Bazel and will not return. On Windows, this will execute Bazel in a new process and return its exit code.
func ExecBazeliskWithArgsFuncAndConfig ¶ added in v1.29.0
func ExecBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, config config.Config) (int, error)
ExecBazeliskWithArgsFuncAndConfig runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories and config.
If possible (i.e. on non-Windows platforms), this will replace the current process with Bazel and will not return. On Windows, this will execute Bazel in a new process and return its exit code.
func GetBazelVersion ¶ added in v1.20.0
GetBazelVersion returns the Bazel version that should be used.
func MakeDefaultConfig ¶ added in v1.18.0
MakeDefaultConfig returns a config based on env and .bazeliskrc files.
func RunBazelisk ¶
func RunBazelisk(args []string, repos *Repositories) (int, error)
RunBazelisk runs the main Bazelisk logic for the given arguments and Bazel repositories.
This will run Bazel in a subprocess and return its exit code.
func RunBazeliskWithArgsFunc ¶ added in v1.14.0
func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error)
RunBazeliskWithArgsFunc runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories.
This will run Bazel in a subprocess and return its exit code.
func RunBazeliskWithArgsFuncAndConfig ¶ added in v1.18.0
func RunBazeliskWithArgsFuncAndConfig(argsFunc ArgsFunc, repos *Repositories, config config.Config) (int, error)
RunBazeliskWithArgsFuncAndConfig runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories and config.
This will run Bazel in a subprocess and return its exit code.
func RunBazeliskWithArgsFuncAndConfigAndOut ¶ added in v1.20.0
func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositories, config config.Config, stdout io.Writer) (int, error)
RunBazeliskWithArgsFuncAndConfigAndOut runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories and config, writing its stdout to the passed writer.
This will run Bazel in a subprocess and return its exit code.
func RunBazeliskWithArgsFuncAndConfigAndOutAndErr ¶ added in v1.29.0
func RunBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repositories, config config.Config, stdout, stderr io.Writer) (int, error)
RunBazeliskWithArgsFuncAndConfigAndOutAndErr runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories and config, writing its stdout and stderr to the passed writers.
This will run Bazel in a subprocess and return its exit code.
func RunOrExecBazeliskWithArgsFuncAndConfigAndOutAndErr ¶ added in v1.29.0
func RunOrExecBazeliskWithArgsFuncAndConfigAndOutAndErr(argsFunc ArgsFunc, repos *Repositories, config config.Config, stdout, stderr io.Writer, exec bool) (int, error)
RunOrExecBazeliskWithArgsFuncAndConfigAndOutAndErr runs the main Bazelisk logic for the given ArgsFunc and Bazel repositories and config.
If exec is true, this will replace the current process with Bazel and will not return (this is not possible on Windows; on Windows this will execute Bazel in a new process and return its exit code even if exec is true). `stdout` and `stderr` are not supported in exec mode.
If exec is false, this will run Bazel in a subprocess and return its exit code, writing its stdout and stderr to the passed writers if provided.
Types ¶
type ArgsFunc ¶ added in v1.14.0
ArgsFunc is a function that receives a resolved Bazel version and returns the arguments to invoke Bazel with.
type BazelInstallation ¶ added in v1.25.0
BazelInstallation provides a summary of a single install of `bazel`
func GetBazelInstallation ¶ added in v1.25.0
func GetBazelInstallation(repos *Repositories, config config.Config) (*BazelInstallation, error)
GetBazelInstallation provides a mechanism to find the `bazel` binary to execute, as well as its version
type CommitRepo ¶
type CommitRepo interface {
// GetLastGreenCommit returns the most recent commit at which a Bazel binary is successfully built.
GetLastGreenCommit(bazeliskHome string) (string, error)
// DownloadAtCommit downloads a Bazel binary built at the given commit into the specified location and returns the absolute path.
DownloadAtCommit(commit, destDir, destFile string, config config.Config) (string, error)
}
CommitRepo represents a repository that stores Bazel binaries built at specific commits. It can also return the hashes of the most recent commits that passed Bazel CI pipelines successfully.
type DownloadFunc ¶
DownloadFunc downloads a specific Bazel binary to the given location and returns the absolute path.
type FilterOpts ¶ added in v1.24.0
FilterOpts represents options relevant to filtering Bazel versions.
type ForkRepo ¶
type ForkRepo interface {
// GetVersions returns the versions of all available Bazel binaries in the given fork.
GetVersions(bazeliskHome, fork string) ([]string, error)
// DownloadVersion downloads the given Bazel binary from the specified fork into the given location and returns the absolute path.
DownloadVersion(fork, version, destDir, destFile string, config config.Config) (string, error)
}
ForkRepo represents a repository that stores a fork of Bazel (releases).
type LTSRepo ¶ added in v1.24.0
type LTSRepo interface {
// GetLTSVersions returns a list of all available LTS release (candidates) that match the given filter options.
// Warning: Filters only work reliably if the versions are processed in descending order!
GetLTSVersions(bazeliskHome string, opts *FilterOpts) ([]string, error)
// DownloadLTS downloads the given Bazel version into the specified location and returns the absolute path.
DownloadLTS(version, destDir, destFile string, config config.Config) (string, error)
}
LTSRepo represents a repository that stores LTS Bazel releases and their candidates.
type Repositories ¶
type Repositories struct {
LTS LTSRepo
Fork ForkRepo
Commits CommitRepo
Rolling RollingRepo
// contains filtered or unexported fields
}
Repositories offers access to different types of Bazel repositories, mainly for finding and downloading the correct version of Bazel.
func CreateRepositories ¶
func CreateRepositories(lts LTSRepo, fork ForkRepo, commits CommitRepo, rolling RollingRepo, supportsBaseOrFormatURL bool) *Repositories
CreateRepositories creates a new Repositories instance with the given repositories. Any nil repository will be replaced by a dummy repository that raises an error whenever a download is attempted.
func (*Repositories) DownloadFromBaseURL ¶
func (r *Repositories) DownloadFromBaseURL(baseURL, version, destDir, destFile string, config config.Config) (string, error)
DownloadFromBaseURL can download Bazel binaries from a specific URL while ignoring the predefined repositories.
func (*Repositories) DownloadFromFormatURL ¶ added in v1.17.0
func (r *Repositories) DownloadFromFormatURL(config config.Config, formatURL, version, destDir, destFile string) (string, error)
DownloadFromFormatURL can download Bazel binaries from a specific URL while ignoring the predefined repositories.
func (*Repositories) ResolveVersion ¶
func (r *Repositories) ResolveVersion(bazeliskHome, fork, version string, config config.Config) (string, DownloadFunc, error)
ResolveVersion resolves a potentially relative Bazel version string such as "latest" to an absolute version identifier, and returns this identifier alongside a function to download said version.
type RollingRepo ¶ added in v1.8.0
type RollingRepo interface {
// GetRollingVersions returns a list of all available rolling release versions.
GetRollingVersions(bazeliskHome string) ([]string, error)
// DownloadRolling downloads the given Bazel version into the specified location and returns the absolute path.
DownloadRolling(version, destDir, destFile string, config config.Config) (string, error)
}
RollingRepo represents a repository that stores rolling Bazel releases.