Skip to content

feat(OtpInfo): add an optional relocatable tree - #18

Open
TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:pr4
Open

TrapsterDK wants to merge 1 commit into
bazelverse:mainfrom
TrapsterDK:pr4

Conversation

@TrapsterDK

Copy link
Copy Markdown

Fixes #17.

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.

Notes:

Test output (OTP 29.1.2, Bazel 9.2.0, --nohome_rc)

The PR was also checked alone on main (root bazel test //... passes). The output below is from all four of my PRs stacked (bazel test //... in the root, then in 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.1s
//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.1s
//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
//private/xrl_yrl_test:lexer_installs_erlang_test (cached) PASSED in 0.1s
//private/xrl_yrl_test:parser_installs_erlang_test (cached) PASSED in 0.0s
Executed 0 out of 15 tests: 15 tests pass.
//app_file:test_applications_preserved PASSED in 0.1s
//ct_no_sname:no_sname_SUITE PASSED in 3.2s
//custom_vars:custom_var_test PASSED in 0.0s
//dot_app_to_json:dialyze PASSED in 0.9s
//dot_app_to_json:dot_app_to_json_SUITE PASSED in 3.2s
//dot_app_to_json:xref PASSED in 0.6s
//erl_attrs_to_json:dialyze PASSED in 0.9s
//erl_attrs_to_json:erl_attrs_to_json_SUITE PASSED in 3.5s
//erl_attrs_to_json:xref PASSED in 0.3s
//rebar_config_to_json:dialyze PASSED in 0.9s
//rebar_config_to_json:rebar_config_to_json_SUITE PASSED in 3.2s
//rebar_config_to_json:xref PASSED in 0.6s
//shard_suite:dialyze PASSED in 0.9s
//shard_suite:eunit PASSED in 0.5s
//shard_suite:shard_suite_SUITE PASSED in 3.6s
//shard_suite:xref PASSED in 0.6s
//xrl_yrl:xrl_yrl_test PASSED in 0.1s
Executed 17 out of 18 tests: 17 tests pass and 1 was skipped.

Assisted by Claude.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OtpInfo cannot describe an erlang that lives inside the build

1 participant