Skip to content

Commit

Permalink
Add a new RunBazeliskWithArgsFunc entry point. (#358)
Browse files Browse the repository at this point in the history
This entry point is useful for consumers that need to set different arguments
depending on the Bazel version, e.g. if an option only exists in a recent
version.
  • Loading branch information
tjgq authored Sep 6, 2022
1 parent cc9d95a commit 31cf2a3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,18 @@ var (
fileConfigOnce sync.Once
)

// ArgsFunc is a function that receives a resolved Bazel version and returns the arguments to invoke
// Bazel with.
type ArgsFunc func(resolvedBazelVersion string) []string

// RunBazelisk runs the main Bazelisk logic for the given arguments and Bazel repositories.
func RunBazelisk(args []string, repos *Repositories) (int, error) {
return RunBazeliskWithArgsFunc(func(_ string) []string { return args }, repos)
}

// RunBazeliskWithArgsFunc runs the main Bazelisk logic for the given ArgsFunc and Bazel
// repositories.
func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error) {
httputil.UserAgent = getUserAgent()

bazeliskHome := GetEnvOrConfig("BAZELISK_HOME")
Expand Down Expand Up @@ -104,6 +114,8 @@ func RunBazelisk(args []string, repos *Repositories) (int, error) {
}
}

args := argsFunc(resolvedBazelVersion)

// --print_env must be the first argument.
if len(args) > 0 && args[0] == "--print_env" {
// print environment variables for sub-processes
Expand Down

0 comments on commit 31cf2a3

Please sign in to comment.