Skip to content

Ensure directory exists before writing the beam file... - #508

Merged
rvirding merged 1 commit into
lfe:developfrom
diasbruno:ensure-directory-exists-before-writing-beam-file
Jul 11, 2026
Merged

rvirding merged 1 commit into
lfe:developfrom
diasbruno:ensure-directory-exists-before-writing-beam-file

Conversation

@diasbruno

@diasbruno diasbruno commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor

This happend when integrating with a mix project.

Screenshot 2025-11-03 at 19 55 19

From this image, the lfe path inside the prod/lib wasn't created.

Ensuring the directory is created fixed the problem, but not sure who should be responsible for creating the directory.

This patch fixes the lfe (tool) compilation. There is still issue on the rebar/mix integration to be addressed.

closes #489

@diasbruno

Copy link
Copy Markdown
Contributor Author

Ah this function is Erlang 25+. So, if we need to be compatible with older version we need to provide the function.

@diasbruno

diasbruno commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor Author

@oubiwann @rvirding What is the older version LFE will support?

EDIT: made a polyfill for the function.

@diasbruno
diasbruno force-pushed the ensure-directory-exists-before-writing-beam-file branch from 024134a to 1acfa01 Compare November 3, 2025 23:25
@oubiwann

oubiwann commented Nov 3, 2025

Copy link
Copy Markdown
Member

Right now, we're supporting 20+, but I have a PR (#504) that's waiting for Robert's approval which will remove Erlang 20 and 21 (mostly just to make our lives easier with CI/CD and avoid the need for maintaining custom build images for versions of Ubuntu that GH doesn't support).

Comment thread src/lfe_comp.erl Resolved
Comment thread src/lfe_comp.erl Resolved
@oubiwann

oubiwann commented Nov 6, 2025

Copy link
Copy Markdown
Member

If you ran into this issue in a mix plugin, it should be fixed there (or in whatever the mix plugin is calling). There's a long discussion going on about that right now :-)

However!

This change is absolutely tool agnostic, so I have no objections to it :-)

That being said, when looking at the code it seems a bit redundant ... extra work for no apparent reason. As such, I'd recommend the addition of a code comment before the call to ensure_path_exists/1 in beam_write_module/2, something along the lines of "this additional check was added to support special-case situations where LFE was being compiled to non-standard paths using tools that expected these paths to already exist."

@diasbruno

Copy link
Copy Markdown
Contributor Author

Ensuring the directory is created fixed the problem, but not sure who should be responsible for creating the directory.

This is the last bit I wrote about this. $REBAR_DEPS_DIR/lfe/ebin this indicates (not sure) that rebar should be responsible for setting this variable - probably defined and passed from mix since it needs to add the environment to the build path (prod, dev, test...).

We can accept this patch since it won't cause much problems, but I'll try to understand where and in which tool the path should be created.

Also, I have no objections in retiring this PR.

@diasbruno
diasbruno force-pushed the ensure-directory-exists-before-writing-beam-file branch from 1acfa01 to b1cefa5 Compare November 7, 2025 00:34
Comment thread src/lfe_comp.erl Resolved

@oubiwann oubiwann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from me :-)

We'll see what Robert has to say!

@diasbruno

Copy link
Copy Markdown
Contributor Author

I think I got what's going on...

The LFE is been compiled first to the rebar3 cache.

===> Fetching rebar3_lfe (from {git,"https://github.com/diasbruno/rebar3_lfe.git",
                     {branch,"paths"}})
===> Fetching lfe (from {git,"https://github.com/diasbruno/lfe",
              {tag,"ensure-directory-exists-before-writing-beam-file"}})
===> Evaluating config script "/Users/dias/.cache/rebar3/plugins/lfe/rebar.config.script"
===> Compile (apps)
===> Running hooks for compile in app lfe (/Users/dias/.cache/rebar3/plugins/lfe) with configuration:
===> 	{pre_hooks, []}.
===> Running hooks for compile in app rebar3_lfe (/Users/dias/.cache/rebar3/plugins/rebar3_lfe) with configuration:
===> 	{pre_hooks, []}.
===> Running hooks for erlc_compile in app lfe (/Users/dias/.cache/rebar3/plugins/lfe) with configuration:
===> 	{pre_hooks, []}.
===> Running hooks for erlc_compile in app rebar3_lfe (/Users/dias/.cache/rebar3/plugins/rebar3_lfe) with configuration:
===> 	{pre_hooks, []}.
===> Analyzing applications...
===> Compiling lfe
===> compile options: {erl_opts, [debug_info,
                                 {d,'ERLANG_VERSION',"27.3.4.3"},
                                 {d,'HAS_MAPS',true},
                                 {d,'HAS_FULL_KEYS',true},
                                 {d,'NEW_REC_CORE',true},
                                 {d,'NEW_RAND',true},
                                 {d,'NEW_BOOL_GUARD',true},
                                 {d,'HAS_FLOOR',true},
                                 {d,'HAS_CEIL',true},
                                 {d,'NEW_STACKTRACE',true},
                                 {d,'EEP48',true},
                                 {d,'HAS_ENSURE_DIR',true},
                                 {d,'OTP27_MAYBE',true}]}.
