diff --git a/bazel_integration_test/private/bazel_binaries_script.template b/bazel_integration_test/private/bazel_binaries_script.template index 3dab7c8..a7cccdd 100644 --- a/bazel_integration_test/private/bazel_binaries_script.template +++ b/bazel_integration_test/private/bazel_binaries_script.template @@ -20,4 +20,4 @@ export BAZELISK_HOME="${PWD}" BINARY="$(rlocation {bazelisk})" || \ (echo >&2 "Failed to locate bazelisk at {bazelisk}" && exit 1) -exec "${BINARY}" "$@" +exec "${BINARY}" ${BIT_STARTUP_OPTIONS:-} "$@" diff --git a/bazel_integration_test/private/bazel_integration_test.bzl b/bazel_integration_test/private/bazel_integration_test.bzl index 64aa48f..6154ca0 100644 --- a/bazel_integration_test/private/bazel_integration_test.bzl +++ b/bazel_integration_test/private/bazel_integration_test.bzl @@ -44,11 +44,12 @@ def bazel_integration_test( workspace_files = None, tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, timeout = "long", - env = {}, + env = None, env_inherit = _DEFAULT_ENV_INHERIT, additional_env_inherit = [], bazel_binaries = None, data = None, + startup_options = "", **kwargs): """Macro that defines a set of targets for a single Bazel integration test. @@ -96,8 +97,12 @@ def bazel_integration_test( `load("@bazel_binaries//:defs.bzl", "bazel_binaries")` to your build file. data: Optional. A list of files to make present at test runtime. + startup_options: Optional. Flags that should be passed to Bazel as + startup options using the `BIT_STARTUP_OPTIONS` + environment variable. **kwargs: additional attributes like timeout and visibility """ + env = env or {} # To support clients that have not transitioned to bzlmod, we provide a # bazel_binaries implementation that works in that mode. If a client using @@ -161,6 +166,8 @@ def bazel_integration_test( if env_vars_are_rootpaths: env["ENV_VARS_TO_ABSOLUTIFY"] = " ".join(env_vars_are_rootpaths) + env["BIT_STARTUP_OPTIONS"] = startup_options + native.sh_test( name = name, srcs = [ @@ -186,6 +193,7 @@ def bazel_integration_tests( env_inherit = _DEFAULT_ENV_INHERIT, additional_env_inherit = [], bazel_binaries = None, + startup_options = "", **kwargs): """Macro that defines a set Bazel integration tests each executed with a different version of Bazel. @@ -216,6 +224,9 @@ def bazel_integration_tests( is loaded by adding `load("@bazel_binaries//:defs.bzl", "bazel_binaries")` to your build file. + startup_options: Optional. Flags that should be passed to Bazel as + startup options using the `BIT_STARTUP_OPTIONS` + environment variable. **kwargs: additional attributes like timeout and visibility """ if bazel_versions == []: @@ -236,5 +247,6 @@ def bazel_integration_tests( env_inherit = env_inherit, additional_env_inherit = additional_env_inherit, bazel_binaries = bazel_binaries, + startup_options = startup_options, **kwargs ) diff --git a/doc/rules_and_macros_overview.md b/doc/rules_and_macros_overview.md index bed5196..cd62f9f 100755 --- a/doc/rules_and_macros_overview.md +++ b/doc/rules_and_macros_overview.md @@ -37,7 +37,7 @@ default_test_runner(name, name, test_runner, bazel_version, bazel_binary, workspace_path, workspace_files, tags, timeout, env, env_inherit, additional_env_inherit, - bazel_binaries, data, kwargs) + bazel_binaries, data, startup_options, kwargs) Macro that defines a set of targets for a single Bazel integration test. @@ -65,11 +65,12 @@ default test runner is provided by the `default_test_runner` macro. | workspace_files | Optional. A list of files for the child workspace. If not specified, then it is derived from the workspace_path. | None | | tags | The Bazel tags to apply to the test declaration. | ["exclusive", "manual"] | | timeout | A valid Bazel timeout value. https://docs.bazel.build/versions/main/test-encyclopedia.html#role-of-the-test-runner | "long" | -| env | Optional. A dictionary of strings. Specifies additional environment variables to be passed to the test. | {} | +| env | Optional. A dictionary of strings. Specifies additional environment variables to be passed to the test. | None | | env_inherit | Optional. Override the env_inherit values passed to the test. Only do this if you understand what needs to be passed along. Most folks will want to use additional_env_inherit to pass additional env_inherit values. | ["SUDO_ASKPASS", "HOME", "CC"] | | additional_env_inherit | Optional. Specify additional env_inherit values that should be passed to the test. | [] | | bazel_binaries | Optional for WORKSPACE loaded repositories. Required for repositories that enable bzlmod. The value for this parameter is loaded by adding load("@bazel_binaries//:defs.bzl", "bazel_binaries") to your build file. | None | | data | Optional. A list of files to make present at test runtime. | None | +| startup_options | Optional. Flags that should be passed to Bazel as startup options using the BIT_STARTUP_OPTIONS environment variable. | "" | | kwargs | additional attributes like timeout and visibility | none | @@ -79,7 +80,8 @@ default test runner is provided by the `default_test_runner` macro.
 bazel_integration_tests(name, test_runner, bazel_versions, workspace_path, workspace_files, tags,
-                        timeout, env_inherit, additional_env_inherit, bazel_binaries, kwargs)
+                        timeout, env_inherit, additional_env_inherit, bazel_binaries, startup_options,
+                        kwargs)
 
Macro that defines a set Bazel integration tests each executed with a different version of Bazel. @@ -99,6 +101,7 @@ Macro that defines a set Bazel integration tests each executed with a different | env_inherit | Optional. Override the env_inherit values passed to the test. Only do this if you understand what needs to be passed along. Most folks will want to use additional_env_inherit to pass additional env_inherit values. | ["SUDO_ASKPASS", "HOME", "CC"] | | additional_env_inherit | Optional. Specify additional env_inherit values that should be passed to the test. | [] | | bazel_binaries | Optional for WORKSPACE loaded repositories. Required for repositories that enable bzlmod. The value for this parameter is loaded by adding load("@bazel_binaries//:defs.bzl", "bazel_binaries") to your build file. | None | +| startup_options | Optional. Flags that should be passed to Bazel as startup options using the BIT_STARTUP_OPTIONS environment variable. | "" | | kwargs | additional attributes like timeout and visibility | none |