25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

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"}}
       ]}.
This commit is contained in:
Badlop 2024-07-09 16:35:48 +02:00
parent a935302a19
commit 101cce0c1e

View File

@ -762,8 +762,10 @@ fetch_rebar_deps(SrcDir) ->
{ok, CurDir} = file:get_cwd(), {ok, CurDir} = file:get_cwd(),
file:set_cwd(SrcDir), file:set_cwd(SrcDir),
filelib:ensure_dir(filename:join("deps", ".")), filelib:ensure_dir(filename:join("deps", ".")),
lists:foreach(fun({_App, Cmd}) -> lists:foreach(fun({App, Cmd}) ->
os:cmd("cd deps; "++Cmd++"; cd ..") io:format("Fetching dependency ~s: ", [App]),
Result = os:cmd("cd deps; "++Cmd++"; cd .."),
io:format("~s", [Result])
end, Deps), end, Deps),
file:set_cwd(CurDir) file:set_cwd(CurDir)
end. end.
@ -777,6 +779,19 @@ rebar_deps(Script) ->
_ -> _ ->
[] []
end. 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}}) -> rebar_dep({App, _, {git, Url}}) ->
{App, "git clone "++Url++" "++filename:basename(App)}; {App, "git clone "++Url++" "++filename:basename(App)};
rebar_dep({App, _, {git, Url, {branch, Ref}}}) -> rebar_dep({App, _, {git, Url, {branch, Ref}}}) ->