Skip to content

Commit 5e5e218

Browse files
authored
Merge pull request #8091 from bjorng/bjorn/kernel/archives/OTP-18966
Deprecate code:lib_dir/2
2 parents 885d12a + cece222 commit 5e5e218

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed
52 Bytes
Binary file not shown.

lib/common_test/src/ct_property_test.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ init_tool(Config) ->
184184
end.
185185

186186
init_tool_extensions(proper) ->
187-
ProperExtDir = code:lib_dir(common_test, proper_ext),
187+
ProperExtDir = filename:join(code:lib_dir(common_test), proper_ext),
188188
true = code:add_patha(ProperExtDir),
189189
ct:log("Added ~ts to code path~n", [ProperExtDir]),
190190
ok;

lib/diameter/src/info/diameter_dbg.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ modules() ->
147147
Mods.
148148

149149
appdir() ->
150-
[_|_] = code:lib_dir(?APP, ebin).
150+
[_|_] = filename:join(code:lib_dir(?APP), "ebin").
151151

152152
%% ----------------------------------------------------------
153153
%% # versions/0

lib/kernel/src/code.erl

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,16 @@ on selected paths.
102102
103103
## Loading of Code From Archive Files
104104
105-
> #### Warning {: .warning }
105+
> #### Change {: .info }
106+
>
107+
> The existing experimental support for archive files will be changed
108+
> in a future release. As of Erlang/OTP 27, the function `code:lib_dir/2`,
109+
> the `-code_path_choice` flag, and using `m:erl_prim_loader` for
110+
> reading files from an archive are deprecated.
106111
>
107-
> The support for loading code from archive files is experimental. The purpose
108-
> of releasing it before it is ready is to obtain early feedback. The file
109-
> format, semantics, interfaces, and so on, can be changed in a future release.
110-
> The function `lib_dir/2` and flag `-code_path_choice` are also experimental.
112+
> `escript` scripts that use archive files should use
113+
> `escript:extract/2` to read data files from its archive instead of using
114+
> `code:lib_dir/2` and `m:erl_prim_loader`.
111115
112116
The Erlang archives are `ZIP` files with extension `.ez`. Erlang archives can
113117
also be [enclosed in `escript`](`m:escript`) files whose file extension is arbitrary.
@@ -167,9 +171,9 @@ directory resolution update).
167171
For each directory on the second level in the application archive (`ebin`,
168172
`priv`, `src`, and so on), the code server first chooses the regular directory
169173
if it exists and second from the archive. Function `code:lib_dir/2` returns the
170-
path to the subdirectory. For example, `code:lib_dir(megaco,ebin)` can return
174+
path to the subdirectory. For example, `code:lib_dir(megaco, ebin)` can return
171175
`/otp/root/lib/megaco-3.9.1.1.ez/megaco-3.9.1.1/ebin` while
172-
`code:lib_dir(megaco,priv)` can return `/otp/root/lib/megaco-3.9.1.1/priv`.
176+
`code:lib_dir(megaco, priv)` can return `/otp/root/lib/megaco-3.9.1.1/priv`.
173177
174178
When an `escript` file contains an archive, there are no restrictions on the
175179
name of the `escript` and no restrictions on how many applications that can be
@@ -178,9 +182,13 @@ level in the archive. At startup, the top directory in the embedded archive and
178182
all (second level) `ebin` directories in the embedded archive are added to the
179183
code path. See [`erts:escript(1)`](`e:erts:escript_cmd.md`).
180184
181-
When the choice of directories in the code path is `strict`, the directory that
182-
ends up in the code path is exactly the stated one. This means that if, for
183-
example, the directory `$OTPROOT/lib/mnesia-4.4.7/ebin` is explicitly added to
185+
A future-proof way for `escript` scripts to read data files from the archive is
186+
to use the `escript:extract/2` function.
187+
188+
When the choice of directories in the code path is `strict` (which is
189+
the default as of Erlang/OTP 27), the directory that ends up in the
190+
code path is exactly the stated one. This means that if, for example,
191+
the directory `$OTPROOT/lib/mnesia-4.4.7/ebin` is explicitly added to
184192
the code path, the code server does not load files from
185193
`$OTPROOT/lib/mnesia-4.4.7.ez/mnesia-4.4.7/ebin`.
186194
@@ -322,6 +330,8 @@ common reasons.
322330
-removed({rehash,0,"the code path cache feature has been removed"}).
323331
-removed({is_module_native,1,"HiPE has been removed"}).
324332

333+
-deprecated([{lib_dir,2,"this functionality will be removed in a future release"}]).
334+
325335
-export_type([load_error_rsn/0, load_ret/0]).
326336
-export_type([prepared_code/0]).
327337
-export_type([module_status/0]).
@@ -787,17 +797,23 @@ Returns `{error, bad_name}` if `Name` is not the name of an application under
787797
lib_dir(App) when is_atom(App) ; is_list(App) -> call({dir,{lib_dir,App}}).
788798

789799
-doc """
800+
> #### Change {: .info }
801+
>
802+
> This function is deprecated and will be removed in a future release.
803+
790804
Returns the path to a subdirectory directly under the top directory of an
791805
application. Normally the subdirectories reside under the top directory for the
792806
application, but when applications at least partly reside in an archive, the
793807
situation is different. Some of the subdirectories can reside as regular
794808
directories while others reside in an archive file. It is not checked whether
795809
this directory exists.
796810
811+
Instead of using this function, use [`code:lib_dir/1`](`code:lib_dir/1`).
812+
797813
_Example:_
798814
799815
```text
800-
> code:lib_dir(megaco, priv).
816+
> filename:join(code:lib_dir(megaco), "priv").
801817
"/usr/local/otp/lib/megaco-3.9.1.1/priv"
802818
```
803819

lib/stdlib/src/otp_internal.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ obsolete(auth, is_auth, 1) ->
3232
{deprecated, "use net_adm:ping/1 instead"};
3333
obsolete(calendar, local_time_to_universal_time, 1) ->
3434
{deprecated, "use calendar:local_time_to_universal_time_dst/1 instead"};
35+
obsolete(code, lib_dir, 2) ->
36+
{deprecated, "this functionality will be removed in a future release"};
3537
obsolete(crypto, rand_uniform, 2) ->
3638
{deprecated, "use rand:uniform/1 instead"};
3739
obsolete(dbg, stop_clear, 0) ->
@@ -221,7 +223,7 @@ obsolete(zlib, setBufSize, 2) ->
221223
obsolete(auth, node_cookie, _) ->
222224
{deprecated, "use erlang:set_cookie/2 and net_adm:ping/1 instead"};
223225
obsolete(mnesia_registry, create_table, _) ->
224-
{deprecated, "Use mnesia:create_table/2 instead", "OTP 28"};
226+
{deprecated, "use mnesia:create_table/2 instead", "OTP 28"};
225227
obsolete(asn1ct, decode, _) ->
226228
{removed, "use Mod:decode/2 instead"};
227229
obsolete(asn1ct, encode, _) ->

system/doc/general_info/DEPRECATIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#
2121
# Added in OTP 27.
2222
#
23-
2423
mnesia_registry:create_table/_ since=27 remove=28
24+
code:lib_dir/2 since=27
2525

2626
#
2727
# Added in OTP 26.

0 commit comments

Comments
 (0)