Skip to content

Commit

Permalink
Allow setting the path to Bazel manually, rather than use Bazelisk. (#…
Browse files Browse the repository at this point in the history
…967)

This is sometimes desirable, e.g. when running in an airgapped environment.
  • Loading branch information
quval authored Oct 28, 2021
1 parent 6b7cab1 commit 42cc5b2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions cmd/rbe_configs_gen/rbe_configs_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (

// Optional input arguments.
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.")
bazelPath = flag.String("bazel_path", "", "(Optional) Path to preinstalled Bazel within the container. If unspecified, Bazelisk will be downloaded and installed.")

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

o := rbeconfigsgen.Options{
BazelVersion: *bazelVersion,
BazelPath: *bazelPath,
ToolchainContainer: *toolchainContainer,
ExecOS: *execOS,
TargetOS: *targetOS,
Expand Down
3 changes: 3 additions & 0 deletions pkg/rbeconfigsgen/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type Options struct {
// BazelVersion is the version of Bazel to generate configs for. If unset, the latest Bazel
// version is automatically populated into this field when Validate() is called.
BazelVersion string
// BazelPath is the path within the container where Bazel is preinstalled. If unspecified,
// Bazelisk will be downloaded and installed.
BazelPath string
// ToolchainContainer is the docker image of the toolchain container to generate configs for.
ToolchainContainer string
// ExecOS is the OS of the toolchain container image or the OS in which the build actions will
Expand Down
19 changes: 11 additions & 8 deletions pkg/rbeconfigsgen/rbeconfigsgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ func appendCppEnv(env []string, o *Options) ([]string, error) {
}

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

cmd := []string{
bazeliskPath,
bazelPath,
o.CppBazelCmd,
}
cmd = append(cmd, o.CPPConfigTargets...)
Expand All @@ -482,7 +482,7 @@ func genCppConfigs(d *dockerRunner, o *Options, bazeliskPath string) (string, er

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

bazeliskPath, err := installBazelisk(d, o.TempWorkDir, o.ExecOS)
if err != nil {
return fmt.Errorf("failed to install Bazelisk into the toolchain container: %w", err)
bazelPath := o.BazelPath
if bazelPath == "" {
bazelPath, err = installBazelisk(d, o.TempWorkDir, o.ExecOS)
if err != nil {
return fmt.Errorf("failed to install Bazelisk into the toolchain container: %w", err)
}
}

cppConfigsTarball, err := genCppConfigs(d, &o, bazeliskPath)
cppConfigsTarball, err := genCppConfigs(d, &o, bazelPath)
if err != nil {
return fmt.Errorf("failed to generate C++ configs: %w", err)
}
Expand Down

0 comments on commit 42cc5b2

Please sign in to comment.