diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8e162c41..aeacecdb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -73,7 +73,7 @@ jobs: if: always() working-directory: test run: | - echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)" + echo "LOGS_PATH=$(readlink -f bazel-testlogs)" | tee $GITHUB_OUTPUT id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() @@ -124,15 +124,14 @@ jobs: working-directory: test shell: bash run: | - LOGS_TAR=$PWD/logs.tar - cd bazel-testlogs - tar -cf $LOGS_TAR * + echo "LOGS_PATH=$(bazel info bazel-testlogs)" | tee $GITHUB_OUTPUT + id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() uses: actions/upload-artifact@v3 with: - name: bazel-testlogs-windows-${{matrix.otp}} - path: test/logs.tar + name: bazel-testlogs-bzlmod-windows-${{matrix.otp}} + path: ${{ steps.resolve-test-logs-path.outputs.LOGS_PATH }}/* test-bzlmod: runs-on: ubuntu-20.04 strategy: @@ -156,7 +155,7 @@ jobs: if: always() working-directory: test run: | - echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)" + echo "LOGS_PATH=$(readlink -f bazel-testlogs)" | tee $GITHUB_OUTPUT id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() @@ -200,15 +199,14 @@ jobs: working-directory: test shell: bash run: | - LOGS_TAR=$PWD/logs.tar - cd bazel-testlogs - tar -cf $LOGS_TAR * + echo "LOGS_PATH=$(bazel info bazel-testlogs)" | tee $GITHUB_OUTPUT + id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() uses: actions/upload-artifact@v3 with: name: bazel-testlogs-bzlmod-windows-${{matrix.otp}} - path: test/logs.tar + path: ${{ steps.resolve-test-logs-path.outputs.LOGS_PATH }}/* test-bzlmod-internal-erlang: runs-on: ubuntu-20.04 steps: @@ -240,7 +238,7 @@ jobs: if: always() working-directory: test run: | - echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)" + echo "LOGS_PATH=$(readlink -f bazel-testlogs)" | tee $GITHUB_OUTPUT id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() @@ -342,7 +340,7 @@ jobs: if: always() working-directory: test run: | - echo "::set-output name=LOGS_PATH::$(readlink -f bazel-testlogs)" + echo "LOGS_PATH=$(readlink -f bazel-testlogs)" | tee $GITHUB_OUTPUT id: resolve-test-logs-path - name: CAPTURE TEST LOGS if: always() diff --git a/MODULE.bazel b/MODULE.bazel index 96f2ace9..2fadd38a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -41,8 +41,8 @@ erlang_package.hex_package( use_repo( erlang_package, "getopt_src", - "xref_runner_src", "thoas", + "xref_runner_src", ) erlang_config_extension = use_extension( diff --git a/erlang_app_info.bzl b/erlang_app_info.bzl index 0d485153..3e820d1e 100644 --- a/erlang_app_info.bzl +++ b/erlang_app_info.bzl @@ -1,3 +1,5 @@ +load("//transitions:beam_transition.bzl", "beam_transition") + ErlangAppInfo = provider( doc = "Compiled Erlang Application", fields = { @@ -62,11 +64,17 @@ erlang_app_info = rule( "extra_apps": attr.string_list(), "hdrs": attr.label_list(allow_files = True), "app": attr.label(allow_files = [".app"]), - "beam": attr.label_list(allow_files = [".beam", ".appup"]), + "beam": attr.label_list( + allow_files = [".beam", ".appup"], + cfg = beam_transition, + ), "priv": attr.label_list(allow_files = True), "license_files": attr.label_list(allow_files = True), "srcs": attr.label_list(allow_files = True), "deps": attr.label_list(providers = [ErlangAppInfo]), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, provides = [ErlangAppInfo], ) diff --git a/gazelle/erl_attrs_to_json/BUILD.bazel b/gazelle/erl_attrs_to_json/BUILD.bazel index 3cb59b94..3b72adb1 100644 --- a/gazelle/erl_attrs_to_json/BUILD.bazel +++ b/gazelle/erl_attrs_to_json/BUILD.bazel @@ -2,6 +2,7 @@ load("@rules_erlang//:erlang_app.bzl", "erlang_app", "test_erlang_app") load("//:escript.bzl", "escript_archive") APP_NAME = "erl_attrs_to_json" + APP_VERSION = "1.0.0" DEPS = ["@thoas//:erlang_app"] diff --git a/private/ct.bzl b/private/ct.bzl index dbfa749b..ef92e22c 100644 --- a/private/ct.bzl +++ b/private/ct.bzl @@ -27,6 +27,7 @@ load( "erlang_dirs", "maybe_install_erlang", ) +load("//transitions:beam_transition.bzl", "beam_transition") def sanitize_sname(s): return s.replace("@", "-").replace(".", "_") @@ -336,6 +337,7 @@ ct_test = rule( "compiled_suites": attr.label_list( allow_files = [".beam"], mandatory = True, + cfg = beam_transition, ), "ct_hooks": attr.string_list(), "ct_run_extra_args": attr.string_list(), @@ -350,6 +352,9 @@ ct_test = rule( default = "group", values = ["group", "case"], ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], test = True, diff --git a/private/dialyze.bzl b/private/dialyze.bzl index b6df475b..1696d9e0 100644 --- a/private/dialyze.bzl +++ b/private/dialyze.bzl @@ -7,6 +7,7 @@ load("//:erlang_app_info.bzl", "ErlangAppInfo") load("//:util.bzl", "path_join", "windows_path") load(":util.bzl", "erl_libs_contents") load(":ct.bzl", "code_paths", "unique_short_dirnames") +load("//transitions:beam_transition.bzl", "beam_transition") def _impl(ctx): if ctx.attr.target == None and len(ctx.attr.beam) == 0: @@ -114,6 +115,7 @@ dialyze_test = rule( ), "beam": attr.label_list( allow_files = [".beam"], + cfg = beam_transition, ), "target": attr.label( providers = [ErlangAppInfo], @@ -129,6 +131,9 @@ dialyze_test = rule( ], ), "warnings_as_errors": attr.bool(default = True), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], test = True, diff --git a/private/erlang_bytecode.bzl b/private/erlang_bytecode.bzl index 93615c35..35de899a 100644 --- a/private/erlang_bytecode.bzl +++ b/private/erlang_bytecode.bzl @@ -1,6 +1,7 @@ load("//:erlang_app_info.bzl", "ErlangAppInfo") load("//:util.bzl", "path_join") load(":util.bzl", "erl_libs_contents") +load("//transitions:beam_transition.bzl", "beam_transition") load( "//tools:erlang_toolchain.bzl", "erlang_dirs", @@ -146,14 +147,11 @@ fi erlang_bytecode = rule( implementation = _impl, + cfg = beam_transition, attrs = { "compile_first": attr.label( executable = True, - # I would have thought this should be "exec", since this is run - # in the execution environment. However, it's an ecript needing - # beam, and "target" allows it to match the toolchains for this - # rule. - cfg = "target", + cfg = "exec", ), "app_name": attr.string(), "hdrs": attr.label_list( @@ -165,6 +163,7 @@ erlang_bytecode = rule( ), "beam": attr.label_list( allow_files = [".beam"], + cfg = beam_transition, ), "deps": attr.label_list( providers = [ErlangAppInfo], @@ -176,6 +175,9 @@ erlang_bytecode = rule( "dest": attr.string( default = "ebin", ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], ) diff --git a/private/erlang_bytecode2.bzl b/private/erlang_bytecode2.bzl index cc1a657d..6615cdcb 100644 --- a/private/erlang_bytecode2.bzl +++ b/private/erlang_bytecode2.bzl @@ -2,6 +2,7 @@ load("//:erlang_app_info.bzl", "ErlangAppInfo", "flat_deps") load("//:util.bzl", "path_join") load(":erlang_bytecode.bzl", "unique_dirnames") load(":util.bzl", "erl_libs_contents") +load("//transitions:beam_transition.bzl", "beam_transition") load( "//tools:erlang_toolchain.bzl", "erlang_dirs", @@ -122,6 +123,7 @@ fi erlang_bytecode = rule( implementation = _impl, + cfg = beam_transition, attrs = { "app_name": attr.string(), "hdrs": attr.label_list( @@ -133,6 +135,7 @@ erlang_bytecode = rule( ), "beam": attr.label_list( allow_files = [".beam"], + cfg = beam_transition, ), "deps": attr.label_list( providers = [ErlangAppInfo], @@ -146,6 +149,9 @@ erlang_bytecode = rule( "outs": attr.output_list( mandatory = True, ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], ) diff --git a/private/escript_archive.bzl b/private/escript_archive.bzl index 746bac54..a93c2ad8 100644 --- a/private/escript_archive.bzl +++ b/private/escript_archive.bzl @@ -12,6 +12,10 @@ load( "//:util.bzl", "path_join", ) +load( + "//transitions:beam_transition.bzl", + "beam_transition", +) load( ":util.bzl", "additional_file_dest_relative_path", @@ -137,10 +141,16 @@ escript_archive = rule( ), "srcs": attr.label_list(allow_files = [".erl"]), "hdrs": attr.label_list(allow_files = [".hrl"]), - "beam": attr.label_list(allow_files = [".beam"]), + "beam": attr.label_list( + allow_files = [".beam"], + cfg = beam_transition, + ), "app": attr.label(providers = [ErlangAppInfo]), "flat": attr.bool(), "drop_hrl": attr.bool(), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], executable = True, diff --git a/private/escript_flat.bzl b/private/escript_flat.bzl index 0c630146..c1ca4cbf 100644 --- a/private/escript_flat.bzl +++ b/private/escript_flat.bzl @@ -3,6 +3,10 @@ load( "erlang_dirs", "maybe_install_erlang", ) +load( + "//transitions:beam_transition.bzl", + "beam_transition", +) def _impl(ctx): out = ctx.actions.declare_file(ctx.attr.out if ctx.attr.out != "" else ctx.label.name) @@ -27,7 +31,7 @@ halt(). body = body, )) - (erlang_home, erlang_release_dir, runfiles) = erlang_dirs(ctx) + (erlang_home, _, runfiles) = erlang_dirs(ctx) inputs = depset( direct = ctx.files.src + ctx.files.beam, @@ -63,8 +67,12 @@ escript_flat = rule( ), "beam": attr.label( allow_single_file = [".beam"], + cfg = beam_transition, ), "out": attr.string(), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], ) diff --git a/private/eunit.bzl b/private/eunit.bzl index 7a5adb35..17daf6e4 100644 --- a/private/eunit.bzl +++ b/private/eunit.bzl @@ -1,13 +1,16 @@ load( "//:erlang_app_info.bzl", "ErlangAppInfo", - "flat_deps", ) load( "//:util.bzl", "path_join", "windows_path", ) +load( + "//transitions:beam_transition.bzl", + "beam_transition", +) load( ":util.bzl", "erl_libs_contents", @@ -222,6 +225,7 @@ eunit_test = rule( "is_windows": attr.bool(mandatory = True), "compiled_suites": attr.label_list( allow_files = [".beam"], + cfg = beam_transition, ), "eunit_mods": attr.string_list(), "target": attr.label(providers = [ErlangAppInfo]), @@ -234,6 +238,9 @@ eunit_test = rule( ), "tools": attr.label_list(), "test_env": attr.string_dict(), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), }, toolchains = ["//tools:toolchain_type"], test = True, diff --git a/test/.bazelrc b/test/.bazelrc index 1214f439..fa25f56f 100644 --- a/test/.bazelrc +++ b/test/.bazelrc @@ -1,6 +1,9 @@ build --enable_bzlmod build --incompatible_strict_action_env +# https://github.com/bazelbuild/bazel/issues/17081 +build --use_top_level_targets_for_symlinks=false + build --flag_alias=erlang_home=@rules_erlang//:erlang_home build --flag_alias=erlang_version=@rules_erlang//:erlang_version diff --git a/test/BUILD.bazel b/test/BUILD.bazel index 48a435a3..ab1f9767 100644 --- a/test/BUILD.bazel +++ b/test/BUILD.bazel @@ -5,6 +5,7 @@ platform( name = "erlang_internal_platform", constraint_values = [ "@erlang_config//:erlang_internal", + "@erlang_config//:erlang_26", ], parents = ["@rbe//config:platform"], ) diff --git a/test/erl_attrs_to_json/BUILD.bazel b/test/erl_attrs_to_json/BUILD.bazel index 3f7b19ed..02456c97 100644 --- a/test/erl_attrs_to_json/BUILD.bazel +++ b/test/erl_attrs_to_json/BUILD.bazel @@ -40,8 +40,8 @@ ct_suite( name = "erl_attrs_to_json_SUITE", size = "small", data = [ - "test/basic.hrl", "test/basic.erl", + "test/basic.hrl", "test/test.erl", ], deps = [ diff --git a/test/gazelle/BUILD.bazel b/test/gazelle/BUILD.bazel index afdf5e54..6bf9ec66 100644 --- a/test/gazelle/BUILD.bazel +++ b/test/gazelle/BUILD.bazel @@ -14,9 +14,9 @@ go_test( data = [ ":gazelle_erlang_binary", "@rules_erlang//gazelle:dot_app_to_json", - "@rules_erlang//gazelle/erl_attrs_to_json:erl_attrs_to_json", "@rules_erlang//gazelle:hex_metadata_config_to_json", "@rules_erlang//gazelle:rebar_config_to_json", + "@rules_erlang//gazelle/erl_attrs_to_json", ] + glob(["testdata/**"]), tags = ["manual"], deps = [ @@ -103,6 +103,6 @@ EOF """, executable = True, tools = [ - "@rules_erlang//gazelle/erl_attrs_to_json:erl_attrs_to_json", + "@rules_erlang//gazelle/erl_attrs_to_json", ], ) diff --git a/transitions/BUILD.bazel b/transitions/BUILD.bazel new file mode 100644 index 00000000..129c4c3a --- /dev/null +++ b/transitions/BUILD.bazel @@ -0,0 +1,7 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + +bool_flag( + name = "enable", + build_setting_default = True, + visibility = ["//visibility:public"], +) diff --git a/transitions/beam_transition.bzl b/transitions/beam_transition.bzl new file mode 100644 index 00000000..aca1ed6d --- /dev/null +++ b/transitions/beam_transition.bzl @@ -0,0 +1,11 @@ +def _impl(settings, attr): + _ignore = (attr) + if not settings["@rules_erlang//transitions:enable"]: + return {} + return {"//command_line_option:cpu": "beam"} + +beam_transition = transition( + implementation = _impl, + inputs = ["@rules_erlang//transitions:enable"], + outputs = ["//command_line_option:cpu"], +)