diff --git a/bazel/integration/index.bzl b/bazel/integration/index.bzl index c1bf3693b0..5f2bff31dd 100644 --- a/bazel/integration/index.bzl +++ b/bazel/integration/index.bzl @@ -6,6 +6,14 @@ def _serialize_file(file): return struct(path = file.path, shortPath = file.short_path) +def _create_expanded_value(value, isExpanded): + """Creates a JSON serializable dictionary matching the `BazelExpandedValue` type in + the test runner.""" + return { + "value": value, + "containsExpansion": isExpanded, + } + def _serialize_and_expand_value(ctx, value, description): """Expands Bazel make variable and location expressions for the given value. Returns a JSON serializable dictionary matching the `BazelExpandedValue` type in the test runner.""" @@ -17,14 +25,50 @@ def _serialize_and_expand_value(ctx, value, description): # directly use `ctx.var` but would have switch users from e.g. `$(VAR)` to `{VAR}`. expanded_make_value = ctx.expand_make_variables(description, expanded_location_value, {}) - return { - "value": expanded_make_value, - "containsExpansion": expanded_make_value != value, - } + return _create_expanded_value(expanded_make_value, expanded_make_value != value) + +def _expand_and_split_command(ctx, command): + """Expands a command using the Bazel command helper. The command is then split into the + binary and its arguments, matching the runner `[BazelExpandedValue, ...string[]]` type.""" + + # Instead of manually resolving the command using e.g. `ctx.expand_location`, we use + # the Bazel `resolve_command` helper which internally follows the semantics of a `genrule`, + # allowing for better expansion/resolution of tools provided in the `data` attribute. + # This is necessary so that e.g. executables from a `sh_binary` can be conveniently + # expanded through `$(rootpath