Skip to content

Commit

Permalink
Remove support Erlang/OTP < 20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledest committed Aug 16, 2024
1 parent 97d85e0 commit cbe5cca
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 578 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/erlang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
version: [27.0, 26.2, 26.1, 26.0, 25.3, 25.2, 25.1, 25.0, 24.3, 24.2, 24.1, 24.0, 23.3, 23.2, 23.1, 23.0, 22.3, 22.2, 22.1, 22.0, 21.3, 21.2, 21.1, 21.0, 20.3, 20.2, 20.1, 20.0]
version: [27.0, 26.2, 26.1, 26.0, 25.3, 25.2, 25.1, 25.0, 24.3, 24.2, 24.1, 24.0, 23.3, 23.2, 23.1, 23.0, 22.3, 22.2, 22.1, 22.0, 21.3, 21.2, 21.1, 21.0, 20.3]
rebar: [rebar, rebar3]
container:
image: erlang:${{ matrix.version }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Parse transformer that implements some new OTP functions in old Erlang/OTP relea

Current version of Erlang/OTP: 27.0.

Supported versions of Erlang/OTP: 20.x, 21.x, 22.x, 23.x, 24.x, 25.x, 26.0, 26.1, 26.2, 27.0.
Supported versions of Erlang/OTP: 20.3, 21.x, 22.x, 23.x, 24.x, 25.x, 26.0, 26.1, 26.2, 27.0.
10 changes: 0 additions & 10 deletions rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ Funs = [{application, get_supervisor, 1},
{erl_pp, legalize_vars, 1},
{erlang, get_stacktrace, 0},
{erlang, get_cookie, 1},
{erlang, iolist_to_iovec, 1},
{erlang, set_cookie, 1},
{erpc, check_response, 3},
{erpc, receive_response, 3},
Expand Down Expand Up @@ -292,7 +291,6 @@ Funs = [{application, get_supervisor, 1},
{ordsets, is_empty, 1},
{ordsets, is_equal, 2},
{ordsets, map, 2},
{os, cmd, 2},
{os, env, 0}, % OTP 24.0
{os, list_env_vars, 0},
{peer, call, 4}, % OTP 25.0
Expand Down Expand Up @@ -331,8 +329,6 @@ Funs = [{application, get_supervisor, 1},
{proc_lib, start_monitor, 5},
{proplists, to_map, 1},
{proplists, to_map, 2},
{pubkey_cert, gen_test_certs, 1},
{pubkey_cert, root_cert, 2},
{pubkey_cert, subject_id, 1},
{pubkey_ocsp, otp_cert, 1},
{pubkey_os_cacerts, clear, 0},
Expand All @@ -353,11 +349,7 @@ Funs = [{application, get_supervisor, 1},
{public_key, encrypt_public, 3},
{public_key, pkix_hash_type, 1},
{public_key, pkix_subject_id, 1},
{public_key, pkix_test_data, 1},
{public_key, pkix_test_root_cert, 2},
{public_key, pkix_verify_hostname_match_fun, 1},
{public_key, sign, 4},
{public_key, verify, 5},
{queue, all, 2},
{queue, any, 2},
{queue, delete, 2},
Expand Down Expand Up @@ -466,10 +458,8 @@ Funs = [{application, get_supervisor, 1},
{zlib, crc32, 3},
{zlib, crc32_combine, 4},
{zlib, getBufSize, 1},
{zlib, inflate, 3},
{zlib, inflateChunk, 1},
{zlib, inflateChunk, 2},
{zlib, safeInflate, 2},
{zlib, setBufSize, 2},
{zlib, compress, 2},
{zlib, gzip, 2},
Expand Down
9 changes: 0 additions & 9 deletions src/otpbp_erlang.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
-module(otpbp_erlang).

-ifndef(HAVE_erlang__iolist_to_iovec_1).
% OTP 20.1
-export([iolist_to_iovec/1]).
-endif.
-ifndef(HAVE_erlang__atom_to_binary_1).
% OTP 23.0
-export([atom_to_binary/1]).
Expand Down Expand Up @@ -41,11 +37,6 @@
-export([set_cookie/1]).
-endif.

-ifndef(HAVE_erlang__iolist_to_iovec_1).
iolist_to_iovec(B) when is_binary(B) -> [B];
iolist_to_iovec(L) -> [list_to_binary(L)].
-endif.

-ifndef(HAVE_erlang__atom_to_binary_1).
atom_to_binary(A) -> atom_to_binary(A, utf8).
-endif.
Expand Down
79 changes: 0 additions & 79 deletions src/otpbp_os.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
-module(otpbp_os).

-ifndef(HAVE_os__cmd_2).
% OTP 20.2.3
-export([cmd/2]).
-endif.
-ifndef(HAVE_os__env_0).
% OTP 24.0
-export([env/0]).
Expand All @@ -19,81 +15,6 @@
-endif.
-endif.

-ifndef(HAVE_os__cmd_2).
cmd(Cmd, Opts) when is_atom(Cmd) -> cmd_(atom_to_list(Cmd), Opts);
cmd(Cmd, Opts) ->
validate(Cmd),
cmd_(Cmd, Opts).

cmd_(Cmd, Opts) ->
{SpawnCmd, SpawnOpts, SpawnInput, Eot} = mk_cmd(Cmd),
Port = open_port({spawn, SpawnCmd}, [binary, stderr_to_stdout, stream, in, hide|SpawnOpts]),
MonRef = monitor(port, Port),
true = port_command(Port, SpawnInput),
Bytes = get_data(Port, MonRef, Eot, [], 0, maps:get(max_size, Opts, infinity)),
demonitor(MonRef, [flush]),
%% Convert to unicode list if possible otherwise return bytes
case unicode:characters_to_list(Bytes) of
String when is_list(String) -> String;
_ -> binary_to_list(Bytes)
end.

mk_cmd(Cmd) ->
%% Have to send command in like this in order to make sh commands like cd and ulimit available
{"/bin/sh -s unix:cmd", [out],
%% We insert a new line after the command, in case the command contains a comment character.
%% The </dev/null closes stdin, which means that programs that use a closed stdin as an termination indicator works.
%% An example of such a program is 'more'.
%% The "echo ^D" is used to indicate that the program has executed and we should return any output we have gotten.
%% We cannot use termination of the child or closing of stdin/stdout as then starting background jobs from os:cmd
%% will block os:cmd.
%% I tried changing this to be "better",
%% but got bombarded with backwards incompatibility bug reports, so leave this as it is.
["(", unicode:characters_to_binary(Cmd), "\n) </dev/null; echo \"\^D\"\n"],
<<$\^D>>}.

validate([C|Rest]) when is_integer(C) -> validate(Rest);
validate([List|Rest]) when is_list(List) ->
validate(List),
validate(Rest);
validate([]) -> ok.

get_data(Port, MonRef, Eot, Sofar, Size, Max) ->
receive
{Port, {data, Bytes}} when Eot =:= <<>> ->
get_data(Port, MonRef, <<>>, [Sofar, Bytes], Size + byte_size(Bytes), Max);
{Port, {data, Bytes}} ->
catch port_close(Port),
flush_until_down(Port, MonRef),
iolist_to_binary([Sofar, eot(Bytes, Eot, Size, Max)]);
{'DOWN', MonRef, _, _, _} ->
flush_exit(Port),
iolist_to_binary(Sofar)
end.

eot(Bs, Eot, Size, Max) ->
MS = Max - Size,
case binary:match(Bs, Eot) of
nomatch when byte_size(Bs) < MS -> more;
{Pos, _} when Pos < MS -> binary:part(Bs, {0, Pos});
_ -> binary:part(Bs, {0, MS})
end.

flush_exit(Port) ->
receive
{'EXIT', Port, _} -> ok
after 0 -> ok
end.

flush_until_down(Port, MonRef) ->
receive
{Port, {data, _Bytes}} -> flush_until_down(Port, MonRef);
{'DOWN', MonRef, _, _, _} -> flush_exit(Port)
end.

-compile({inline, [mk_cmd/1, eot/4]}).
-endif.

-ifndef(HAVE_os__list_env_vars_0).
list_env_vars() -> env().
-endif.
Expand Down
13 changes: 3 additions & 10 deletions src/otpbp_pt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
{{erl_pp, legalize_vars, 1}, otpbp_erl_pp},
{{erlang, get_stacktrace, 0}, otpbp_erlang},
{{erlang, [get_cookie, set_cookie], 1}, otpbp_erlang},
{{erlang, iolist_to_iovec, 1}, otpbp_erlang},
{{erpc, reqids_new, 0}, {maps, new}},
{{erpc, [reqids_size, reqids_to_list], 1}, otpbp_erpc},
{{erpc, [check_response, receive_response, reqids_add, wait_response], 3}, otpbp_erpc},
Expand Down Expand Up @@ -176,7 +175,6 @@
{{ordsets, [filtermap, is_equal, map], 2}, otpbp_ordsets},
{{ordsets, foreach, 2}, otpbp_orddict},
{{ordsets, is_empty, 1}, otpbp_ordsets},
{{os, cmd, 2}, otpbp_os},
{{os, [env, list_env_vars], 0}, otpbp_os},
{{peer, call, [4, 5]}, otpbp_peer},
{{peer, cast, 4}, otpbp_peer},
Expand All @@ -193,8 +191,7 @@
{{proc_lib, start_monitor, [3, 4, 5]}, otpbp_proc_lib},
{{proplists, from_map, 1}, {maps, to_list}}, % OTP 24.0
{{proplists, to_map, [1, 2]}, otpbp_proplists},
{{pubkey_cert, [gen_test_certs, subject_id], 1}, otpbp_pubkey_cert},
{{pubkey_cert, root_cert, 2}, otpbp_pubkey_cert},
{{pubkey_cert, subject_id, 1}, otpbp_pubkey_cert},
{{pubkey_ocsp, otp_cert, 1}, otpbp_pubkey_ocsp},
{{pubkey_os_cacerts, [clear, get], 0}, otpbp_pubkey_os_cacerts},
{{pubkey_os_cacerts, load, [0, 1]}, otpbp_pubkey_os_cacerts},
Expand All @@ -204,14 +201,11 @@
{{public_key, [cacerts_clear, cacerts_get], 0}, otpbp_public_key},
{{public_key, cacerts_load, [0, 1]}, otpbp_public_key},
{{public_key, [encrypt_private, encrypt_public], 3}, otpbp_public_key},
{{public_key, [pkix_hash_type, pkix_subject_id, pkix_test_data], 1}, otpbp_public_key},
{{public_key, [pkix_hash_type, pkix_subject_id], 1}, otpbp_public_key},
{{public_key, pkix_verify_hostname_match_fun, 1}, otpbp_public_key},
{{public_key, pkix_test_root_cert, 2}, otpbp_public_key},
{{public_key, sign, 4}, otpbp_public_key},
{{public_key, ssh_decode, 2}, {ssh_file, decode}},
{{public_key, ssh_encode, 2}, {ssh_file, encode}},
{{public_key, ssh_hostkey_fingerprint, [1, 2]}, {ssh, hostkey_fingerprint}},
{{public_key, verify, 5}, otpbp_public_key},
{{queue, [all, any, delete, delete_r, delete_with, delete_with_r, filtermap, foreach], 2}, otpbp_queue},
{{queue, fold, 3}, otpbp_queue},
{{rand, bytes, 1}, otpbp_rand},
Expand Down Expand Up @@ -257,10 +251,9 @@
{{xmerl_xml_indent, '#element#', 5}, otpbp_xmerl_xml_indent},
{{zlib, [adler32, crc32], [2, 3]}, otpbp_zlib},
{{zlib, [adler32_combine, crc32_combine], 4}, otpbp_zlib},
{{zlib, inflate, 3}, otpbp_zlib},
{{zlib, inflateChunk, [1, 2]}, otpbp_zlib},
{{zlib, getBufSize, 1}, otpbp_zlib},
{{zlib, [safeInflate, setBufSize], 2}, otpbp_zlib},
{{zlib, setBufSize, 2}, otpbp_zlib},
{{zlib, [compress, gzip, zip], 2}, otpbp_zlib}]).
-define(TRANSFORM_BEHAVIOURS, []).

Expand Down
Loading

0 comments on commit cbe5cca

Please sign in to comment.