From b7c0ac33c9bb06c9b78f8f6555f1399a72a1477a Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Fri, 10 Jun 2022 16:35:53 -0700 Subject: [PATCH] Add `PRE_BAZEL_INIT` variable to run a command before Bazel server starts. This is useful for initializing things that the Bazel server container requires before starting in the first place. PiperOrigin-RevId: 454265814 --- tools/bazel.mk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/bazel.mk b/tools/bazel.mk index 6a5135dc3..bbbfbc9da 100644 --- a/tools/bazel.mk +++ b/tools/bazel.mk @@ -25,6 +25,8 @@ ## DOCKER_RUN_OPTIONS - Options for the container (default: --privileged, required for tests). ## DOCKER_NAME - The container name (default: gvisor-bazel-HASH). ## DOCKER_PRIVILEGED - Docker privileged flags (default: --privileged). +## PRE_BAZEL_INIT - If set, run this command with bash outside the Bazel +## server container. ## BAZEL_CACHE - The bazel cache directory (default: detected). ## GCLOUD_CONFIG - The gcloud config directory (detect: detected). ## DOCKER_SOCKET - The Docker socket (default: detected). @@ -55,6 +57,7 @@ GCLOUD_CONFIG := $(HOME)/.config/gcloud/ DOCKER_SOCKET := /var/run/docker.sock DOCKER_CONFIG := /etc/docker DEVICE_FILE ?= +PRE_BAZEL_INIT ?= ## ## Bazel helpers. @@ -152,10 +155,8 @@ endif # Add other device file, if specified. ifneq ($(DEVICE_FILE),) -ifneq (,$(wildcard $(DEVICE_FILE))) DOCKER_RUN_OPTIONS += --device "$(DEVICE_FILE):$(DEVICE_FILE)" endif -endif # Top-level functions. # @@ -188,6 +189,10 @@ bazel-image: load-default ## Ensures that the local builder exists. ifneq (true,$(shell $(wrapper echo true))) bazel-server: bazel-image ## Ensures that the server exists. +ifneq (,$(PRE_BAZEL_INIT)) + @$(call header,PRE_BAZEL_INIT) + @bash -euxo pipefail -c "$(PRE_BAZEL_INIT)" +endif @$(call header,DOCKER RUN) @docker rm -f $(DOCKER_NAME) 2>/dev/null || true @mkdir -p $(BAZEL_CACHE)