ext_mod: Improve support for loading *.so files from ext_mod dependencies
Copying files from deps/*/priv/*.so to the ejabberd priv/
is not possible when running ejabberd as OTP release or in a container.
Instead, let's copy the deps/*/priv/*.so maintaining the file structure,
and then using code:add_pathz for those dirs.
This partially reverts 5c1b72853f
This commit is contained in:
parent
3b34538038
commit
c5c7e7fc4d
|
@ -66,7 +66,7 @@ init([]) ->
|
||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
add_paths() ->
|
add_paths() ->
|
||||||
[code:add_patha(module_ebin_dir(Module))
|
[code:add_pathsz([module_ebin_dir(Module)|module_deps_dirs(Module)])
|
||||||
|| {Module, _} <- installed()].
|
|| {Module, _} <- installed()].
|
||||||
|
|
||||||
handle_call(Request, From, State) ->
|
handle_call(Request, From, State) ->
|
||||||
|
@ -229,7 +229,7 @@ install(Package) when is_binary(Package) ->
|
||||||
Module = misc:binary_to_atom(Package),
|
Module = misc:binary_to_atom(Package),
|
||||||
case compile_and_install(Module, Attrs) of
|
case compile_and_install(Module, Attrs) of
|
||||||
ok ->
|
ok ->
|
||||||
code:add_patha(module_ebin_dir(Module)),
|
code:add_pathsz([module_ebin_dir(Module)|module_deps_dirs(Module)]),
|
||||||
ejabberd_config:reload(),
|
ejabberd_config:reload(),
|
||||||
copy_commit_json(Package, Attrs),
|
copy_commit_json(Package, Attrs),
|
||||||
case erlang:function_exported(Module, post_install, 0) of
|
case erlang:function_exported(Module, post_install, 0) of
|
||||||
|
@ -256,7 +256,7 @@ uninstall(Package) when is_binary(Package) ->
|
||||||
|| Host <- ejabberd_option:hosts()],
|
|| Host <- ejabberd_option:hosts()],
|
||||||
code:purge(Module),
|
code:purge(Module),
|
||||||
code:delete(Module),
|
code:delete(Module),
|
||||||
code:del_path(module_ebin_dir(Module)),
|
[code:del_path(PathDelete) || PathDelete <- [module_ebin_dir(Module)|module_deps_dirs(Module)]],
|
||||||
delete_path(module_lib_dir(Module)),
|
delete_path(module_lib_dir(Module)),
|
||||||
ejabberd_config:reload();
|
ejabberd_config:reload();
|
||||||
false ->
|
false ->
|
||||||
|
@ -654,11 +654,12 @@ install(Module, Spec, SrcDir, LibDir) ->
|
||||||
Files1 = [{File, copy(File, filename:join(LibDir, File))}
|
Files1 = [{File, copy(File, filename:join(LibDir, File))}
|
||||||
|| File <- filelib:wildcard("{ebin,priv,conf,include}/**")],
|
|| File <- filelib:wildcard("{ebin,priv,conf,include}/**")],
|
||||||
Files2 = [{File, copy(File, filename:join(LibDir, filename:join(lists:nthtail(2,filename:split(File)))))}
|
Files2 = [{File, copy(File, filename:join(LibDir, filename:join(lists:nthtail(2,filename:split(File)))))}
|
||||||
|| File <- filelib:wildcard("deps/*/{ebin,priv}/**")],
|
|| File <- filelib:wildcard("deps/*/ebin/**")],
|
||||||
|
Files3 = [{File, copy(File, filename:join(LibDir, File))}
|
||||||
|
|| File <- filelib:wildcard("deps/*/priv/**")],
|
||||||
Errors = lists:dropwhile(fun({_, ok}) -> true;
|
Errors = lists:dropwhile(fun({_, ok}) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
end, Files1++Files2),
|
end, Files1++Files2++Files3),
|
||||||
copy_priv_files(LibDir),
|
|
||||||
inform_module_configuration(Module, LibDir, Files1),
|
inform_module_configuration(Module, LibDir, Files1),
|
||||||
Result = case Errors of
|
Result = case Errors of
|
||||||
[{F, {error, E}}|_] ->
|
[{F, {error, E}}|_] ->
|
||||||
|
@ -671,12 +672,6 @@ install(Module, Spec, SrcDir, LibDir) ->
|
||||||
file:set_cwd(CurDir),
|
file:set_cwd(CurDir),
|
||||||
Result.
|
Result.
|
||||||
|
|
||||||
copy_priv_files(LibDir) ->
|
|
||||||
file:set_cwd(LibDir),
|
|
||||||
EjabberdLibDir = code:lib_dir(ejabberd),
|
|
||||||
[{File, copy(File, filename:join(EjabberdLibDir, File))}
|
|
||||||
|| File <- filelib:wildcard("{priv}/**")].
|
|
||||||
|
|
||||||
inform_module_configuration(Module, LibDir, Files1) ->
|
inform_module_configuration(Module, LibDir, Files1) ->
|
||||||
Res = lists:filter(fun({[$c, $o, $n, $f |_], ok}) -> true;
|
Res = lists:filter(fun({[$c, $o, $n, $f |_], ok}) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
|
@ -736,6 +731,14 @@ rebar_dep({App, _, {git, Url, Ref}}) ->
|
||||||
"; (cd "++filename:basename(App)++
|
"; (cd "++filename:basename(App)++
|
||||||
"; git checkout -q "++Ref++")"}.
|
"; git checkout -q "++Ref++")"}.
|
||||||
|
|
||||||
|
module_deps_dirs(Module) ->
|
||||||
|
SrcDir = module_src_dir(Module),
|
||||||
|
LibDir = module_lib_dir(Module),
|
||||||
|
DepsDir = filename:join(LibDir, "deps"),
|
||||||
|
Deps = rebar_deps(filename:join(SrcDir, "rebar.config"))
|
||||||
|
++ rebar_deps(filename:join(SrcDir, "rebar.config.script")),
|
||||||
|
[filename:join(DepsDir, App) || {App, _Cmd} <- Deps].
|
||||||
|
|
||||||
%% -- YAML spec parser
|
%% -- YAML spec parser
|
||||||
|
|
||||||
consult(File) ->
|
consult(File) ->
|
||||||
|
|
Loading…
Reference in New Issue