Skip to content

Commit 42cc5b2

Browse files
authored
Allow setting the path to Bazel manually, rather than use Bazelisk. (#967)
This is sometimes desirable, e.g. when running in an airgapped environment.
1 parent 6b7cab1 commit 42cc5b2

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

cmd/rbe_configs_gen/rbe_configs_gen.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var (
3535

3636
// Optional input arguments.
3737
bazelVersion = flag.String("bazel_version", "", "(Optional) Bazel release version to generate configs for. E.g., 4.0.0. If unspecified, the latest available Bazel release is picked.")
38+
bazelPath = flag.String("bazel_path", "", "(Optional) Path to preinstalled Bazel within the container. If unspecified, Bazelisk will be downloaded and installed.")
3839

3940
// Arguments affecting output generation not specific to either C++ or Java Configs.
4041
outputTarball = flag.String("output_tarball", "", "(Optional) Path where a tarball with the generated configs will be created.")
@@ -66,6 +67,9 @@ func printFlags() {
6667
log.Printf("--exec_os=%q \\", *execOS)
6768
log.Printf("--target_os=%q \\", *targetOS)
6869
log.Printf("--bazel_version=%q \\", *bazelVersion)
70+
if len(*bazelPath) != 0 {
71+
log.Printf("--bazel_path=%q \\", *bazelPath)
72+
}
6973
if len(*outputTarball) != 0 {
7074
log.Printf("--output_tarball=%q \\", *outputTarball)
7175
}
@@ -148,6 +152,7 @@ func main() {
148152

149153
o := rbeconfigsgen.Options{
150154
BazelVersion: *bazelVersion,
155+
BazelPath: *bazelPath,
151156
ToolchainContainer: *toolchainContainer,
152157
ExecOS: *execOS,
153158
TargetOS: *targetOS,

pkg/rbeconfigsgen/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type Options struct {
3131
// BazelVersion is the version of Bazel to generate configs for. If unset, the latest Bazel
3232
// version is automatically populated into this field when Validate() is called.
3333
BazelVersion string
34+
// BazelPath is the path within the container where Bazel is preinstalled. If unspecified,
35+
// Bazelisk will be downloaded and installed.
36+
BazelPath string
3437
// ToolchainContainer is the docker image of the toolchain container to generate configs for.
3538
ToolchainContainer string
3639
// ExecOS is the OS of the toolchain container image or the OS in which the build actions will

pkg/rbeconfigsgen/rbeconfigsgen.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ func appendCppEnv(env []string, o *Options) ([]string, error) {
429429
}
430430

431431
// genCppConfigs generates C++ configs inside the running toolchain container represented by the
432-
// given docker runner according to the given options. bazeliskPath is the path to the bazelisk
432+
// given docker runner according to the given options. bazelPath is the path to the Bazel
433433
// binary inside the running toolchain container.
434434
// The return value is the path to the C++ configs tarball copied out of the toolchain container.
435-
func genCppConfigs(d *dockerRunner, o *Options, bazeliskPath string) (string, error) {
435+
func genCppConfigs(d *dockerRunner, o *Options, bazelPath string) (string, error) {
436436
if !o.GenCPPConfigs {
437437
return "", nil
438438
}
@@ -472,7 +472,7 @@ func genCppConfigs(d *dockerRunner, o *Options, bazeliskPath string) (string, er
472472
d.env = generationEnv
473473

474474
cmd := []string{
475-
bazeliskPath,
475+
bazelPath,
476476
o.CppBazelCmd,
477477
}
478478
cmd = append(cmd, o.CPPConfigTargets...)
@@ -482,7 +482,7 @@ func genCppConfigs(d *dockerRunner, o *Options, bazeliskPath string) (string, er
482482

483483
// Restore the env needed for Bazelisk.
484484
d.env = bazeliskEnv
485-
bazelOutputRoot, err := d.execCmd(bazeliskPath, "info", "output_base")
485+
bazelOutputRoot, err := d.execCmd(bazelPath, "info", "output_base")
486486
if err != nil {
487487
return "", fmt.Errorf("unable to determine the build output directory where Bazel produced C++ configs in the toolchain container: %w", err)
488488
}
@@ -992,12 +992,15 @@ func Run(o Options) error {
992992
}
993993
d.workdir = workdir(o.ExecOS)
994994

995-
bazeliskPath, err := installBazelisk(d, o.TempWorkDir, o.ExecOS)
996-
if err != nil {
997-
return fmt.Errorf("failed to install Bazelisk into the toolchain container: %w", err)
995+
bazelPath := o.BazelPath
996+
if bazelPath == "" {
997+
bazelPath, err = installBazelisk(d, o.TempWorkDir, o.ExecOS)
998+
if err != nil {
999+
return fmt.Errorf("failed to install Bazelisk into the toolchain container: %w", err)
1000+
}
9981001
}
9991002

1000-
cppConfigsTarball, err := genCppConfigs(d, &o, bazeliskPath)
1003+
cppConfigsTarball, err := genCppConfigs(d, &o, bazelPath)
10011004
if err != nil {
10021005
return fmt.Errorf("failed to generate C++ configs: %w", err)
10031006
}

0 commit comments

Comments
 (0)