"tests for run_binary" load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test") load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//lib:run_binary.bzl", "run_binary") sh_binary( name = "expansions_sh", srcs = [":expansions.sh"], ) write_file( name = "gen_src_1", out = "src_1", content = ["src1"], ) # target-under-test run_binary( name = "expansions", srcs = [ ":gen_src_1", ], outs = ["expansions_out"], args = [ "$@", "$(@D)", "$(rootpath :gen_src_1)", "$(rootpaths :gen_src_1)", "$(execpath :gen_src_1)", "$(execpaths :gen_src_1)", "$(rlocationpath :gen_src_1)", "$(rlocationpaths :gen_src_1)", "$(location :gen_src_1)", "$(locations :gen_src_1)", # Bazel built-in pre-defined variables # https://bazel.build/reference/be/make-variables#predefined_variables "$(COMPILATION_MODE)", "$(BINDIR)", "$(GENDIR)", "$(TARGET_CPU)", # Additional variables handled by aspect_bazel_lib expand_variables # used by run_binary # https://docs.aspect.build/rules/aspect_bazel_lib/docs/expand_expansions#expand_variables "$(BUILD_FILE_PATH)", "$(VERSION_FILE)", "$(INFO_FILE)", "$(TARGET)", "$(WORKSPACE)", ], execution_requirements = { "no-cache": "1", }, progress_message = "doing some work to make %{output}", tool = ":expansions_sh", # May introduce non-determinism; use with care! # See e.g. https://github.com/bazelbuild/bazel/issues/4912 use_default_shell_env = True, ) diff_test( name = "expansions_golden_test", file1 = ":expansions_out", file2 = select({ "@aspect_bazel_lib//lib:bzlmod": "expansions_golden_bzlmod", "//conditions:default": "expansions_golden", }), )