...

Text file src/edge-infra.dev/test/snapshot/snapshot.bzl

Documentation: edge-infra.dev/test/snapshot

     1"""
     2Update snapshots per go_test that uses the snapshot library.
     3Existing snapshots are passed as inputs, with its path passed as an attr.
     4Any snapshots that are created, updated, or copied by the snapshot library are
     5written to the out.path.
     6"""
     7
     8_attrs = {
     9    "snapshot_test": attr.label(
    10        executable = True,
    11        cfg = "exec",
    12        doc = "go_test rule that uses snapshots",
    13        allow_files = True,
    14    ),
    15    "srcs": attr.label_list(
    16        allow_files = True,
    17        mandatory = True,
    18        doc = "source files for go_test, snapshot dir must be included (e.g. glob([testdata/**]))",
    19    ),
    20    "snapshot_path": attr.string(
    21        mandatory = True,
    22        doc = "location where snapshots are read from and written to",
    23    ),
    24}
    25
    26def _snapshot_impl(ctx):
    27    out = ctx.actions.declare_directory(ctx.label.name)
    28    args = ctx.actions.args()
    29    args.add(out.path)
    30
    31    # set read and write paths for the snapshot lib as they will differ
    32    env_var = {}
    33    env_var["SNAPSHOT_READ"] = ctx.attr.snapshot_path
    34    env_var["SNAPSHOT_WRITE"] = out.path
    35    env_var["UPDATE_SNAPSHOTS"] = "true"
    36
    37    ctx.actions.run(
    38        arguments = [args],
    39        inputs = ctx.files.srcs,
    40        outputs = [out],
    41        env = env_var,
    42        executable = ctx.executable.snapshot_test,
    43    )
    44
    45    # TODO(wc185097_ncrvoyix): generate write_source_files inside this impl
    46
    47    return [DefaultInfo(files = depset([out]))]
    48
    49generate_snapshots = rule(
    50    implementation = _snapshot_impl,
    51    attrs = _attrs,
    52)

View as plain text