Skip to content

rules_erlang: split hermetic_otp.patch into four upstream PRs to bazelverse/rules_erlang #3743

Open

Description

@TrapsterDK

Blocked on: bazelverse/rules_erlang#12, bazelverse/rules_erlang#14, bazelverse/rules_erlang#16 and bazelverse/rules_erlang#18 (all open). Nothing to change in-repo until one merges; then drop its hunks in a pin bump.

Problem
patches/rules_erlang/hermetic_otp.patch is applied to the pinned bazelverse/rules_erlang (RULES_ERLANG_COMMIT = 13977b3..., equal to upstream main today) by the repository rule in erlang/toolchain/repos.bzl:305. It mixes four unrelated changes. The fork's issues are disabled, so the only upstream channel is pull requests (maintainer: Marvin Hansen). One big patch is hard to review, and rules_dx must re-diff it at every pin bump. Split it into separate, tested PRs. Whatever does not land stays in the rules_dx patch, smaller.

The patch does not reach consumers directly: rules_dx applies it inside its own repo rule, so this is not part of #2283's consumer bug. It is listed there because it is the same patch directory.

Where

  • patches/rules_erlang/hermetic_otp.patch, patches/rules_erlang/BUILD.bazel
  • erlang/toolchain/pins.bzl (RULES_ERLANG_COMMIT, RULES_ERLANG_SHA256, RULES_ERLANG_URL), erlang/toolchain/repos.bzl:169,305 (patch application)
  • erlang/toolchain/otp.bzl:5-20: dx_otp returns OtpInfo(..., tree = tree) and erlang_home = "${DX_ERLANG_HOME}"; erlang/rules/defs.bzl:65 sets DX_ERLANG_HOME
  • Upstream files (bazelverse/rules_erlang main): private/erlang_xrl_yrl.bzl:36-40, erlang_app.bzl:50-190, ct.bzl:35-60, private/ct.bzl:190-218 and :282-299 (two ct_run blocks), private/erlang_build.bzl:17-34 (OtpInfo), tools/erlang_toolchain.bzl:38-75; CI in .github/workflows/test.yaml (bazelisk test //... with OTP 28.5 and 29.0)

Fix
Four PRs, each from a fresh branch on upstream main, each with its own test. They are independent except PR 4, which does not need the others. Order them by risk, smallest first.

  1. xrl_yrl installs Erlang: private/erlang_xrl_yrl.bzl already passes maybe_install_erlang = ... to format() but the script template has no {maybe_install_erlang} line, so a release-tar erlang is never unpacked for erlang_xrl_yrl. Add the line (as erlang_bytecode2.bzl:83 does). Test: a .xrl or .yrl target built against a toolchain with release_dir_tar set, or at least that the generated script contains the unpack step; use what the repo's test/ can do without a network.
  2. Forward target_compatible_with and tags: in erlang_app.bzl add the two arguments to erlang_app() and pass them to each generated target (erlang_bytecode, app_file, the appup rule, erlang_app_info); in ct.bzl forward target_compatible_with in ct_suite. Defaults None, so nothing changes. Test: a target with target_compatible_with = ["@platforms//:incompatible"] is skipped by bazel build //..., and tags show up in bazel query --output=build.
  3. CT without -hidden -sname, as an opt-in: add a ct_test attribute (for example distributed = True by default, so current behavior stays) that, when False, omits -hidden -sname <name> from both ct_run blocks in private/ct.bzl. Reason to give upstream: nodes need epmd and a free name, which fails in sandboxes without a loopback. Test: the generated test script contains -sname by default and not with the opt-out.
  4. Relocatable OTP tree as a documented provider field: add tree to OtpInfo in private/erlang_build.bzl with a doc string ("optional depset of every file of a relocatable in-tree Erlang; its root holds version_file"). tools/erlang_toolchain.bzl: erlang_dirs uses tree for runfiles when set; maybe_install_erlang exports the home derived from the version_file location instead of unpacking. Do not hard-code a DX_* variable name upstream. Pick a neutral name (for example ERLANG_HOME), then change erlang/toolchain/otp.bzl and erlang/rules/defs.bzl:65 in rules_dx to match. Existing built-from-source and external toolchains must be unchanged (tree defaults to absent: use getattr or give the field a default through the provider constructor). Test: an OtpInfo fixture with tree set and a rule that runs erlc --version from the derived home.
  5. For each PR: run bazelisk test //... in the upstream clone and include the result. Draft the PR title and body (problem, change, test). No issue text is needed because issues are disabled.
  6. After each PR lands and a pin that contains it is chosen: bump pins.bzl (commit, sha256, url), regenerate hermetic_otp.patch without the landed hunks (git apply --check against the new pin), and run the Erlang tests (erlang/tests). When all four land, delete the patch and patches/rules_erlang/.

Upstream rules (read first)

  • Do not open, edit or comment on any upstream issue or PR, and do not push to any upstream fork. The maintainer submits everything personally.
  • Your output is ready-to-submit material, posted as one comment on this issue: the diff against upstream main (git format-patch or a fenced diff), the test output from the upstream repo, and the drafted upstream issue and PR text.
  • Work in a fresh clone of the upstream repo at its current main. Re-check that no equivalent change or open PR exists before drafting.
  • Write the upstream text in plain, short sentences. State the problem, the change and how it was tested. Do not paste rules_dx internals.
  • The upstream fork has no issue tracker. Do not message the maintainer either.

Done when

  • A comment on this issue holds, per PR: the diff against upstream main, the passing bazelisk test //... output from the upstream clone, and the PR text. Four PRs, or a note saying why one was dropped.
  • Each diff applies cleanly to upstream main (git apply --check) and, together, they cover every hunk of hermetic_otp.patch except those the comment says stay in rules_dx.
  • No upstream PR was opened.
  • After the PRs land: the rules_dx patch holds only what did not land, or is gone.

Related
#2283. rules_elixir split issue (its tree PR depends on PR 4 here).

Activity

  1. added
    P2
    on Oct 26, 2026
  2. TrapsterDK commented on Oct 27, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream PR material for bazelverse/rules_erlang

    There are four independent PRs, each one commit on upstream main. Nothing was opened, pushed or commented upstream.

    Setup

    • Fresh clone of bazelverse/rules_erlang at 13977b3. This is RULES_ERLANG_COMMIT and still upstream main.
    • gh pr list --state all shows only dependabot and release PRs, so no equivalent change exists.
    • Bazel 9.2.0 (the repo's .bazelversion).
    • OTP 29.1.2, with ERLANG_HOME exported and on PATH as the CI does. OTP 28.5 was not run locally.
    • ~/.bazelrc was skipped (--nohome_rc), so nothing ran remotely.
    • Baseline on main: root //... 3/3 pass, test/ //... 15/15 pass.

    Note
    In test/, the internal OTP toolchain only matches the erlang_internal exec constraint, so the default test/ run uses the external erl. The release-tar and tree code paths are therefore tested with small fake OtpInfo toolchains in root analysis tests. Those tests need no network and no OTP build.

    Order
    PR 1, 2, 3, 4 (smallest first). Each applies alone to main (git apply --check), and all four apply together with git am in that order.

    PR 1: fix(erlang_xrl_yrl): install a release-tar erlang before running erlc

    PR text

    Title: fix(erlang_xrl_yrl): install a release-tar erlang before running erlc

    Problem
    erlang_xrl_yrl passes maybe_install_erlang to format(), but its script template has no {maybe_install_erlang} line. With a toolchain that ships erlang as a release tar, the tar is never unpacked for this action. erlc then works only if another action already unpacked it under the install path.

    Change
    Add the placeholder to the script, as erlang_bytecode2 does. One line.

    Test

    • private/xrl_yrl_test: analysis tests with a fake release-tar toolchain. They check that the ERLC action for a .xrl and a .yrl target runs tar --extract and has the tar as an input. Both fail on main and pass with the fix.
    • test/xrl_yrl: builds a .xrl and a .yrl with the default toolchain and checks the generated modules.
    bazelisk test //... output (root, then test/)

    (cached) means the same tree had passed earlier in that output base.

    $ bazel test //...
    //:util_tests_test_0                                            (cached) PASSED in 0.0s
    //private:app_file_test                                         (cached) PASSED in 0.0s
    //private:util_tests_test_0                                     (cached) PASSED in 0.0s
    //private/xrl_yrl_test:lexer_installs_erlang_test               (cached) PASSED in 0.0s
    //private/xrl_yrl_test:parser_installs_erlang_test              (cached) PASSED in 0.0s
    Executed 0 out of 5 tests: 5 tests pass.
    
    $ cd test && bazel test //...
    //app_file:test_applications_preserved                          (cached) PASSED in 0.0s
    //custom_vars:custom_var_test                                   (cached) PASSED in 0.0s
    //dot_app_to_json:dialyze                                       (cached) PASSED in 1.2s
    //dot_app_to_json:dot_app_to_json_SUITE                         (cached) PASSED in 2.9s
    //dot_app_to_json:xref                                          (cached) PASSED in 0.3s
    //erl_attrs_to_json:dialyze                                     (cached) PASSED in 1.3s
    //erl_attrs_to_json:erl_attrs_to_json_SUITE                     (cached) PASSED in 2.9s
    //erl_attrs_to_json:xref                                        (cached) PASSED in 0.1s
    //rebar_config_to_json:dialyze                                  (cached) PASSED in 1.1s
    //rebar_config_to_json:rebar_config_to_json_SUITE               (cached) PASSED in 2.9s
    //rebar_config_to_json:xref                                     (cached) PASSED in 0.3s
    //shard_suite:dialyze                                           (cached) PASSED in 1.3s
    //shard_suite:eunit                                             (cached) PASSED in 0.1s
    //shard_suite:shard_suite_SUITE                                 (cached) PASSED in 3.0s
    //shard_suite:xref                                              (cached) PASSED in 0.2s
    //xrl_yrl:xrl_yrl_test                                                   PASSED in 0.0s
    Executed 1 out of 16 tests: 16 tests pass.
    
    git format-patch against main (pr1-xrl-yrl-install)
    From 21c76e2b9ea1aac0ee91cce5da4f847b2a4f4d0b Mon Sep 17 00:00:00 2001
    From: Martin Kuntz Jacobsen <martin.kuntz.jacobsen@gmail.com>
    Date: Tue, 27 Oct 2026 15:23:35 +0100
    Subject: [PATCH] fix(erlang_xrl_yrl): install a release-tar erlang before
     running erlc
    
    The ERLC action of erlang_xrl_yrl formats maybe_install_erlang into its
    script, but the template had no {maybe_install_erlang} placeholder. With
    a toolchain that ships erlang as a release tar, the tar was never
    unpacked, so erlc only worked if another action had unpacked it first.
    
    Add the placeholder, as erlang_bytecode2 does. Add analysis tests that
    check the ERLC action unpacks the release tar, and a test/ package that
    builds a .xrl and a .yrl.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_011u9TXHDZrfmzFQ2WT8QAKK
    ---
     private/erlang_xrl_yrl.bzl            |  1 +
     private/xrl_yrl_test/BUILD.bazel      | 38 +++++++++++++++
     private/xrl_yrl_test/fake_otp_version |  1 +
     private/xrl_yrl_test/fake_release.tar |  1 +
     private/xrl_yrl_test/lexer.xrl        | 10 ++++
     private/xrl_yrl_test/parser.yrl       |  8 ++++
     private/xrl_yrl_test/xrl_yrl_test.bzl | 67 +++++++++++++++++++++++++++
     test/xrl_yrl/BUILD.bazel              | 32 +++++++++++++
     test/xrl_yrl/lexer.xrl                | 10 ++++
     test/xrl_yrl/parser.yrl               |  8 ++++
     test/xrl_yrl/xrl_yrl_test.sh          |  5 ++
     11 files changed, 181 insertions(+)
     create mode 100644 private/xrl_yrl_test/BUILD.bazel
     create mode 100644 private/xrl_yrl_test/fake_otp_version
     create mode 100644 private/xrl_yrl_test/fake_release.tar
     create mode 100644 private/xrl_yrl_test/lexer.xrl
     create mode 100644 private/xrl_yrl_test/parser.yrl
     create mode 100644 private/xrl_yrl_test/xrl_yrl_test.bzl
     create mode 100644 test/xrl_yrl/BUILD.bazel
     create mode 100644 test/xrl_yrl/lexer.xrl
     create mode 100644 test/xrl_yrl/parser.yrl
     create mode 100755 test/xrl_yrl/xrl_yrl_test.sh
    
    diff --git a/private/erlang_xrl_yrl.bzl b/private/erlang_xrl_yrl.bzl
    index ce0603d..429f0e8 100644
    --- a/private/erlang_xrl_yrl.bzl
    +++ b/private/erlang_xrl_yrl.bzl
    @@ -35,6 +35,7 @@ def _impl(ctx):
     
         script = """set -euo pipefail
     
    +{maybe_install_erlang}
     
     mkdir -p {out_dir}
     
    diff --git a/private/xrl_yrl_test/BUILD.bazel b/private/xrl_yrl_test/BUILD.bazel
    new file mode 100644
    index 0000000..0da7984
    --- /dev/null
    +++ b/private/xrl_yrl_test/BUILD.bazel
    @@ -0,0 +1,38 @@
    +load("//:erlang_xrl_yrl.bzl", "erlang_xrl_yrl")
    +load("//tools:erlang_toolchain.bzl", "erlang_toolchain")
    +load(":xrl_yrl_test.bzl", "fake_release_otp", "xrl_yrl_test_suite")
    +
    +# An erlang that ships as a release tar. Nothing here runs: the tests
    +# only inspect the ERLC action of erlang_xrl_yrl.
    +fake_release_otp(
    +    name = "fake_otp",
    +    release_dir_tar = "fake_release.tar",
    +    version_file = "fake_otp_version",
    +)
    +
    +erlang_toolchain(
    +    name = "fake_erlang",
    +    otp = ":fake_otp",
    +)
    +
    +toolchain(
    +    name = "fake_toolchain",
    +    toolchain = ":fake_erlang",
    +    toolchain_type = "//tools:toolchain_type",
    +)
    +
    +erlang_xrl_yrl(
    +    name = "lexer",
    +    srcs = ["lexer.xrl"],
    +    outs = ["lexer.erl"],
    +    tags = ["manual"],
    +)
    +
    +erlang_xrl_yrl(
    +    name = "parser",
    +    srcs = ["parser.yrl"],
    +    outs = ["parser.erl"],
    +    tags = ["manual"],
    +)
    +
    +xrl_yrl_test_suite(name = "xrl_yrl_test")
    diff --git a/private/xrl_yrl_test/fake_otp_version b/private/xrl_yrl_test/fake_otp_version
    new file mode 100644
    index 0000000..573541a
    --- /dev/null
    +++ b/private/xrl_yrl_test/fake_otp_version
    @@ -0,0 +1 @@
    +0
    diff --git a/private/xrl_yrl_test/fake_release.tar b/private/xrl_yrl_test/fake_release.tar
    new file mode 100644
    index 0000000..3e14aea
    --- /dev/null
    +++ b/private/xrl_yrl_test/fake_release.tar
    @@ -0,0 +1 @@
    +fake release tar, never unpacked by these tests
    diff --git a/private/xrl_yrl_test/lexer.xrl b/private/xrl_yrl_test/lexer.xrl
    new file mode 100644
    index 0000000..c98b464
    --- /dev/null
    +++ b/private/xrl_yrl_test/lexer.xrl
    @@ -0,0 +1,10 @@
    +Definitions.
    +
    +D = [0-9]
    +
    +Rules.
    +
    +{D}+ : {token, {int, TokenLine, list_to_integer(TokenChars)}}.
    +[\s\t\n]+ : skip_token.
    +
    +Erlang code.
    diff --git a/private/xrl_yrl_test/parser.yrl b/private/xrl_yrl_test/parser.yrl
    new file mode 100644
    index 0000000..307238f
    --- /dev/null
    +++ b/private/xrl_yrl_test/parser.yrl
    @@ -0,0 +1,8 @@
    +Nonterminals list items.
    +Terminals int.
    +Rootsymbol list.
    +
    +list -> items : '$1'.
    +list -> '$empty' : [].
    +items -> int : [element(3, '$1')].
    +items -> int items : [element(3, '$1') | '$2'].
    diff --git a/private/xrl_yrl_test/xrl_yrl_test.bzl b/private/xrl_yrl_test/xrl_yrl_test.bzl
    new file mode 100644
    index 0000000..d503dd3
    --- /dev/null
    +++ b/private/xrl_yrl_test/xrl_yrl_test.bzl
    @@ -0,0 +1,67 @@
    +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
    +load("//private:erlang_build.bzl", "OtpInfo")
    +
    +def _fake_release_otp_impl(ctx):
    +    return [OtpInfo(
    +        version = "0",
    +        release_dir_tar = ctx.file.release_dir_tar,
    +        install_path = "/tmp/bazel/erlang/fake",
    +        erlang_home = "/tmp/bazel/erlang/fake",
    +        version_file = ctx.file.version_file,
    +    )]
    +
    +fake_release_otp = rule(
    +    implementation = _fake_release_otp_impl,
    +    attrs = {
    +        "release_dir_tar": attr.label(allow_single_file = True, mandatory = True),
    +        "version_file": attr.label(allow_single_file = True, mandatory = True),
    +    },
    +    provides = [OtpInfo],
    +)
    +
    +def _installs_erlang_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    actions = [a for a in analysistest.target_actions(env) if a.mnemonic == "ERLC"]
    +    asserts.equals(env, 1, len(actions), "expected one ERLC action")
    +    if actions:
    +        action = actions[0]
    +        command = " ".join(action.argv)
    +        asserts.true(
    +            env,
    +            "tar --extract" in command,
    +            "ERLC command does not unpack the release tar:\n" + command,
    +        )
    +        asserts.true(
    +            env,
    +            "fake_release.tar" in command,
    +            "ERLC command does not name the release tar:\n" + command,
    +        )
    +        inputs = [f.basename for f in action.inputs.to_list()]
    +        asserts.true(env, "fake_release.tar" in inputs, "release tar is not an input")
    +    return analysistest.end(env)
    +
    +installs_erlang_test = analysistest.make(
    +    _installs_erlang_test_impl,
    +    config_settings = {
    +        "//command_line_option:extra_toolchains": [
    +            str(Label("//private/xrl_yrl_test:fake_toolchain")),
    +        ],
    +    },
    +)
    +
    +def xrl_yrl_test_suite(name):
    +    installs_erlang_test(
    +        name = "lexer_installs_erlang_test",
    +        target_under_test = ":lexer",
    +    )
    +    installs_erlang_test(
    +        name = "parser_installs_erlang_test",
    +        target_under_test = ":parser",
    +    )
    +    native.test_suite(
    +        name = name,
    +        tests = [
    +            ":lexer_installs_erlang_test",
    +            ":parser_installs_erlang_test",
    +        ],
    +    )
    diff --git a/test/xrl_yrl/BUILD.bazel b/test/xrl_yrl/BUILD.bazel
    new file mode 100644
    index 0000000..bad52e1
    --- /dev/null
    +++ b/test/xrl_yrl/BUILD.bazel
    @@ -0,0 +1,32 @@
    +load("@rules_erlang//:erlang_xrl_yrl.bzl", "erlang_xrl_yrl")
    +load("@rules_shell//shell:sh_test.bzl", "sh_test")
    +
    +erlang_xrl_yrl(
    +    name = "lexer",
    +    srcs = ["lexer.xrl"],
    +    outs = ["lexer.erl"],
    +)
    +
    +erlang_xrl_yrl(
    +    name = "parser",
    +    srcs = ["parser.yrl"],
    +    outs = ["parser.erl"],
    +)
    +
    +sh_test(
    +    name = "xrl_yrl_test",
    +    srcs = ["xrl_yrl_test.sh"],
    +    args = [
    +        "$(location :lexer)",
    +        "$(location :parser)",
    +    ],
    +    data = [
    +        ":lexer",
    +        ":parser",
    +    ],
    +    target_compatible_with = select({
    +        "@platforms//os:osx": [],
    +        "@platforms//os:linux": [],
    +        "//conditions:default": ["@platforms//:incompatible"],
    +    }),
    +)
    diff --git a/test/xrl_yrl/lexer.xrl b/test/xrl_yrl/lexer.xrl
    new file mode 100644
    index 0000000..c98b464
    --- /dev/null
    +++ b/test/xrl_yrl/lexer.xrl
    @@ -0,0 +1,10 @@
    +Definitions.
    +
    +D = [0-9]
    +
    +Rules.
    +
    +{D}+ : {token, {int, TokenLine, list_to_integer(TokenChars)}}.
    +[\s\t\n]+ : skip_token.
    +
    +Erlang code.
    diff --git a/test/xrl_yrl/parser.yrl b/test/xrl_yrl/parser.yrl
    new file mode 100644
    index 0000000..307238f
    --- /dev/null
    +++ b/test/xrl_yrl/parser.yrl
    @@ -0,0 +1,8 @@
    +Nonterminals list items.
    +Terminals int.
    +Rootsymbol list.
    +
    +list -> items : '$1'.
    +list -> '$empty' : [].
    +items -> int : [element(3, '$1')].
    +items -> int items : [element(3, '$1') | '$2'].
    diff --git a/test/xrl_yrl/xrl_yrl_test.sh b/test/xrl_yrl/xrl_yrl_test.sh
    new file mode 100755
    index 0000000..b4fba15
    --- /dev/null
    +++ b/test/xrl_yrl/xrl_yrl_test.sh
    @@ -0,0 +1,5 @@
    +#!/usr/bin/env bash
    +set -euo pipefail
    +
    +grep -q -- '-module(lexer).' "$1"
    +grep -q -- '-module(parser).' "$2"
    -- 
    2.53.0

    PR 2: feat(erlang_app, ct_suite): forward target_compatible_with and tags

    PR text

    Title: feat(erlang_app, ct_suite): forward target_compatible_with and tags

    Problem
    erlang_app and test_erlang_app cannot mark their generated targets as incompatible with a platform, or tag them. ct_suite passes target_compatible_with to the test but not to the suite's bytecode target, so the suite still compiles on platforms where it cannot run.

    Change

    • erlang_app: new arguments target_compatible_with and tags, both default None. They are passed to erlang_bytecode, app_file, the appup copy_file and erlang_app_info.
    • ct_suite: also passes target_compatible_with to the suite's erlang_bytecode.
    • With the defaults nothing changes.

    Test
    test/erlang_app_attrs: an app, a test app and a suite, all with tags = ["attrs_fixture"] and target_compatible_with = ["@platforms//:incompatible"]. A macro in the same BUILD file walks native.existing_rules() and fails at loading time if a generated rule misses either attribute. bazel test //... skips the incompatible suite, and bazel query --output=build shows the tag on each target. On main the package fails to load (_erlang_app() got unexpected keyword arguments: tags, target_compatible_with).

    bazelisk test //... output (root, then test/)

    (cached) means the same tree had passed earlier in that output base.

    $ bazel test //...
    //:util_tests_test_0                                            (cached) PASSED in 0.0s
    //private:app_file_test                                         (cached) PASSED in 0.0s
    //private:util_tests_test_0                                     (cached) PASSED in 0.0s
    Executed 0 out of 3 tests: 3 tests pass.
    
    $ cd test && bazel test //...
    //app_file:test_applications_preserved                          (cached) PASSED in 0.0s
    //custom_vars:custom_var_test                                   (cached) PASSED in 0.0s
    //dot_app_to_json:dialyze                                       (cached) PASSED in 1.2s
    //dot_app_to_json:dot_app_to_json_SUITE                         (cached) PASSED in 2.9s
    //dot_app_to_json:xref                                          (cached) PASSED in 0.3s
    //erl_attrs_to_json:dialyze                                     (cached) PASSED in 1.3s
    //erl_attrs_to_json:erl_attrs_to_json_SUITE                     (cached) PASSED in 2.9s
    //erl_attrs_to_json:xref                                        (cached) PASSED in 0.1s
    //rebar_config_to_json:dialyze                                  (cached) PASSED in 1.1s
    //rebar_config_to_json:rebar_config_to_json_SUITE               (cached) PASSED in 2.9s
    //rebar_config_to_json:xref                                     (cached) PASSED in 0.3s
    //shard_suite:dialyze                                           (cached) PASSED in 1.3s
    //shard_suite:eunit                                             (cached) PASSED in 0.1s
    //shard_suite:shard_suite_SUITE                                 (cached) PASSED in 3.0s
    //shard_suite:xref                                              (cached) PASSED in 0.2s
    //erlang_app_attrs:attrs_app_SUITE                                      SKIPPED
    Executed 0 out of 16 tests: 15 tests pass and 1 was skipped.
    
    git format-patch against main (pr2-forward-tcw-tags)
    From 017bbcdd7a91ab22d9f4f018b86d3d8881af99a9 Mon Sep 17 00:00:00 2001
    From: Martin Kuntz Jacobsen <martin.kuntz.jacobsen@gmail.com>
    Date: Tue, 27 Oct 2026 15:30:22 +0100
    Subject: [PATCH] feat(erlang_app, ct_suite): forward target_compatible_with
     and tags
    
    erlang_app and test_erlang_app had no way to mark their generated
    targets as incompatible with a platform or to tag them. ct_suite passed
    target_compatible_with to the test but not to the suite's bytecode
    target, so the suite still compiled on platforms it cannot run on.
    
    Add target_compatible_with and tags to erlang_app (default None, so
    nothing changes) and pass them to erlang_bytecode, app_file, the appup
    copy and erlang_app_info. ct_suite now passes target_compatible_with to
    the suite's erlang_bytecode as well. Add a test/ package whose targets
    are all incompatible and whose BUILD file fails at loading time if a
    generated rule misses either attribute.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_011u9TXHDZrfmzFQ2WT8QAKK
    ---
     ct.bzl                                        |  3 ++
     erlang_app.bzl                                | 10 +++++
     test/erlang_app_attrs/BUILD.bazel             | 37 +++++++++++++++++++
     test/erlang_app_attrs/defs.bzl                | 20 ++++++++++
     test/erlang_app_attrs/src/attrs_app.app.src   |  7 ++++
     test/erlang_app_attrs/src/attrs_app.appup     |  1 +
     test/erlang_app_attrs/src/attrs_app.erl       |  6 +++
     .../erlang_app_attrs/test/attrs_app_SUITE.erl |  9 +++++
     8 files changed, 93 insertions(+)
     create mode 100644 test/erlang_app_attrs/BUILD.bazel
     create mode 100644 test/erlang_app_attrs/defs.bzl
     create mode 100644 test/erlang_app_attrs/src/attrs_app.app.src
     create mode 100644 test/erlang_app_attrs/src/attrs_app.appup
     create mode 100644 test/erlang_app_attrs/src/attrs_app.erl
     create mode 100644 test/erlang_app_attrs/test/attrs_app_SUITE.erl
    
    diff --git a/ct.bzl b/ct.bzl
    index 503c30d..1ebb0da 100644
    --- a/ct.bzl
    +++ b/ct.bzl
    @@ -35,6 +35,7 @@ def ct_suite(
             erlc_opts = DEFAULT_TEST_ERLC_OPTS,
             deps = [],
             runtime_deps = [],
    +        target_compatible_with = None,
             **kwargs):
         if suite_name == "":
             suite_name = name
    @@ -46,6 +47,7 @@ def ct_suite(
             erlc_opts = erlc_opts,
             dest = "test",
             deps = [":test_erlang_app"] + deps,
    +        target_compatible_with = target_compatible_with,
             testonly = True,
         )
     
    @@ -54,6 +56,7 @@ def ct_suite(
             suite_name = suite_name,
             deps = deps,
             runtime_deps = runtime_deps,
    +        target_compatible_with = target_compatible_with,
             **kwargs
         )
     
    diff --git a/erlang_app.bzl b/erlang_app.bzl
    index a45df18..fdc9bae 100644
    --- a/erlang_app.bzl
    +++ b/erlang_app.bzl
    @@ -50,7 +50,9 @@ def _erlang_app(
             deps = [],
             runtime_deps = [],
             stamp = None,
    +        target_compatible_with = None,
             testonly = False,
    +        tags = None,
             # new attrs for gazelle extension
             beam_files = None,
             hdrs = None,
    @@ -114,6 +116,8 @@ def _erlang_app(
                 erlc_opts = erlc_opts,
                 dest = "ebin" if not test else "test",
                 deps = build_deps + deps,
    +            target_compatible_with = target_compatible_with,
    +            tags = tags,
                 testonly = test or testonly,
             )
     
    @@ -136,6 +140,8 @@ def _erlang_app(
                     deps = deps + runtime_deps,
                     dest = "ebin",
                     stamp = stamp,
    +                target_compatible_with = target_compatible_with,
    +                tags = tags,
                     testonly = testonly,
                 )
             app = ":app_file"
    @@ -150,6 +156,8 @@ def _erlang_app(
                     name = "appup",
                     src = "src/{}.appup".format(app_name),
                     out = "ebin/{}.appup".format(app_name),
    +                target_compatible_with = target_compatible_with,
    +                tags = tags,
                 )
             appup = ":appup"
         else:
    @@ -178,6 +186,8 @@ def _erlang_app(
             license_files = license_files,
             srcs = srcs,
             deps = deps + runtime_deps,
    +        target_compatible_with = target_compatible_with,
    +        tags = tags,
             visibility = ["//visibility:public"],
             testonly = test or testonly,
         )
    diff --git a/test/erlang_app_attrs/BUILD.bazel b/test/erlang_app_attrs/BUILD.bazel
    new file mode 100644
    index 0000000..25e8933
    --- /dev/null
    +++ b/test/erlang_app_attrs/BUILD.bazel
    @@ -0,0 +1,37 @@
    +load("@rules_erlang//:ct.bzl", "ct_suite")
    +load("@rules_erlang//:erlang_app.bzl", "erlang_app", "test_erlang_app")
    +load(":defs.bzl", "assert_forwarded")
    +
    +# Every target in this package is incompatible, so `bazel build //...`
    +# and `bazel test //...` skip them. If erlang_app or ct_suite stops
    +# forwarding tags or target_compatible_with, assert_forwarded fails the
    +# package at loading time.
    +
    +TAGS = ["attrs_fixture"]
    +
    +INCOMPATIBLE = ["@platforms//:incompatible"]
    +
    +erlang_app(
    +    app_name = "attrs_app",
    +    tags = TAGS,
    +    target_compatible_with = INCOMPATIBLE,
    +)
    +
    +test_erlang_app(
    +    app_name = "attrs_app",
    +    tags = TAGS,
    +    target_compatible_with = INCOMPATIBLE,
    +)
    +
    +ct_suite(
    +    name = "attrs_app_SUITE",
    +    tags = TAGS,
    +    target_compatible_with = INCOMPATIBLE,
    +)
    +
    +assert_forwarded(
    +    tag = "attrs_fixture",
    +    incompatible = "//:incompatible",
    +    # ct_suite passes tags to the test only, not to the suite's bytecode.
    +    untagged = ["attrs_app_SUITE_beam_files"],
    +)
    diff --git a/test/erlang_app_attrs/defs.bzl b/test/erlang_app_attrs/defs.bzl
    new file mode 100644
    index 0000000..e140023
    --- /dev/null
    +++ b/test/erlang_app_attrs/defs.bzl
    @@ -0,0 +1,20 @@
    +"""Loading-time check that erlang_app and ct_suite forward attributes."""
    +
    +def assert_forwarded(tag, incompatible, untagged = []):
    +    """Fails the package unless every generated rule carries the tag and the constraint.
    +
    +    Args:
    +      tag: a tag passed to erlang_app and ct_suite.
    +      incompatible: the target_compatible_with label passed to them.
    +      untagged: rules that only get target_compatible_with.
    +    """
    +    rules = native.existing_rules()
    +    if not rules:
    +        fail("no rules to check")
    +    for name, rule in rules.items():
    +        tags = rule.get("tags") or []
    +        if name not in untagged and tag not in tags:
    +            fail("{}: tags {} do not contain {}".format(name, tags, tag))
    +        tcw = [str(c) for c in (rule.get("target_compatible_with") or [])]
    +        if not [c for c in tcw if c.endswith(incompatible)]:
    +            fail("{}: target_compatible_with {} does not contain {}".format(name, tcw, incompatible))
    diff --git a/test/erlang_app_attrs/src/attrs_app.app.src b/test/erlang_app_attrs/src/attrs_app.app.src
    new file mode 100644
    index 0000000..2a82c39
    --- /dev/null
    +++ b/test/erlang_app_attrs/src/attrs_app.app.src
    @@ -0,0 +1,7 @@
    +{application, attrs_app, [
    +    {description, "Fixture for target_compatible_with and tags forwarding"},
    +    {vsn, "1.0.0"},
    +    {registered, []},
    +    {applications, [kernel, stdlib]},
    +    {env, []}
    +]}.
    diff --git a/test/erlang_app_attrs/src/attrs_app.appup b/test/erlang_app_attrs/src/attrs_app.appup
    new file mode 100644
    index 0000000..a6c1ce2
    --- /dev/null
    +++ b/test/erlang_app_attrs/src/attrs_app.appup
    @@ -0,0 +1 @@
    +{"1.0.0", [], []}.
    diff --git a/test/erlang_app_attrs/src/attrs_app.erl b/test/erlang_app_attrs/src/attrs_app.erl
    new file mode 100644
    index 0000000..c2a9bae
    --- /dev/null
    +++ b/test/erlang_app_attrs/src/attrs_app.erl
    @@ -0,0 +1,6 @@
    +-module(attrs_app).
    +
    +-export([hello/0]).
    +
    +hello() ->
    +    world.
    diff --git a/test/erlang_app_attrs/test/attrs_app_SUITE.erl b/test/erlang_app_attrs/test/attrs_app_SUITE.erl
    new file mode 100644
    index 0000000..6ddb084
    --- /dev/null
    +++ b/test/erlang_app_attrs/test/attrs_app_SUITE.erl
    @@ -0,0 +1,9 @@
    +-module(attrs_app_SUITE).
    +
    +-export([all/0, hello/1]).
    +
    +all() ->
    +    [hello].
    +
    +hello(_Config) ->
    +    world = attrs_app:hello().
    -- 
    2.53.0

    PR 3: feat(ct_test): add auto_sname to opt out of -hidden -sname

    PR text

    Title: feat(ct_test): add auto_sname to opt out of -hidden -sname

    Problem
    ct_test always starts ct_run with -hidden -sname <name>. A named node needs epmd and a free name on a working loopback. In a sandbox without a loopback interface the node cannot start, and the test fails before any case runs. ct_run_extra_args can add node options but cannot remove these two.

    Change

    • New bool attribute auto_sname on ct_test, default True.
    • When False, both the POSIX and the Windows script start ct_run without -hidden and -sname. ct_run_extra_args then chooses the node options. For example, -sname undefined -start_epmd false runs the suite without epmd.
    • Without any -sname or -name, ct_run uses its own default name (ct). The attribute doc says so.
    • ct_suite and ct_suite_variant pass it through **kwargs.
    • With the default, the generated scripts are byte-for-byte unchanged. This was checked by building the POSIX and the Windows script on main and on the branch and comparing them.

    Test

    • private/ct_auto_sname_test: analysis tests on the generated POSIX and Windows scripts. -hidden and -sname are present by default and absent with auto_sname = False.
    • test/ct_no_sname: a suite with auto_sname = False and -sname undefined -start_epmd false. It checks that node() is nonode@nohost and that the node is not hidden. With the default auto_sname the same suite fails, because -hidden is still passed.
    bazelisk test //... output (root, then test/)

    (cached) means the same tree had passed earlier in that output base.

    $ bazel test //...
    //:util_tests_test_0                                            (cached) PASSED in 0.0s
    //private:app_file_test                                         (cached) PASSED in 0.0s
    //private:util_tests_test_0                                     (cached) PASSED in 0.0s
    //private/ct_auto_sname_test:auto_sname_posix_test              (cached) PASSED in 0.0s
    //private/ct_auto_sname_test:auto_sname_windows_test            (cached) PASSED in 0.0s
    //private/ct_auto_sname_test:default_posix_test                 (cached) PASSED in 0.0s
    //private/ct_auto_sname_test:no_sname_posix_test                (cached) PASSED in 0.0s
    //private/ct_auto_sname_test:no_sname_windows_test              (cached) PASSED in 0.0s
    Executed 0 out of 8 tests: 8 tests pass.
    
    $ cd test && bazel test //...
    //app_file:test_applications_preserved                          (cached) PASSED in 0.0s
    //custom_vars:custom_var_test                                   (cached) PASSED in 0.0s
    //dot_app_to_json:dialyze                                       (cached) PASSED in 1.2s
    //dot_app_to_json:dot_app_to_json_SUITE                         (cached) PASSED in 2.9s
    //dot_app_to_json:xref                                          (cached) PASSED in 0.3s
    //erl_attrs_to_json:dialyze                                     (cached) PASSED in 1.3s
    //erl_attrs_to_json:erl_attrs_to_json_SUITE                     (cached) PASSED in 2.9s
    //erl_attrs_to_json:xref                                        (cached) PASSED in 0.1s
    //rebar_config_to_json:dialyze                                  (cached) PASSED in 1.1s
    //rebar_config_to_json:rebar_config_to_json_SUITE               (cached) PASSED in 2.9s
    //rebar_config_to_json:xref                                     (cached) PASSED in 0.3s
    //shard_suite:dialyze                                           (cached) PASSED in 1.3s
    //shard_suite:eunit                                             (cached) PASSED in 0.1s
    //shard_suite:shard_suite_SUITE                                 (cached) PASSED in 3.0s
    //shard_suite:xref                                              (cached) PASSED in 0.2s
    //ct_no_sname:no_sname_SUITE                                             PASSED in 2.6s
    Executed 1 out of 16 tests: 16 tests pass.
    
    git format-patch against main (pr3-ct-auto-sname)
    From bf7fa5debe7fcd6bf29e5fcab71277d0ea92b795 Mon Sep 17 00:00:00 2001
    From: Martin Kuntz Jacobsen <martin.kuntz.jacobsen@gmail.com>
    Date: Tue, 27 Oct 2026 15:31:23 +0100
    Subject: [PATCH] feat(ct_test): add auto_sname to opt out of -hidden -sname
    
    ct_test always starts ct_run with -hidden -sname <name>. A named node
    needs epmd and a free name on a working loopback. In sandboxes without
    a loopback interface the node cannot start, so the test fails before
    any case runs. ct_run_extra_args can add node options but cannot
    remove these two.
    
    Add a bool attribute auto_sname to ct_test (default True). When False,
    both the POSIX and the Windows script start ct_run without -hidden and
    -sname, and ct_run_extra_args picks the node options. For example,
    -sname undefined -start_epmd false runs the suite without epmd.
    ct_suite and ct_suite_variant pass it through **kwargs. With the
    default, the generated scripts are byte-for-byte unchanged.
    
    Add analysis tests for the POSIX and Windows scripts with and without
    the option, and a test/ suite that runs with auto_sname = False and
    -sname undefined -start_epmd false and checks that the node is
    unnamed and not hidden.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_011u9TXHDZrfmzFQ2WT8QAKK
    ---
     private/ct.bzl                                | 21 ++++---
     private/ct_auto_sname_test/BUILD.bazel        | 40 ++++++++++++
     .../ct_auto_sname_test/ct_auto_sname_test.bzl | 61 +++++++++++++++++++
     private/ct_auto_sname_test/fake_SUITE.beam    |  1 +
     test/ct_no_sname/BUILD.bazel                  | 23 +++++++
     test/ct_no_sname/src/no_sname.app.src         |  7 +++
     test/ct_no_sname/src/no_sname.erl             |  6 ++
     test/ct_no_sname/test/no_sname_SUITE.erl      | 12 ++++
     8 files changed, 163 insertions(+), 8 deletions(-)
     create mode 100644 private/ct_auto_sname_test/BUILD.bazel
     create mode 100644 private/ct_auto_sname_test/ct_auto_sname_test.bzl
     create mode 100644 private/ct_auto_sname_test/fake_SUITE.beam
     create mode 100644 test/ct_no_sname/BUILD.bazel
     create mode 100644 test/ct_no_sname/src/no_sname.app.src
     create mode 100644 test/ct_no_sname/src/no_sname.erl
     create mode 100644 test/ct_no_sname/test/no_sname_SUITE.erl
    
    diff --git a/private/ct.bzl b/private/ct.bzl
    index fe08235..5bfaa99 100644
    --- a/private/ct.bzl
    +++ b/private/ct.bzl
    @@ -190,9 +190,7 @@ set -x
         -noinput \\
         ${{FILTER}} \\
         -dir test {pa_args} \\
    -    -logdir "{log_dir}" \\
    -    -hidden \\
    -    -sname {sname} ${{COVER_ARGS}} {extra_args}
    +    -logdir "{log_dir}"{node_args} ${{COVER_ARGS}} {extra_args}
     set +x
     if [ -n "${{COVERAGE}}" ]; then
         "{erlang_home}"/bin/escript $TEST_SRCDIR/$TEST_WORKSPACE/{coverdata_to_lcov} \\
    @@ -214,7 +212,7 @@ fi
                 pa_args = " ".join(pa_args),
                 dir = path_join(package, "test"),
                 log_dir = log_dir,
    -            sname = sname(ctx),
    +            node_args = " \\\n    -hidden \\\n    -sname {}".format(sname(ctx)) if ctx.attr.auto_sname else "",
                 extra_args = " ".join(extra_args),
                 test_env = "\n".join(test_env_commands),
             )
    @@ -277,9 +275,7 @@ echo on
         -noinput ^
         %FILTER% ^
         -dir test {pa_args} ^
    -    -logdir {drive_letter}: ^
    -    -hidden ^
    -    -sname {sname} {extra_args}
    +    -logdir {drive_letter}:{node_args} {extra_args}
     set CT_RUN_ERRORLEVEL=%ERRORLEVEL%
     subst {drive_letter}: /d
     exit /b %CT_RUN_ERRORLEVEL%
    @@ -295,7 +291,7 @@ exit /b %CT_RUN_ERRORLEVEL%
                 dir = path_join(package, "test"),
                 log_dir = log_dir,
                 drive_letter = ctx.attr._windows_logdir_drive_letter[BuildSettingInfo].value,
    -            sname = sname(ctx),
    +            node_args = " ^\n    -hidden ^\n    -sname {}".format(sname(ctx)) if ctx.attr.auto_sname else "",
                 extra_args = " ".join(extra_args),
                 test_env = "\n".join(test_env_commands),
             ).replace("\n", "\r\n")
    @@ -346,6 +342,15 @@ ct_test = rule(
             ),
             "ct_hooks": attr.string_list(),
             "ct_run_extra_args": attr.string_list(),
    +        "auto_sname": attr.bool(
    +            default = True,
    +            doc = """Start the test node as a hidden node with a short name
    +generated from the label (-hidden -sname <name>). A named node needs
    +epmd and a working loopback. Set to False to leave both flags out and
    +choose node options in ct_run_extra_args instead. Without a -sname or
    +-name there, ct_run falls back to its own default name (ct). To run
    +without epmd, pass -sname undefined -start_epmd false.""",
    +        ),
             "data": attr.label_list(allow_files = True),
             "deps": attr.label_list(providers = [ErlangAppInfo]),
             "ez_deps": attr.label_list(
    diff --git a/private/ct_auto_sname_test/BUILD.bazel b/private/ct_auto_sname_test/BUILD.bazel
    new file mode 100644
    index 0000000..1782ede
    --- /dev/null
    +++ b/private/ct_auto_sname_test/BUILD.bazel
    @@ -0,0 +1,40 @@
    +load("//private:ct.bzl", "ct_test")
    +load(":ct_auto_sname_test.bzl", "ct_auto_sname_test_suite")
    +
    +# The tests only inspect the generated test scripts; nothing here runs.
    +
    +[
    +    ct_test(
    +        name = "{}_{}".format(
    +            "auto_sname" if auto_sname else "no_sname",
    +            "windows" if is_windows else "posix",
    +        ),
    +        auto_sname = auto_sname,
    +        compiled_suites = ["fake_SUITE.beam"],
    +        coverdata_to_lcov = "//tools/coverdata_to_lcov",
    +        shard_suite = "//tools/shard_suite",
    +        is_windows = is_windows,
    +        suite_name = "fake_SUITE",
    +        tags = ["manual"],
    +    )
    +    for auto_sname in [
    +        True,
    +        False,
    +    ]
    +    for is_windows in [
    +        True,
    +        False,
    +    ]
    +]
    +
    +ct_test(
    +    name = "default_posix",
    +    compiled_suites = ["fake_SUITE.beam"],
    +    coverdata_to_lcov = "//tools/coverdata_to_lcov",
    +    is_windows = False,
    +    shard_suite = "//tools/shard_suite",
    +    suite_name = "fake_SUITE",
    +    tags = ["manual"],
    +)
    +
    +ct_auto_sname_test_suite(name = "ct_auto_sname_test")
    diff --git a/private/ct_auto_sname_test/ct_auto_sname_test.bzl b/private/ct_auto_sname_test/ct_auto_sname_test.bzl
    new file mode 100644
    index 0000000..44608ce
    --- /dev/null
    +++ b/private/ct_auto_sname_test/ct_auto_sname_test.bzl
    @@ -0,0 +1,61 @@
    +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
    +
    +def _script(env):
    +    writes = [
    +        a
    +        for a in analysistest.target_actions(env)
    +        if a.mnemonic == "FileWrite"
    +    ]
    +    asserts.equals(env, 1, len(writes), "expected one FileWrite action")
    +    return writes[0].content if writes else ""
    +
    +def _has_sname_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    script = _script(env)
    +    asserts.true(env, "-hidden" in script, "-hidden missing:\n" + script)
    +    asserts.true(env, "-sname " in script, "-sname missing:\n" + script)
    +    return analysistest.end(env)
    +
    +has_sname_test = analysistest.make(_has_sname_test_impl)
    +
    +def _no_sname_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    script = _script(env)
    +    asserts.false(env, "-hidden" in script, "-hidden present:\n" + script)
    +    asserts.false(env, "-sname" in script, "-sname present:\n" + script)
    +    asserts.true(env, "-logdir" in script, "-logdir missing:\n" + script)
    +    return analysistest.end(env)
    +
    +no_sname_test = analysistest.make(_no_sname_test_impl)
    +
    +def ct_auto_sname_test_suite(name):
    +    has_sname_test(
    +        name = "default_posix_test",
    +        target_under_test = ":default_posix",
    +    )
    +    has_sname_test(
    +        name = "auto_sname_posix_test",
    +        target_under_test = ":auto_sname_posix",
    +    )
    +    has_sname_test(
    +        name = "auto_sname_windows_test",
    +        target_under_test = ":auto_sname_windows",
    +    )
    +    no_sname_test(
    +        name = "no_sname_posix_test",
    +        target_under_test = ":no_sname_posix",
    +    )
    +    no_sname_test(
    +        name = "no_sname_windows_test",
    +        target_under_test = ":no_sname_windows",
    +    )
    +    native.test_suite(
    +        name = name,
    +        tests = [
    +            ":default_posix_test",
    +            ":auto_sname_posix_test",
    +            ":auto_sname_windows_test",
    +            ":no_sname_posix_test",
    +            ":no_sname_windows_test",
    +        ],
    +    )
    diff --git a/private/ct_auto_sname_test/fake_SUITE.beam b/private/ct_auto_sname_test/fake_SUITE.beam
    new file mode 100644
    index 0000000..4ab92ba
    --- /dev/null
    +++ b/private/ct_auto_sname_test/fake_SUITE.beam
    @@ -0,0 +1 @@
    +not a real beam file; only used for analysis
    diff --git a/test/ct_no_sname/BUILD.bazel b/test/ct_no_sname/BUILD.bazel
    new file mode 100644
    index 0000000..530821f
    --- /dev/null
    +++ b/test/ct_no_sname/BUILD.bazel
    @@ -0,0 +1,23 @@
    +load("@rules_erlang//:ct.bzl", "ct_suite")
    +load("@rules_erlang//:erlang_app.bzl", "erlang_app", "test_erlang_app")
    +
    +erlang_app(
    +    app_name = "no_sname",
    +)
    +
    +test_erlang_app(
    +    app_name = "no_sname",
    +)
    +
    +# auto_sname = False leaves out -hidden -sname <name>, so the suite can
    +# start a node that does not register with epmd.
    +ct_suite(
    +    name = "no_sname_SUITE",
    +    auto_sname = False,
    +    ct_run_extra_args = [
    +        "-sname",
    +        "undefined",
    +        "-start_epmd",
    +        "false",
    +    ],
    +)
    diff --git a/test/ct_no_sname/src/no_sname.app.src b/test/ct_no_sname/src/no_sname.app.src
    new file mode 100644
    index 0000000..6fefdb2
    --- /dev/null
    +++ b/test/ct_no_sname/src/no_sname.app.src
    @@ -0,0 +1,7 @@
    +{application, no_sname, [
    +    {description, "Fixture for ct_suite with auto_sname = False"},
    +    {vsn, "1.0.0"},
    +    {registered, []},
    +    {applications, [kernel, stdlib]},
    +    {env, []}
    +]}.
    diff --git a/test/ct_no_sname/src/no_sname.erl b/test/ct_no_sname/src/no_sname.erl
    new file mode 100644
    index 0000000..0c8214a
    --- /dev/null
    +++ b/test/ct_no_sname/src/no_sname.erl
    @@ -0,0 +1,6 @@
    +-module(no_sname).
    +
    +-export([node_name/0]).
    +
    +node_name() ->
    +    node().
    diff --git a/test/ct_no_sname/test/no_sname_SUITE.erl b/test/ct_no_sname/test/no_sname_SUITE.erl
    new file mode 100644
    index 0000000..b05da69
    --- /dev/null
    +++ b/test/ct_no_sname/test/no_sname_SUITE.erl
    @@ -0,0 +1,12 @@
    +-module(no_sname_SUITE).
    +
    +-export([all/0, no_generated_name/1]).
    +
    +all() ->
    +    [no_generated_name].
    +
    +%% With auto_sname = False the node gets no -hidden and no generated
    +%% -sname, so -sname undefined from ct_run_extra_args leaves it unnamed.
    +no_generated_name(_Config) ->
    +    nonode@nohost = no_sname:node_name(),
    +    error = init:get_argument(hidden).
    -- 
    2.53.0

    PR 4: feat(OtpInfo): add an optional relocatable tree

    PR text

    Title: feat(OtpInfo): add an optional relocatable tree

    Problem
    A toolchain can give erlang in two ways only: an absolute erlang_home on the host, or a release tar that each action unpacks to a fixed absolute path. Neither lets an erlang that lives inside the build be used as plain inputs and runfiles. Examples are a relocatable release in a repository rule or in the source tree.

    Change

    • OtpInfo gets an optional, documented tree field. It is a depset of every file of a relocatable erlang whose root directory holds version_file.
    • When tree is set:
      • erlang_dirs puts the tree in the runfiles. It returns the home ${RULES_ERLANG_HOME}, which is exported as TREE_ERLANG_HOME.
      • maybe_install_erlang assigns RULES_ERLANG_HOME from the directory of version_file, using the path in actions and the short path in tests. It does not unpack a tar. The variable is a plain shell variable and is not exported.
      • The ERLANG_HOME make variable from erlang_toolchain and erlang_vars is the directory of version_file. A genrule that uses it must list the tree files as inputs.
    • tree is read with getattr. Providers that do not set it, and every existing toolchain, behave as before.
    • Only the POSIX shell scripts support a tree, and the field doc says so.
    • erlang_headers now double-quotes the home, so the variable expands.
    • Every rule that calls erlang_dirs also emits maybe_install_erlang. A new rule that skips it fails at once with an unset variable. (erlang_xrl_yrl has this bug on main for release tars as well; PR 1 fixes it.)

    Test
    private/otp_tree_test has a fake tree toolchain: OTP_VERSION plus stub bin/erl, bin/erlc and bin/escript.

    • Analysis tests check four things:
      • erl_eval derives the home, runs "${RULES_ERLANG_HOME}"/bin/erl, has every tree file as an input, and does not unpack a tar.
      • The eunit script derives the home from the short path and has the tree in its runfiles.
      • A release-tar toolchain still unpacks its tar.
      • The make variable points at the tree.
    • A sh_test builds erl_eval with the tree toolchain (through a transition on extra_toolchains) and checks that the stub erl ran from the tree in the sandbox.
    • On main the fixture fails at analysis, because OtpInfo has no tree field.
    bazelisk test //... output (root, then test/)

    (cached) means the same tree had passed earlier in that output base.

    $ bazel test //...
    //:util_tests_test_0                                            (cached) PASSED in 0.0s
    //private:app_file_test                                         (cached) PASSED in 0.0s
    //private:util_tests_test_0                                     (cached) PASSED in 0.0s
    //private/otp_tree_test:erl_eval_with_release_tar_test          (cached) PASSED in 0.0s
    //private/otp_tree_test:erl_eval_with_tree_test                 (cached) PASSED in 0.0s
    //private/otp_tree_test:erl_runs_from_tree_test                 (cached) PASSED in 0.0s
    //private/otp_tree_test:eunit_with_tree_test                    (cached) PASSED in 0.0s
    //private/otp_tree_test:template_vars_with_tree_test            (cached) PASSED in 0.0s
    Executed 0 out of 8 tests: 8 tests pass.
    
    $ cd test && bazel test //...
    //app_file:test_applications_preserved                          (cached) PASSED in 0.0s
    //custom_vars:custom_var_test                                   (cached) PASSED in 0.0s
    //dot_app_to_json:dialyze                                       (cached) PASSED in 1.2s
    //dot_app_to_json:dot_app_to_json_SUITE                         (cached) PASSED in 2.9s
    //dot_app_to_json:xref                                          (cached) PASSED in 0.3s
    //erl_attrs_to_json:dialyze                                     (cached) PASSED in 1.3s
    //erl_attrs_to_json:erl_attrs_to_json_SUITE                     (cached) PASSED in 2.9s
    //erl_attrs_to_json:xref                                        (cached) PASSED in 0.1s
    //rebar_config_to_json:dialyze                                  (cached) PASSED in 1.1s
    //rebar_config_to_json:rebar_config_to_json_SUITE               (cached) PASSED in 2.9s
    //rebar_config_to_json:xref                                     (cached) PASSED in 0.3s
    //shard_suite:dialyze                                           (cached) PASSED in 1.3s
    //shard_suite:eunit                                             (cached) PASSED in 0.1s
    //shard_suite:shard_suite_SUITE                                 (cached) PASSED in 3.0s
    //shard_suite:xref                                              (cached) PASSED in 0.2s
    Executed 0 out of 15 tests: 15 tests pass.
    
    git format-patch against main (pr4-otp-tree)
    From c8f9a7be55cac991484a2f64dc195f34e4d64d9d Mon Sep 17 00:00:00 2001
    From: Martin Kuntz Jacobsen <martin.kuntz.jacobsen@gmail.com>
    Date: Tue, 27 Oct 2026 15:34:04 +0100
    Subject: [PATCH] feat(OtpInfo): add an optional relocatable tree
    
    A toolchain can only provide erlang as an absolute erlang_home on the
    host, or as a release tar that each action unpacks to a fixed absolute
    path under /tmp. Neither lets an erlang that lives inside the build
    (for example a relocatable release checked in or fetched as a repo) be
    used as plain inputs and runfiles.
    
    Add an optional tree field to OtpInfo: a depset of every file of a
    relocatable erlang whose root directory holds version_file. When it is
    set:
    
    - erlang_dirs puts the tree in the runfiles and returns the home
      ${RULES_ERLANG_HOME} (exported as TREE_ERLANG_HOME).
    - maybe_install_erlang assigns RULES_ERLANG_HOME from the directory of
      version_file (path in actions, short_path in tests) instead of
      unpacking a tar. The variable is a plain shell variable, not exported.
    - The ERLANG_HOME make variable of erlang_toolchain and erlang_vars is
      the directory of version_file.
    
    The field is read with getattr, so providers that do not set it, and
    all existing toolchains, keep the current behaviour. Only the POSIX
    shell scripts support a tree. erlang_headers now double-quotes the
    home so the variable expands.
    
    Add analysis tests with a fake tree toolchain (stub bin/erl, erlc,
    escript): the erl_eval action derives the home and has every tree file
    as input, the eunit script derives it from the short path and has the
    tree in its runfiles, a release-tar toolchain still unpacks its tar,
    and the make variable points at the tree. A sh_test builds erl_eval
    with the tree toolchain and checks that the stub erl ran from the tree.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_011u9TXHDZrfmzFQ2WT8QAKK
    ---
     private/erlang_build.bzl                      |   7 +
     private/otp_tree_test/BUILD.bazel             |  86 +++++++++
     .../otp_tree_test/erl_runs_from_tree_test.sh  |  11 ++
     private/otp_tree_test/fake_otp/OTP_VERSION    |   1 +
     private/otp_tree_test/fake_otp/bin/erl        |   7 +
     private/otp_tree_test/fake_otp/bin/erlc       |   7 +
     private/otp_tree_test/fake_otp/bin/escript    |   7 +
     private/otp_tree_test/fake_release.tar        |   1 +
     private/otp_tree_test/fake_test.beam          |   1 +
     private/otp_tree_test/otp_tree_test.bzl       | 169 ++++++++++++++++++
     tools/erlang_headers.bzl                      |   2 +-
     tools/erlang_toolchain.bzl                    |  24 ++-
     tools/erlang_vars.bzl                         |   4 +-
     13 files changed, 324 insertions(+), 3 deletions(-)
     create mode 100644 private/otp_tree_test/BUILD.bazel
     create mode 100755 private/otp_tree_test/erl_runs_from_tree_test.sh
     create mode 100644 private/otp_tree_test/fake_otp/OTP_VERSION
     create mode 100755 private/otp_tree_test/fake_otp/bin/erl
     create mode 100755 private/otp_tree_test/fake_otp/bin/erlc
     create mode 100755 private/otp_tree_test/fake_otp/bin/escript
     create mode 100644 private/otp_tree_test/fake_release.tar
     create mode 100644 private/otp_tree_test/fake_test.beam
     create mode 100644 private/otp_tree_test/otp_tree_test.bzl
    
    diff --git a/private/erlang_build.bzl b/private/erlang_build.bzl
    index 0448323..37fc754 100644
    --- a/private/erlang_build.bzl
    +++ b/private/erlang_build.bzl
    @@ -29,6 +29,13 @@ installation""",
             "version_file": """A file containing the version of this
     erlang, used to correctly invalidate the cache when an
     external erlang is used""",
    +        "tree": """Optional. A depset of every file of a relocatable
    +erlang installation whose root directory holds version_file. When set,
    +rules put these files in their inputs and runfiles and find the
    +installation next to version_file at run time, so erlang_home,
    +release_dir_tar and install_path are not used by the rules. Only the
    +POSIX shell scripts support it. Providers that do not set this field
    +keep the current behaviour.""",
         },
     )
     
    diff --git a/private/otp_tree_test/BUILD.bazel b/private/otp_tree_test/BUILD.bazel
    new file mode 100644
    index 0000000..77b8b24
    --- /dev/null
    +++ b/private/otp_tree_test/BUILD.bazel
    @@ -0,0 +1,86 @@
    +load("@rules_shell//shell:sh_test.bzl", "sh_test")
    +load("//:erl_eval.bzl", "erl_eval")
    +load("//private:eunit.bzl", "eunit_test")
    +load("//tools:erlang_toolchain.bzl", "erlang_toolchain")
    +load(
    +    ":otp_tree_test.bzl",
    +    "fake_release_otp",
    +    "fake_tree_otp",
    +    "otp_tree_test_suite",
    +    "with_fake_tree_toolchain",
    +)
    +
    +# A relocatable erlang whose files are all in this package. Its bin/
    +# holds shell stubs that record where they ran from.
    +fake_tree_otp(
    +    name = "fake_tree_otp",
    +    srcs = glob(["fake_otp/**"]),
    +    version_file = "fake_otp/OTP_VERSION",
    +)
    +
    +erlang_toolchain(
    +    name = "fake_tree_erlang",
    +    otp = ":fake_tree_otp",
    +)
    +
    +toolchain(
    +    name = "fake_tree_toolchain",
    +    toolchain = ":fake_tree_erlang",
    +    toolchain_type = "//tools:toolchain_type",
    +)
    +
    +# An erlang that ships as a release tar, without a tree.
    +fake_release_otp(
    +    name = "fake_release_otp",
    +    release_dir_tar = "fake_release.tar",
    +    version_file = "fake_otp/OTP_VERSION",
    +)
    +
    +erlang_toolchain(
    +    name = "fake_release_erlang",
    +    otp = ":fake_release_otp",
    +)
    +
    +toolchain(
    +    name = "fake_release_toolchain",
    +    toolchain = ":fake_release_erlang",
    +    toolchain_type = "//tools:toolchain_type",
    +)
    +
    +erl_eval(
    +    name = "where",
    +    outs = ["where.txt"],
    +    expression = "halt().",
    +    tags = ["manual"],
    +)
    +
    +eunit_test(
    +    name = "fake_eunit",
    +    compiled_suites = ["fake_test.beam"],
    +    coverdata_to_lcov = "//tools/coverdata_to_lcov",
    +    eunit_mods = ["fake_test"],
    +    is_windows = False,
    +    tags = ["manual"],
    +)
    +
    +# Runs :where with the tree toolchain, so the stub erl actually runs
    +# from the home that maybe_install_erlang derived.
    +with_fake_tree_toolchain(
    +    name = "where_with_tree",
    +    target = ":where",
    +    toolchain = ":fake_tree_toolchain",
    +)
    +
    +sh_test(
    +    name = "erl_runs_from_tree_test",
    +    srcs = ["erl_runs_from_tree_test.sh"],
    +    args = ["$(rootpath :where_with_tree)"],
    +    data = [":where_with_tree"],
    +    target_compatible_with = select({
    +        "@platforms//os:osx": [],
    +        "@platforms//os:linux": [],
    +        "//conditions:default": ["@platforms//:incompatible"],
    +    }),
    +)
    +
    +otp_tree_test_suite(name = "otp_tree_test")
    diff --git a/private/otp_tree_test/erl_runs_from_tree_test.sh b/private/otp_tree_test/erl_runs_from_tree_test.sh
    new file mode 100755
    index 0000000..0861f98
    --- /dev/null
    +++ b/private/otp_tree_test/erl_runs_from_tree_test.sh
    @@ -0,0 +1,11 @@
    +#!/usr/bin/env bash
    +set -euo pipefail
    +
    +out="$(cat "$1")"
    +case "$out" in
    +"fake erl at /"*/private/otp_tree_test/fake_otp/bin/erl) ;;
    +*)
    +    echo "erl did not run from the tree: $out" >&2
    +    exit 1
    +    ;;
    +esac
    diff --git a/private/otp_tree_test/fake_otp/OTP_VERSION b/private/otp_tree_test/fake_otp/OTP_VERSION
    new file mode 100644
    index 0000000..69c5cbf
    --- /dev/null
    +++ b/private/otp_tree_test/fake_otp/OTP_VERSION
    @@ -0,0 +1 @@
    +0.0-fake
    diff --git a/private/otp_tree_test/fake_otp/bin/erl b/private/otp_tree_test/fake_otp/bin/erl
    new file mode 100755
    index 0000000..56f8339
    --- /dev/null
    +++ b/private/otp_tree_test/fake_otp/bin/erl
    @@ -0,0 +1,7 @@
    +#!/usr/bin/env bash
    +# Stand-in for erl from a relocatable erlang. Writes where it ran from to
    +# every file in $OUTS, so tests can check the derived erlang home.
    +set -euo pipefail
    +for out in ${OUTS:-}; do
    +    echo "fake erl at $0" > "$out"
    +done
    diff --git a/private/otp_tree_test/fake_otp/bin/erlc b/private/otp_tree_test/fake_otp/bin/erlc
    new file mode 100755
    index 0000000..da61700
    --- /dev/null
    +++ b/private/otp_tree_test/fake_otp/bin/erlc
    @@ -0,0 +1,7 @@
    +#!/usr/bin/env bash
    +# Stand-in for erlc from a relocatable erlang. Writes where it ran from to
    +# every file in $OUTS, so tests can check the derived erlang home.
    +set -euo pipefail
    +for out in ${OUTS:-}; do
    +    echo "fake erlc at $0" > "$out"
    +done
    diff --git a/private/otp_tree_test/fake_otp/bin/escript b/private/otp_tree_test/fake_otp/bin/escript
    new file mode 100755
    index 0000000..1b4677b
    --- /dev/null
    +++ b/private/otp_tree_test/fake_otp/bin/escript
    @@ -0,0 +1,7 @@
    +#!/usr/bin/env bash
    +# Stand-in for escript from a relocatable erlang. Writes where it ran from to
    +# every file in $OUTS, so tests can check the derived erlang home.
    +set -euo pipefail
    +for out in ${OUTS:-}; do
    +    echo "fake escript at $0" > "$out"
    +done
    diff --git a/private/otp_tree_test/fake_release.tar b/private/otp_tree_test/fake_release.tar
    new file mode 100644
    index 0000000..3e14aea
    --- /dev/null
    +++ b/private/otp_tree_test/fake_release.tar
    @@ -0,0 +1 @@
    +fake release tar, never unpacked by these tests
    diff --git a/private/otp_tree_test/fake_test.beam b/private/otp_tree_test/fake_test.beam
    new file mode 100644
    index 0000000..4ab92ba
    --- /dev/null
    +++ b/private/otp_tree_test/fake_test.beam
    @@ -0,0 +1 @@
    +not a real beam file; only used for analysis
    diff --git a/private/otp_tree_test/otp_tree_test.bzl b/private/otp_tree_test/otp_tree_test.bzl
    new file mode 100644
    index 0000000..dc8e3a5
    --- /dev/null
    +++ b/private/otp_tree_test/otp_tree_test.bzl
    @@ -0,0 +1,169 @@
    +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
    +load("//private:erlang_build.bzl", "OtpInfo")
    +
    +def _fake_tree_otp_impl(ctx):
    +    return [OtpInfo(
    +        version = "0.0",
    +        release_dir_tar = None,
    +        install_path = None,
    +        # Rules must not use this when tree is set.
    +        erlang_home = "/fake_tree_otp/erlang_home/not/used",
    +        version_file = ctx.file.version_file,
    +        tree = depset(ctx.files.srcs),
    +    )]
    +
    +fake_tree_otp = rule(
    +    implementation = _fake_tree_otp_impl,
    +    attrs = {
    +        "srcs": attr.label_list(allow_files = True, mandatory = True),
    +        "version_file": attr.label(allow_single_file = True, mandatory = True),
    +    },
    +    provides = [OtpInfo],
    +)
    +
    +def _fake_release_otp_impl(ctx):
    +    return [OtpInfo(
    +        version = "0.0",
    +        release_dir_tar = ctx.file.release_dir_tar,
    +        install_path = "/tmp/bazel/erlang/fake",
    +        erlang_home = "/tmp/bazel/erlang/fake",
    +        version_file = ctx.file.version_file,
    +    )]
    +
    +fake_release_otp = rule(
    +    implementation = _fake_release_otp_impl,
    +    attrs = {
    +        "release_dir_tar": attr.label(allow_single_file = True, mandatory = True),
    +        "version_file": attr.label(allow_single_file = True, mandatory = True),
    +    },
    +    provides = [OtpInfo],
    +)
    +
    +def _extra_toolchains_transition_impl(_settings, attr):
    +    return {"//command_line_option:extra_toolchains": [str(attr.toolchain)]}
    +
    +_extra_toolchains_transition = transition(
    +    implementation = _extra_toolchains_transition_impl,
    +    inputs = [],
    +    outputs = ["//command_line_option:extra_toolchains"],
    +)
    +
    +def _with_fake_tree_toolchain_impl(ctx):
    +    return [DefaultInfo(files = depset(ctx.files.target))]
    +
    +with_fake_tree_toolchain = rule(
    +    implementation = _with_fake_tree_toolchain_impl,
    +    attrs = {
    +        "target": attr.label(cfg = _extra_toolchains_transition),
    +        "toolchain": attr.label(),
    +    },
    +)
    +
    +_TREE = str(Label("//private/otp_tree_test:fake_tree_toolchain"))
    +_RELEASE = str(Label("//private/otp_tree_test:fake_release_toolchain"))
    +_TREE_FILES = [
    +    "fake_otp/OTP_VERSION",
    +    "fake_otp/bin/erl",
    +    "fake_otp/bin/erlc",
    +    "fake_otp/bin/escript",
    +]
    +_PKG = "private/otp_tree_test/"
    +_HOME = 'RULES_ERLANG_HOME="$(cd "$(dirname "{}fake_otp/OTP_VERSION")" && pwd)"'.format(_PKG)
    +
    +def _assert_has_tree(env, paths, what):
    +    for f in _TREE_FILES:
    +        asserts.true(env, _PKG + f in paths, "{} misses {}".format(what, f))
    +
    +def _action_with_tree_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    actions = [a for a in analysistest.target_actions(env) if a.argv]
    +    asserts.equals(env, 1, len(actions), "expected one shell action")
    +    if actions:
    +        action = actions[0]
    +        command = " ".join(action.argv)
    +        asserts.true(env, _HOME in command, "home is not derived:\n" + command)
    +        asserts.true(env, '"${RULES_ERLANG_HOME}"/bin/erl' in command, "erl not run from the derived home:\n" + command)
    +        asserts.false(env, "tar" in command, "tree toolchain unpacks a tar:\n" + command)
    +        asserts.false(env, "/fake_tree_otp/erlang_home" in command, "erlang_home used:\n" + command)
    +        _assert_has_tree(env, [f.short_path for f in action.inputs.to_list()], "action inputs")
    +    return analysistest.end(env)
    +
    +action_with_tree_test = analysistest.make(
    +    _action_with_tree_test_impl,
    +    config_settings = {"//command_line_option:extra_toolchains": [_TREE]},
    +)
    +
    +def _test_script_with_tree_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    target = analysistest.target_under_test(env)
    +    writes = [a for a in analysistest.target_actions(env) if a.mnemonic == "FileWrite"]
    +    asserts.equals(env, 1, len(writes), "expected one FileWrite action")
    +    if writes:
    +        script = writes[0].content
    +        asserts.true(env, _HOME in script, "home is not derived from the short path:\n" + script)
    +        asserts.false(env, "/fake_tree_otp/erlang_home" in script, "erlang_home used:\n" + script)
    +    _assert_has_tree(
    +        env,
    +        [f.short_path for f in target[DefaultInfo].default_runfiles.files.to_list()],
    +        "runfiles",
    +    )
    +    return analysistest.end(env)
    +
    +test_script_with_tree_test = analysistest.make(
    +    _test_script_with_tree_test_impl,
    +    config_settings = {"//command_line_option:extra_toolchains": [_TREE]},
    +)
    +
    +def _action_with_release_tar_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    actions = [a for a in analysistest.target_actions(env) if a.argv]
    +    asserts.equals(env, 1, len(actions), "expected one shell action")
    +    if actions:
    +        command = " ".join(actions[0].argv)
    +        asserts.true(env, "tar --extract" in command, "release tar not unpacked:\n" + command)
    +        asserts.false(env, "RULES_ERLANG_HOME" in command, "tree home used without a tree:\n" + command)
    +    return analysistest.end(env)
    +
    +action_with_release_tar_test = analysistest.make(
    +    _action_with_release_tar_test_impl,
    +    config_settings = {"//command_line_option:extra_toolchains": [_RELEASE]},
    +)
    +
    +def _template_vars_test_impl(ctx):
    +    env = analysistest.begin(ctx)
    +    variables = analysistest.target_under_test(env)[platform_common.TemplateVariableInfo].variables
    +    asserts.true(
    +        env,
    +        variables["ERLANG_HOME"].endswith(_PKG + "fake_otp"),
    +        "ERLANG_HOME make variable is " + variables["ERLANG_HOME"],
    +    )
    +    return analysistest.end(env)
    +
    +template_vars_test = analysistest.make(_template_vars_test_impl)
    +
    +def otp_tree_test_suite(name):
    +    action_with_tree_test(
    +        name = "erl_eval_with_tree_test",
    +        target_under_test = ":where",
    +    )
    +    test_script_with_tree_test(
    +        name = "eunit_with_tree_test",
    +        target_under_test = ":fake_eunit",
    +    )
    +    action_with_release_tar_test(
    +        name = "erl_eval_with_release_tar_test",
    +        target_under_test = ":where",
    +    )
    +    template_vars_test(
    +        name = "template_vars_with_tree_test",
    +        target_under_test = ":fake_tree_erlang",
    +    )
    +    native.test_suite(
    +        name = name,
    +        tests = [
    +            ":erl_eval_with_tree_test",
    +            ":eunit_with_tree_test",
    +            ":erl_eval_with_release_tar_test",
    +            ":template_vars_with_tree_test",
    +        ],
    +    )
    diff --git a/tools/erlang_headers.bzl b/tools/erlang_headers.bzl
    index 68fb2a4..913b550 100644
    --- a/tools/erlang_headers.bzl
    +++ b/tools/erlang_headers.bzl
    @@ -31,7 +31,7 @@ def _erlang_headers_impl(ctx):
         outs = []
         for f in ctx.attr.filenames:
             dest = ctx.actions.declare_file(path_join(ctx.label.name, f))
    -        commands.append("cp '{erlang_home}'/usr/include/{f} {dest}".format(
    +        commands.append("cp \"{erlang_home}\"/usr/include/{f} {dest}".format(
                 erlang_home = erlang_home,
                 f = f,
                 dest = dest.path,
    diff --git a/tools/erlang_toolchain.bzl b/tools/erlang_toolchain.bzl
    index 89f4930..7233f7d 100644
    --- a/tools/erlang_toolchain.bzl
    +++ b/tools/erlang_toolchain.bzl
    @@ -3,11 +3,24 @@ load(
         "OtpInfo",
     )
     
    +# The erlang home that rules use when OtpInfo.tree is set. The shell
    +# snippet from maybe_install_erlang assigns this variable.
    +TREE_ERLANG_HOME = "${RULES_ERLANG_HOME}"
    +
    +def _tree(info):
    +    return getattr(info, "tree", None)
    +
    +def template_erlang_home(otpinfo):
    +    """The erlang home for make variables, which are not run through a shell."""
    +    if _tree(otpinfo) != None:
    +        return otpinfo.version_file.dirname
    +    return otpinfo.erlang_home
    +
     def _impl(ctx):
         otpinfo = ctx.attr.otp[OtpInfo]
         vars = {
             "OTP_VERSION": otpinfo.version,
    -        "ERLANG_HOME": otpinfo.erlang_home,
    +        "ERLANG_HOME": template_erlang_home(otpinfo),
         }
         if otpinfo.release_dir_tar != None:
             vars["ERLANG_RELEASE_TAR_PATH"] = otpinfo.release_dir_tar.path
    @@ -40,6 +53,12 @@ def _build_info(ctx):
     
     def erlang_dirs(ctx):
         info = _build_info(ctx)
    +    tree = _tree(info)
    +    if tree != None:
    +        runfiles = ctx.runfiles(
    +            transitive_files = depset([info.version_file], transitive = [tree]),
    +        )
    +        return (TREE_ERLANG_HOME, None, runfiles)
         if info.release_dir_tar != None:
             runfiles = ctx.runfiles([
                 info.release_dir_tar,
    @@ -53,6 +72,9 @@ def erlang_dirs(ctx):
     
     def maybe_install_erlang(ctx, short_path = False):
         info = _build_info(ctx)
    +    if _tree(info) != None:
    +        version_file = info.version_file.short_path if short_path else info.version_file.path
    +        return 'RULES_ERLANG_HOME="$(cd "$(dirname "{}")" && pwd)"'.format(version_file)
         release_dir_tar = info.release_dir_tar
         if release_dir_tar == None:
             return ""
    diff --git a/tools/erlang_vars.bzl b/tools/erlang_vars.bzl
    index 0b26bf4..deee925 100644
    --- a/tools/erlang_vars.bzl
    +++ b/tools/erlang_vars.bzl
    @@ -1,3 +1,5 @@
    +load(":erlang_toolchain.bzl", "template_erlang_home")
    +
     ERLANG_VARS_ENV_MAP = {
         "OTP_VERSION": "$(OTP_VERSION)",
         "OTP_VERSION_FILE_PATH": "$(OTP_VERSION_FILE_PATH)",
    @@ -17,7 +19,7 @@ def _impl(ctx):
             "OTP_VERSION": otpinfo.version,
             "OTP_VERSION_FILE_PATH": otpinfo.version_file.path,
             "OTP_VERSION_FILE_SHORT_PATH": otpinfo.version_file.short_path,
    -        "ERLANG_HOME": otpinfo.erlang_home,
    +        "ERLANG_HOME": template_erlang_home(otpinfo),
         }
         if otpinfo.release_dir_tar != None:
             vars["OTP_INSTALL_PATH"] = otpinfo.install_path
    -- 
    2.53.0

    Coverage of hermetic_otp.patch

    Every hunk is covered.

    Patch hunk PR
    private/erlang_xrl_yrl.bzl {maybe_install_erlang} 1
    erlang_app.bzl tcw/tags, ct.bzl tcw 2
    private/ct.bzl drop -hidden -sname 3
    private/erlang_build.bzl tree, tools/erlang_toolchain.bzl 4

    The four PRs, applied together, were diffed against main + hermetic_otp.patch. Only these intentional differences remain:

    • PR 2: the appup copy also gets target_compatible_with.
    • PR 3: an opt-in attribute auto_sname (default unchanged), not an unconditional removal. The Windows block is covered too.
    • PR 4:
      • The variable is RULES_ERLANG_HOME, exported as TREE_ERLANG_HOME, not DX_ERLANG_HOME.
      • erlang_dirs returns that constant instead of info.erlang_home.
      • The make variable ERLANG_HOME points at the tree.
      • erlang_headers quoting is fixed.
      • The field doc is longer.

    The -sname opt-in is named auto_sname, not distributed. With it off, ct_run still starts a distributed node: its default name is ct, and rules_dx passes -sname undefined.

    rules_dx side

    #4072 replaces hermetic_otp.patch with the combined diff of these four PRs, without their tests. In the same PR:

    • dx_otp loads TREE_ERLANG_HOME.
    • The rules_elixir patch assigns RULES_ERLANG_HOME.
    • ct_suite passes auto_sname = False.

    //erlang/tests/..., //elixir/tests/..., //examples/erlang-app/... and //examples/elixir-app/... pass with it.

    After each upstream merge:

    • Bump pins.bzl.
    • Remove that PR's hunks from the patch (git apply --check against the new pin).
    • Run //erlang/tests/....

    When all four have merged, delete patches/rules_erlang/ and the patches attr in erlang/toolchain/repos.bzl. The rules_elixir tree PR should reuse TREE_ERLANG_HOME rather than define its own variable.

  3. added
    needs-host
    model:opus
    blocked
    on Oct 28, 2026
  4. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Recheck 2026-11-04: still blocked. The maintainer must submit the four upstream PRs from the comment of 2026-10-27 (issue is needs-host). Upstream bazelverse/rules_erlang main is still 13977b3, our pin, and no upstream PR is open. Next: pin bump per merged PR, removing its hunks from hermetic_otp.patch.

  5. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Plan (agent): size S once unblocked
    Decision: an agent opens the four upstream PRs from the 2026-10-27 comment, then drops each PR's hunks here as it merges. Rejected: keep waiting for a manual submit (it has sat 8 days, and AGENTS.md says agents open the upstream PR); one more combined PR upstream (harder to review, the reason for this issue).
    Cause: nothing is broken in rules_dx. #4072 already made patches/rules_erlang/hermetic_otp.patch equal to the four PRs combined, applied at erlang/toolchain/repos.bzl:358. The only open step is upstream submission. bazelverse/rules_erlang main is still 13977b3 (our pin in erlang/toolchain/pins.bzl:10), with no PR from us.
    Change, after "yes":

    1. Fork bazelverse/rules_erlang, then push the four git format-patch commits from the 2026-10-27 comment as four branches on fresh main. Re-check git apply --check first. Open PR 1 to PR 4 with the drafted text and link each one here. The fork has no issue tracker, so the PR is the issue.
    2. patches/rules_erlang/: split hermetic_otp.patch into 01_xrl_yrl.patch, 02_tcw_tags.patch, 03_auto_sname.patch and 04_otp_tree.patch. Each one touches different files. List all four in erlang/toolchain/repos.bzl:358 and BUILD.bazel exports_files. After that, a merged PR means a pin bump plus deleting one file.
    3. After each upstream merge: bump pins.bzl (commit, sha256, url), delete that PR's patch, and confirm the rest still apply. When all four are in, delete the four patches. toolchain_type_alias.patch stays.
      Tests: tools/dx test //erlang/tests/... //elixir/tests/... //examples/erlang-app/... //examples/elixir-app/...
      Host: none. The needs-host label looks wrong: nothing here needs macOS or Windows.
      Upstream: the four PRs to bazelverse/rules_erlang above. The rules_elixir tree PR depends on PR 4.

    Question for owner: may an agent open the four PRs on bazelverse/rules_erlang from your GitHub account? This issue's body says only you submit, and AGENTS.md says agents open upstream PRs. Recommended: yes. Reply "yes", or reply "no, I submit" and post the PR links here.

  6. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Owner decision: yes. Agents submit the drafted upstream PRs from this account (each ends with 'Assisted by Claude.'), then split our patch so each upstream merge is a pin bump plus deleting one patch file.

  7. removed
    blocked
    on Nov 4, 2026
  8. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Owner: before submitting each upstream PR, take extra care that it fits upstream: read their CONTRIBUTING and recent merged PRs, search for existing issues/PRs on the same thing, match their style and commit format, keep the diff minimal and focused, add a regression test in their test layout, and run their tests locally. Get a review pass before opening. Open the upstream issue first if they expect one.

  9. removed
    needs-host
    on Nov 4, 2026
  10. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream PR 1 submitted: issue bazelverse/rules_erlang#11, PR bazelverse/rules_erlang#12 (branch TrapsterDK:pr1). Tests: root 5/5 alone on main; stacked root 15/15 and test/ 17 of 18 pass (1 skipped as incompatible by design).

  11. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream PR 2 submitted: issue bazelverse/rules_erlang#13, PR bazelverse/rules_erlang#14 (branch TrapsterDK:pr2). Root 3/3 alone on main; stacked results as in PR 1.

  12. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream PR 3 submitted: issue bazelverse/rules_erlang#15, PR bazelverse/rules_erlang#16 (branch TrapsterDK:pr3). Root 8/8 alone on main. macOS and Windows jobs not run locally.

  13. TrapsterDK commented on Nov 4, 2026

    @TrapsterDK
    CollaboratorAuthor

    Upstream PR 4 submitted: issue bazelverse/rules_erlang#17, PR bazelverse/rules_erlang#18 (branch TrapsterDK:pr4). Depends on PR 1 (#12) merging first. Root 8/8 alone on main. Review follow-ups not applied (kept diff minimal): Windows scripts do not guard against a tree, shell rule runfiles drop the tree, ERLANG_HOME make variable is execroot-relative.

  14. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor

    Still blocked on upstream: bazelverse/rules_erlang PRs #12, #14, #16, #18 are all open, none merged; upstream main is still 13977b3 (our pin). Nothing to change in-repo until one merges; then drop its patch in a pin-bump PR, one at a time.

  15. added
    blocked
    on Nov 5, 2026
  16. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

    Unblocked: #12, #14, #16, #18 closed

  17. removed
    blocked
    on Nov 5, 2026
  18. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor

    False unblock: the bot matched local #12/#14/#16/#18. Upstream PRs are still open; their CI waits for maintainer approval (action_required). Still blocked.

  19. added
    blocked
    on Nov 5, 2026
  20. TrapsterDK commented on Nov 5, 2026

    @TrapsterDK
    CollaboratorAuthor

    Recheck 2026-11-05: #12/#14/#16/#18 upstream still open, main 13977b3. Split already done (repos.bzl:358). Next: one pin-bump PR per upstream merge.

  21. TrapsterDK commented on Nov 21, 2026

    @TrapsterDK
    CollaboratorAuthor

    rules_erlang patch 08 (08_nif_profile_per_library.patch) sent upstream: issue bazelverse/rules_erlang#22, PR bazelverse/rules_erlang#23. rules_dx header update: #14503.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2blockedmodel:opus

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions