From 101cce0c1ef699288a93282f808d49326f3bb22c Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 9 Jul 2024 16:35:48 +0200 Subject: [PATCH] ext_mod: Fetch dependencies from hex.pm when mix is available This doesn't work when running an OTP release build using mix, which means it doesn't work in binary installers or containers; only when using relive, or compiled with rebar3. Set the desired hex package version in the module's rebar.config For example, to fetch hex package recon 2.5.5 when mix is available, and otherwise download using git: in the file ejabberd-contrib/ejabberd_observer_cli/rebar.config set both the hex version and git details: {deps, [ {recon, "2.5.5", {git, "https://github.com/ferd/recon"}} ]}. --- src/ext_mod.erl | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ext_mod.erl b/src/ext_mod.erl index dc4e96f2a..2228af99e 100644 --- a/src/ext_mod.erl +++ b/src/ext_mod.erl @@ -762,8 +762,10 @@ fetch_rebar_deps(SrcDir) -> {ok, CurDir} = file:get_cwd(), file:set_cwd(SrcDir), filelib:ensure_dir(filename:join("deps", ".")), - lists:foreach(fun({_App, Cmd}) -> - os:cmd("cd deps; "++Cmd++"; cd ..") + lists:foreach(fun({App, Cmd}) -> + io:format("Fetching dependency ~s: ", [App]), + Result = os:cmd("cd deps; "++Cmd++"; cd .."), + io:format("~s", [Result]) end, Deps), file:set_cwd(CurDir) end. @@ -777,6 +779,19 @@ rebar_deps(Script) -> _ -> [] end. + +rebar_dep({App, Version, Git}) when Version /= ".*" -> + AppS = atom_to_list(App), + Help = os:cmd("mix hex.package"), + case string:find(Help, "mix hex.package fetch") /= nomatch of + true -> + {App, "mix hex.package fetch "++AppS++" "++Version++" --unpack"}; + false -> + io:format("I'll download ~p using git because I can't use Mix " + "to fetch from hex.pm:~n~s", [AppS, help]), + rebar_dep({App, ".*", Git}) + end; + rebar_dep({App, _, {git, Url}}) -> {App, "git clone "++Url++" "++filename:basename(App)}; rebar_dep({App, _, {git, Url, {branch, Ref}}}) ->