<commit_before>load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

def _serialize_file(file):
    """Serializes a file into a struct that matches the `BazelFileInfo` type in the
      packager implementation. Useful for transmission of such information."""

    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."""
    expanded_location_value = ctx.expand_location(value, targets = ctx.attr.data)

    # Note: `expand_make_variables` is deprecated but there is no reasonable replacement
    # yet. It's also still discussed whether the deprecation was reasonable to begin with:
    # https://github.com/bazelbuild/bazel/issues/5859. If this ever gets deleted, we can
    # 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 _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 <label>`). Note that the same would not work with
    # `ctx.expand_location` as a `sh_binary` exposes multiple files causing an error like:
    #  -->  `expression expands to more than one file, please use $(locations ...)`.
    # The Bazel command helper utility instead (which is also used by the genrule internally),
    # will be able to determine the executable (based on the current exec platform) and expand it.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java;l=175-199;drc=2255ce4165f936f695111020fa664b259a875c4a.
    inputs, resolved_bash_command, manifests = ctx.resolve_command(
        command = command,
        attribute = "command (%s)" % command,
        expand_locations = True,
        make_variables = ctx.var,
        tools = ctx.attr.data,
    )

    # If the resolved command does not have three arguments, then there were too many arguments
    # and Bazel extracted the command into a dedicated Bash script that we cannot read here.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/BashCommandConstructor.java;l=40;drc=2255ce4165f936f695111020fa664b259a875c4a.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java;l=275-282;drc=2255ce4165f936f695111020fa664b259a875c4a.
    if len(resolved_bash_command) != 3:
        fail("Test command too long. Please use a shorter one, or extract this " +
             "into a dedicated script: %s" % command)

    # The third argument of the resolved `bash -c` command will hold the actually expanded command.
    # We extract the command since we were only interested in the proper expansion of tools.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/BashCommandConstructor.java;l=40;drc=2255ce4165f936f695111020fa664b259a875c4a.
    resolved_command = resolved_bash_command[2].split(" ")<commit_msg>build: fix buildifier lint errors in `index.bzl` for `integration` rule<commit_after>load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")

def _serialize_file(file):
    """Serializes a file into a struct that matches the `BazelFileInfo` type in the
      packager implementation. Useful for transmission of such information."""

    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."""
    expanded_location_value = ctx.expand_location(value, targets = ctx.attr.data)

    # Note: `expand_make_variables` is deprecated but there is no reasonable replacement
    # yet. It's also still discussed whether the deprecation was reasonable to begin with:
    # https://github.com/bazelbuild/bazel/issues/5859. If this ever gets deleted, we can
    # 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 _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 <label>`). Note that the same would not work with
    # `ctx.expand_location` as a `sh_binary` exposes multiple files causing an error like:
    #  -->  `expression expands to more than one file, please use $(locations ...)`.
    # The Bazel command helper utility instead (which is also used by the genrule internally),
    # will be able to determine the executable (based on the current exec platform) and expand it.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java;l=175-199;drc=2255ce4165f936f695111020fa664b259a875c4a.
    _, resolved_bash_command, _ = ctx.resolve_command(
        command = command,
        attribute = "command (%s)" % command,
        expand_locations = True,
        make_variables = ctx.var,
        tools = ctx.attr.data,
    )

    # If the resolved command does not have three arguments, then there were too many arguments
    # and Bazel extracted the command into a dedicated Bash script that we cannot read here.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/BashCommandConstructor.java;l=40;drc=2255ce4165f936f695111020fa664b259a875c4a.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java;l=275-282;drc=2255ce4165f936f695111020fa664b259a875c4a.
    if len(resolved_bash_command) != 3:
        fail("Test command too long. Please use a shorter one, or extract this " +
             "into a dedicated script: %s" % command)

    # The third argument of the resolved `bash -c` command will hold the actually expanded command.
    # We extract the command since we were only interested in the proper expansion of tools.
    # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/BashCommandConstructor.java;l=40;drc=2255ce4165f936f695111020fa664b259a875c4a.
    resolved_command = resolved_bash_command[2].split(" ")
{'fraction_non_alphanumeric': 0.09342184671092335, 'fraction_numerical': 0.03427881713940857, 'mean_word_length': 4.086556169429097, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4482579', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2412, 'n_words': 759}