From 6a847f95bea2691945caf4f14bbfd73e5d2f242d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 22 Feb 2024 10:42:32 +0100 Subject: [PATCH] Eliminate use of experimental function code:lib_dir/2 The `code:lib_dir/2` function was introduced to support looking into archives. Both archives and the `code:lib_dir/2` are marked as experimental. In the upcoming Erlang/OTP 27 release, `code:lib_dir/2` will be deprecated. In some future release, the archive functionality will be changed (`escript:extract/2` will continue to work, reading archive members using `erl_prim_loader` will not). --- apps/rebar/src/rebar_compiler_erl.erl | 4 ++-- apps/rebar/src/rebar_erlc_compiler.erl | 4 ++-- apps/rebar/src/rebar_prv_dialyzer.erl | 7 ++++--- apps/rebar/src/rebar_prv_escriptize.erl | 5 +++-- vendor/relx/src/rlx_assemble.erl | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/rebar/src/rebar_compiler_erl.erl b/apps/rebar/src/rebar_compiler_erl.erl index 26263edc4..dd7608df1 100644 --- a/apps/rebar/src/rebar_compiler_erl.erl +++ b/apps/rebar/src/rebar_compiler_erl.erl @@ -454,11 +454,11 @@ maybe_expand_include_lib_path(File, Dir) -> [_] -> warn_and_find_path(File, Dir); [Lib | SubDir] -> - case code:lib_dir(list_to_atom(Lib), list_to_atom(filename:join(SubDir))) of + case code:lib_dir(list_to_atom(Lib)) of {error, bad_name} -> warn_and_find_path(File, Dir); AppDir -> - [filename:join(AppDir, File1)] + [filename:join([AppDir] ++ SubDir ++ [File1])] end end. diff --git a/apps/rebar/src/rebar_erlc_compiler.erl b/apps/rebar/src/rebar_erlc_compiler.erl index a1942c567..5539e0c8d 100644 --- a/apps/rebar/src/rebar_erlc_compiler.erl +++ b/apps/rebar/src/rebar_erlc_compiler.erl @@ -755,11 +755,11 @@ maybe_expand_include_lib_path(File, Dir) -> [_] -> warn_and_find_path(File, Dir); [Lib | SubDir] -> - case code:lib_dir(list_to_atom(Lib), list_to_atom(filename:join(SubDir))) of + case code:lib_dir(list_to_atom(Lib)) of {error, bad_name} -> warn_and_find_path(File, Dir); AppDir -> - [filename:join(AppDir, File1)] + [filename:join([AppDir] ++ SubDir ++ [File1])] end end. diff --git a/apps/rebar/src/rebar_prv_dialyzer.erl b/apps/rebar/src/rebar_prv_dialyzer.erl index e4ca0fdb8..ca71e3d11 100644 --- a/apps/rebar/src/rebar_prv_dialyzer.erl +++ b/apps/rebar/src/rebar_prv_dialyzer.erl @@ -298,13 +298,14 @@ app_files(AppName, ExtraDirs) -> end. app_ebin(AppName) -> - case code:lib_dir(AppName, ebin) of + case code:lib_dir(AppName) of {error, bad_name} = Error -> Error; - EbinDir -> + AppDir -> + EbinDir = filename:join(AppDir, "ebin"), case check_ebin(EbinDir) of {error, bad_name} -> - check_ebin(filename:join(code:lib_dir(AppName), "preloaded/ebin")); + check_ebin(filename:join(AppDir, "preloaded/ebin")); Response -> Response end diff --git a/apps/rebar/src/rebar_prv_escriptize.erl b/apps/rebar/src/rebar_prv_escriptize.erl index bad8d67ee..28129d937 100644 --- a/apps/rebar/src/rebar_prv_escriptize.erl +++ b/apps/rebar/src/rebar_prv_escriptize.erl @@ -191,10 +191,11 @@ get_apps_beams([App | Rest], AllApps, Acc) -> Beams = get_app_beams(App, OutDir), get_apps_beams(Rest, AllApps, Beams ++ Acc); _-> - case code:lib_dir(App, ebin) of + case code:lib_dir(App) of {error, bad_name} -> throw(?PRV_ERROR({bad_name, App})); - Path -> + AppDir -> + Path = filename:join(AppDir, "ebin"), Beams = get_app_beams(App, Path), get_apps_beams(Rest, AllApps, Beams ++ Acc) end diff --git a/vendor/relx/src/rlx_assemble.erl b/vendor/relx/src/rlx_assemble.erl index 0b7c6b265..308abb7d6 100644 --- a/vendor/relx/src/rlx_assemble.erl +++ b/vendor/relx/src/rlx_assemble.erl @@ -741,7 +741,7 @@ maybe_check_for_undefined_functions_(State, Release) -> %% without adding the erts application there will be warnings about %% missing functions from the preloaded modules even though they %% are in the runtime. - ErtsApp = code:lib_dir(erts, ebin), + ErtsApp = filename:join(code:lib_dir(erts), "ebin"), %% xref library path is what is searched for functions used by the %% project apps.