core

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 24 Imported by: 4

Documentation

Overview

Package core contains the core Bazelisk logic, as well as abstractions for Bazel repositories.

Index

Constants

View Source
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

View Source
var (
	// BazeliskVersion is filled in via x_defs when building a release.
	BazeliskVersion = "development"
)

Functions

func BuildURLFromFormat added in v1.17.0

func BuildURLFromFormat(config config.Config, formatURL, version string) (string, error)

BuildURLFromFormat returns a Bazel download URL based on formatURL.

func GetBazelVersion added in v1.20.0

func GetBazelVersion(config config.Config) (string, error)

GetBazelVersion returns the Bazel version that should be used.

func MakeDefaultConfig added in v1.18.0

func MakeDefaultConfig() config.Config

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.

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.

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.

func RunBazeliskWithArgsFuncAndConfigAndOut added in v1.20.0

func RunBazeliskWithArgsFuncAndConfigAndOut(argsFunc ArgsFunc, repos *Repositories, config config.Config, out 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.

Types

type ArgsFunc added in v1.14.0

type ArgsFunc func(resolvedBazelVersion string) []string

ArgsFunc is a function that receives a resolved Bazel version and returns the arguments to invoke Bazel with.

type CandidateRepo

type CandidateRepo interface {
	// GetCandidateVersions returns the versions of all available release candidates.
	GetCandidateVersions(bazeliskHome string) ([]string, error)

	// DownloadCandidate downloads the given Bazel release candidate into the specified location and returns the absolute path.
	DownloadCandidate(version, destDir, destFile string, config config.Config) (string, error)
}

CandidateRepo represents a repository that stores Bazel release candidates.

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

type DownloadFunc func(destDir, destFile string) (string, error)

DownloadFunc downloads a specific Bazel binary to the given location and returns the absolute path.

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 ReleaseFilter added in v1.13.2

type ReleaseFilter func(matchesSoFar int, currentVersion string) bool

ReleaseFilter filters Bazel versions based on specific criteria.

type ReleaseRepo

type ReleaseRepo interface {
	// GetReleaseVersions returns a list of all available release versions that match the given filter function.
	// Warning: the filter only works reliably if the versions are processed in descending order!
	GetReleaseVersions(bazeliskHome string, filter ReleaseFilter) ([]string, error)

	// DownloadRelease downloads the given Bazel version into the specified location and returns the absolute path.
	DownloadRelease(version, destDir, destFile string, config config.Config) (string, error)
}

ReleaseRepo represents a repository that stores LTS Bazel releases.

type Repositories

type Repositories struct {
	Releases   ReleaseRepo
	Candidates CandidateRepo
	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(releases ReleaseRepo, candidates CandidateRepo, fork ForkRepo, commits CommitRepo, rolling RollingRepo, supportsBaseURL 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.

Jump to

Keyboard shortcuts

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