===> files to analyze ["/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_edlin_expand.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_shell.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_internal.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_macro_export.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_io_write.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_docs.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_lib.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_codegen.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_comp.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_struct.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfescript.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_gen.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/scm.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_io_format.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_codelift.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_scan.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_lint.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_macro_record.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_bits.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_init.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_abstract_code.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_io_pretty.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_translate.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_macro_struct.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_error.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_shell_docs.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_macro_include.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_eval.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_eval_bits.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_ms.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_qlc.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_macro.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_parse.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_env.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_types.erl",
                      "/Users/dias/.cache/rebar3/plugins/lfe/src/lfe_io.erl"]
===>      Compiled lfe_init.erl
===>      Compiled lfe_struct.erl
===>      Compiled lfe_eval_bits.erl
===>      Compiled lfe_docs.erl
===>      Compiled lfe_macro_include.erl
===>      Compiled lfe_macro_struct.erl
===>      Compiled lfe_codelift.erl
===>      Compiled lfe_lib.erl
===>      Compiled lfe_shell_docs.erl
===>      Compiled lfe_macro_record.erl
===>      Compiled lfe_gen.erl
===>      Compiled lfescript.erl
===>      Compiled lfe_internal.erl
===>      Compiled scm.erl
===>      Compiled lfe_bits.erl
===>      Compiled lfe_io_pretty.erl
===>      Compiled lfe_io_format.erl
===>      Compiled lfe_io_write.erl
===>      Compiled lfe_io.erl
===>      Compiled lfe_codegen.erl
===>      Compiled lfe_parse.erl
===>      Compiled lfe_edlin_expand.erl
===>      Compiled lfe_types.erl
===>      Compiled lfe_ms.erl
===>      Compiled lfe_abstract_code.erl
===>      Compiled lfe_macro.erl
===>      Compiled lfe_shell.erl
===>      Compiled lfe.erl
===>      Compiled lfe_macro_export.erl
===>      Compiled lfe_qlc.erl
===>      Compiled lfe_error.erl
===>      Compiled lfe_env.erl
===>      Compiled lfe_comp.erl
===>      Compiled lfe_lint.erl
===>      Compiled lfe_scan.erl
===>      Compiled lfe_eval.erl
===>      Compiled lfe_translate.erl
===> Compiling rebar3_lfe
===> compile options: {erl_opts, [debug_info,warnings_as_errors,
                                 warn_export_vars,warn_shadow_vars,
                                 warn_obsolete_guard]}.
===> files to analyze ["/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_dependency_scanner.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_release.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_dep_cache.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_escriptize.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_progress.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_completion.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_versions.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_confabulate.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_compile_opts.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_compile_worker.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_config.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_rlwrap.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_repl.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_compile.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_clean.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_eval.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_package_tracker.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/rebar3_lfe.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_compiler_mod.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_package.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_run_release.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_ltest.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_run_escript.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_util.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_prv_run.erl",
                      "/Users/dias/.cache/rebar3/plugins/rebar3_lfe/src/r3lfe_paths.erl"]
===>      Compiled r3lfe_completion.erl
===>      Compiled r3lfe_prv_escriptize.erl
===>      Compiled r3lfe_prv_ltest.erl
===>      Compiled r3lfe_prv_versions.erl
===>      Compiled r3lfe_dependency_scanner.erl
===>      Compiled rebar3_lfe.erl
===>      Compiled r3lfe_package.erl
===>      Compiled r3lfe_prv_confabulate.erl
===>      Compiled r3lfe_paths.erl
===>      Compiled r3lfe_util.erl
===>      Compiled r3lfe_rlwrap.erl
===>      Compiled r3lfe_package_tracker.erl
===>      Compiled r3lfe_prv_compile.erl
===>      Compiled r3lfe_prv_run_escript.erl
===>      Compiled r3lfe_prv_clean.erl
===>      Compiled r3lfe_compile_worker.erl
===>      Compiled r3lfe_prv_run.erl
===>      Compiled r3lfe_dep_cache.erl
===>      Compiled r3lfe_progress.erl
===>      Compiled r3lfe_compile_opts.erl
===>      Compiled r3lfe_compiler_mod.erl
===>      Compiled r3lfe_prv_eval.erl
===>      Compiled r3lfe_prv_repl.erl
===>      Compiled r3lfe_prv_release.erl
===>      Compiled r3lfe_config.erl
===>      Compiled r3lfe_prv_run_release.erl

