core

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 26 Imported by: 5

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)

func MakeDefaultConfig added in v1.18.0

func MakeDefaultConfig() config.Config

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.

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 Commit added in v1.17.0

type Commit struct {
	SHA     string         `json:"sha"`
	PARENTS []ParentCommit `json:"parents"`
}

type CommitRepo

type CommitRepo interface {
	// GetLastGreenCommit returns the most recent commit at which a Bazel binary passed a specific Bazel CI pipeline.
	// If downstreamGreen is true, the pipeline is https://buildkite.com/bazel/bazel-at-head-plus-downstream, otherwise
	// it's https://buildkite.com/bazel/bazel-bazel
	GetLastGreenCommit(bazeliskHome string, downstreamGreen bool) (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 CompareResponse added in v1.17.0

type CompareResponse struct {
	Commits         []Commit `json:"commits"`
	BaseCommit      Commit   `json:"base_commit"`
	MergeBaseCommit Commit   `json:"merge_base_commit"`
}

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 ParentCommit added in v1.17.0

type ParentCommit struct {
	SHA string `json:"sha"`
}

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