From c15c76f13bd82e6adfaca901d3391fca5ebab35b Mon Sep 17 00:00:00 2001 From: yoshi~ Date: Mon, 2 Dec 2024 22:07:18 +0100 Subject: [PATCH 1/2] fix: do not use code:del_paths since that function is not available on older versions of Erlang. --- CHANGELOG.md | 4 ++++ compiler-cli/templates/gleam@@compile.erl | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 026907d8769..c4c1b3eaae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -227,6 +227,10 @@ the left-hand side was a function call. ([Surya Rose](https://github.com/GearsDatapacks)) + - Fixed a bug where Gleam would be unable to compile to BEAM bytecode on older + versions of Erlang/OTP. + ([yoshi](https://github.com/joshi-monster)) + ## v1.6.1 - 2024-11-19 ### Bug fixed diff --git a/compiler-cli/templates/gleam@@compile.erl b/compiler-cli/templates/gleam@@compile.erl index 3e0a645b737..3cc90cf9dc3 100644 --- a/compiler-cli/templates/gleam@@compile.erl +++ b/compiler-cli/templates/gleam@@compile.erl @@ -150,7 +150,11 @@ add_lib_to_erlang_path(Lib) -> code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). del_lib_from_erlang_path(Lib) -> - code:del_paths(filelib:wildcard([Lib, "/*/ebin"])). + Paths = filelib:wildcard([Lib, "/*/ebin"]), + case erlang:function_exported(code, del_paths, 1) of + true -> code:del_paths(Paths); + false -> lists:foreach(fun code:del_path/1, Paths) + end. configure_logging() -> Enabled = os:getenv("GLEAM_LOG") /= false, From 08bca3952b9368ed4575528a0b15664fceaf67bd Mon Sep 17 00:00:00 2001 From: yoshi~ Date: Tue, 3 Dec 2024 15:02:58 +0100 Subject: [PATCH 2/2] switch to conditional compilations instead of a runtime check --- compiler-cli/templates/gleam@@compile.erl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler-cli/templates/gleam@@compile.erl b/compiler-cli/templates/gleam@@compile.erl index 3cc90cf9dc3..4622976100f 100644 --- a/compiler-cli/templates/gleam@@compile.erl +++ b/compiler-cli/templates/gleam@@compile.erl @@ -147,14 +147,18 @@ do_compile_elixir(Modules, Out) -> end. add_lib_to_erlang_path(Lib) -> - code:add_paths(filelib:wildcard([Lib, "/*/ebin"])). + code:add_paths(expand_lib_paths(Lib)). +-if(?OTP_RELEASE >= 26). del_lib_from_erlang_path(Lib) -> - Paths = filelib:wildcard([Lib, "/*/ebin"]), - case erlang:function_exported(code, del_paths, 1) of - true -> code:del_paths(Paths); - false -> lists:foreach(fun code:del_path/1, Paths) - end. + code:del_paths(expand_lib_paths(Lib)). +-else. +del_lib_from_erlang_path(Lib) -> + lists:foreach(fun code:del_path/1, expand_lib_paths(Lib)). +-endif. + +expand_lib_paths(Lib) -> + filelib:wildcard([Lib, "/*/ebin"]). configure_logging() -> Enabled = os:getenv("GLEAM_LOG") /= false,