From 07344608b3482351914424119461448fc9e511f7 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Mon, 7 Oct 2024 08:11:59 +0200 Subject: [PATCH] Remove unneeded dependency if OTP covers it --- rebar.config | 4 +--- rebar.config.script | 13 +++++++++++++ rebar.lock | 9 +-------- src/rebar3_codecov.app.src | 3 +-- src/rebar3_codecov.app.src.script | 17 +++++++++++++++++ src/rebar3_codecov_prv.erl | 18 +++++++++++++++++- 6 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 rebar.config.script create mode 100644 src/rebar3_codecov.app.src.script diff --git a/rebar.config b/rebar.config index a3f2592..ead8209 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,5 @@ {erl_opts, [debug_info]}. -{deps, [ - {jsone, "1.8.0"} - ]}. +{deps, []}. {project_plugins, [rebar3_hex]}. diff --git a/rebar.config.script b/rebar.config.script new file mode 100644 index 0000000..8d723ca --- /dev/null +++ b/rebar.config.script @@ -0,0 +1,13 @@ +{Deps0, Config0} = case lists:keytake(deps, 1, CONFIG) of + false -> {[], CONFIG}; + {value, {deps, D}, Cfg} -> {D, Cfg} + end, + +Deps = case list_to_integer(erlang:system_info(otp_release)) of + N when N >= 27 -> + Deps0; + _ -> + [{jsone, "1.8.0"} | Deps0] + end, + +[{deps, Deps} | Config0]. diff --git a/rebar.lock b/rebar.lock index eb70b2e..57afcca 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,8 +1 @@ -{"1.2.0", -[{<<"jsone">>,{pkg,<<"jsone">>,<<"1.8.0">>},0}]}. -[ -{pkg_hash,[ - {<<"jsone">>, <<"347FF1FA700E182E1F9C5012FA6D737B12C854313B9AE6954CA75D3987D6C06D">>}]}, -{pkg_hash_ext,[ - {<<"jsone">>, <<"08560B78624A12E0B5E7EC0271EC8CA38EF51F63D84D84843473E14D9B12618C">>}]} -]. +[]. diff --git a/src/rebar3_codecov.app.src b/src/rebar3_codecov.app.src index 0d656d5..851e359 100644 --- a/src/rebar3_codecov.app.src +++ b/src/rebar3_codecov.app.src @@ -4,8 +4,7 @@ {registered, []}, {applications, [kernel, - stdlib, - jsone + stdlib ]}, {env,[]}, {modules, []}, diff --git a/src/rebar3_codecov.app.src.script b/src/rebar3_codecov.app.src.script new file mode 100644 index 0000000..b7fcce2 --- /dev/null +++ b/src/rebar3_codecov.app.src.script @@ -0,0 +1,17 @@ +[{application, rebar3_codecov, Config}] = CONFIG, + +{Apps0, Config0} = case lists:keytake(applications, 1, Config) of + false -> + {[], CONFIG}; + {value, {applications, A}, Cfg} -> + {A, Cfg} + end, + +Apps = case list_to_integer(erlang:system_info(otp_release)) of + N when N >= 27 -> + Apps0; + _ -> + [jsone, rfc3339 | Apps0] + end, + +[{application, rebar3_codecov, [{applications, Apps} | Config]}]. diff --git a/src/rebar3_codecov_prv.erl b/src/rebar3_codecov_prv.erl index c619606..9fba857 100644 --- a/src/rebar3_codecov_prv.erl +++ b/src/rebar3_codecov_prv.erl @@ -89,7 +89,7 @@ export_formats(State) -> to_json(SrcDirs, Mod2Data, #{json := true}) -> rebar_api:info("exporting ~s~n", [?JSON_OUT_FILE]), {_SrcDirs, JSON} = maps:fold(fun format_array_to_list/3, {SrcDirs, []}, Mod2Data), - Binary = jsone:encode(#{<<"coverage">> => {JSON}}), + Binary = json_encode(#{<<"coverage">> => {JSON}}), file:write_file(?JSON_OUT_FILE, Binary); to_json(_, _, _) -> ok. @@ -196,3 +196,19 @@ get_excluded_modules(AppInfo) -> end, rebar_api:info("Excluding modules from coverage report ~p~n", [ExcludeModules]), ExcludeModules. + +-ifdef(OTP_RELEASE). + -if(?OTP_RELEASE >= 27). + %% OTP 27 or higher +json_encode(Bin) -> + json:encode(Bin). + -else. + %% OTP 26 to 21. +json_encode(Bin) -> + jsone:encode(Bin). + -endif. +-else. + %% OTP 20 or lower. +json_encode(Bin) -> + jsone:encode(Bin). +-endif.