Later on, the pre_hook is executed with $REBAR_DEPS_DIR been the path that mix defined. And this would explain why it needs to ensure the path exists on the LFE lfec.

===> Running hooks for app_compile in app lfe (/Users/dias/.cache/rebar3/plugins/lfe) with configuration:
===> 	{pre_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)",
                      app_compile,
                      "bin/lfescript bin/lfec -o $REBAR_DEPS_DIR/lfe/ebin src/*.lfe"}]}.
src/cl.lfe:472: Warning: redefining core function car/1
src/cl.lfe:479: Warning: redefining core function cdr/1

this happend when integrating with a mix project.
@diasbruno
diasbruno force-pushed the ensure-directory-exists-before-writing-beam-file branch from e229c1d to 9f59b34 Compare November 15, 2025 12:57
@rvirding
rvirding merged commit 938b112 into lfe:develop Jul 11, 2026
rvirding pushed a commit that referenced this pull request Jul 12, 2026
* Makefile: split DESTDIR and PREFIX  (#513)

* Makefile: use portable "command -v" instead of the "which" command

Signed-off-by: Maciej Barć <[email protected]>

* Makefile: split DESTDIR and PREFIX

* Use DESTDIR as the output directory, default to /.  Normally it
  would be used like so: make DESTDIR="$(pwd)/image/" install
* Run MANDB only if DESTDIR is /, so only when we install onto the
  system root.

Signed-off-by: Maciej Barć <[email protected]>

---------

Signed-off-by: Maciej Barć <[email protected]>

* Bug/517/otp 28 user drv (#518)

* Added failing tests for issue #517.

See: #517

* Fix for OTP 28 user_drv behaviour change.

Three-branch version dispatch using list_to_integer(OTPRelease) instead of string comparison:
- OTP 28+: user_drv:start(#{initial_shell => noshell, input => cooked}) — provides the required input key
- OTP 26-27: user_drv:start(#{initial_shell => noshell}) — unchanged, input defaults to true
- OTP <26: user:start() — the legacy API

* Updated OTP versions for CI.

* Implement this less awkwardly.

* We need the full build for the new CT test.

* Addressed review feedback.

* ensure directory exists before writing the beam file... (#508)

this happend when integrating with a mix project.

* Feature/271/clj prints (#519)

* Added tests for new clj print macros.

* Implemented clj print functions.

* Updated docs.

* Feature/277/clj update in (#520)

* Added implementations for update, update-in, assoc, assoc-in.

* Updated docs for new clj functions/macros.

* Fix lfe_init_SUITE ERL_LIBS to target the compiled lfe app

The suite spawns bin/lfe and set ERL_LIBS to the repo root, which is
not a valid OTP library directory for the lfe app: the compiled beams
(including lfe_init.beam) live in _build/<profile>/lib/lfe/ebin, while
the root ebin/ holds only lfe.app. bin/lfe could therefore only find
lfe_init via its fallback rebar3 path, which defaults to the `default`
profile.

CI stayed green because the builds job runs `rebar3 compile` (populating
_build/default/lib/lfe/ebin) before `make ct`. A bare `rebar3 ct` -- or
`make tests`, which cleans _build and builds only the test profile --
never populates the default profile, so lfe_init was absent from the
resolved code path and the kernel user child failed with
{undef,[{lfe_init,start,[],[]}...]}.

Derive ERL_LIBS from the running app instead: the parent of
code:lib_dir('lfe') is the actual _build/<profile>/lib dir containing
the compiled lfe app, making the suite independent of which rebar3
profile happens to be pre-built. bin/lfe is still located from the repo
root as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Signed-off-by: Maciej Barć <[email protected]>
Co-authored-by: Maciej Barć <[email protected]>
Co-authored-by: Bruno Dias <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

(Mix) Could not compile dependency :lfe - Elixir 1.15.7 OTP 26

3 participants