mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Improve module install code, allows better error checking
This commit is contained in:
parent
7492ecae52
commit
6987e85602
@ -318,9 +318,23 @@ extract_github_master(Repos, DestDir) ->
|
|||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
copy_file(From, To) ->
|
copy(From, To) ->
|
||||||
|
case filelib:is_dir(From) of
|
||||||
|
true ->
|
||||||
|
Copy = fun(F) ->
|
||||||
|
SubFrom = filename:join(From, F),
|
||||||
|
SubTo = filename:join(To, F),
|
||||||
|
copy(SubFrom, SubTo)
|
||||||
|
end,
|
||||||
|
lists:foldl(fun({ok, C2}, {ok, C1}) -> {ok, C1+C2};
|
||||||
|
({ok, _}, Error) -> Error;
|
||||||
|
(Error, _) -> Error
|
||||||
|
end, {ok, 0},
|
||||||
|
[Copy(filename:basename(X)) || X<-filelib:wildcard(From++"/*")]);
|
||||||
|
false ->
|
||||||
filelib:ensure_dir(To),
|
filelib:ensure_dir(To),
|
||||||
file:copy(From, To).
|
file:copy(From, To)
|
||||||
|
end.
|
||||||
|
|
||||||
delete_path(Path) ->
|
delete_path(Path) ->
|
||||||
case filelib:is_dir(Path) of
|
case filelib:is_dir(Path) of
|
||||||
@ -449,14 +463,9 @@ compile(_Module, _Spec, DestDir) ->
|
|||||||
filelib:ensure_dir(filename:join(Ebin, ".")),
|
filelib:ensure_dir(filename:join(Ebin, ".")),
|
||||||
EjabBin = filename:dirname(code:which(ejabberd)),
|
EjabBin = filename:dirname(code:which(ejabberd)),
|
||||||
EjabInc = filename:join(filename:dirname(EjabBin), "include"),
|
EjabInc = filename:join(filename:dirname(EjabBin), "include"),
|
||||||
Logger = case code:is_loaded(lager) of
|
XmlHrl = filename:join(EjabInc, "xml.hrl"),
|
||||||
{file, _} -> [{d, 'LAGER'}];
|
Logger = [{d, 'LAGER'} || code:is_loaded(lager)=/=false],
|
||||||
_ -> []
|
ExtLib = [{d, 'NO_EXT_LIB'} || filelib:is_file(XmlHrl)],
|
||||||
end,
|
|
||||||
ExtLib = case filelib:is_file(filename:join(EjabInc, "xml.hrl")) of
|
|
||||||
true -> [{d, 'NO_EXT_LIB'}]; %% use include instead of include_lib
|
|
||||||
false -> []
|
|
||||||
end,
|
|
||||||
Options = [{outdir, Ebin}, {i, "include"}, {i, EjabInc},
|
Options = [{outdir, Ebin}, {i, "include"}, {i, EjabInc},
|
||||||
verbose, report_errors, report_warnings]
|
verbose, report_errors, report_warnings]
|
||||||
++ Logger ++ ExtLib,
|
++ Logger ++ ExtLib,
|
||||||
@ -476,11 +485,23 @@ compile(_Module, _Spec, DestDir) ->
|
|||||||
[Error|_] -> Error
|
[Error|_] -> Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
install(Module, _Spec, DestDir) ->
|
install(Module, Spec, DestDir) ->
|
||||||
|
Errors = lists:dropwhile(fun({_, {ok, _}}) -> true;
|
||||||
|
(_) -> false
|
||||||
|
end, [{File, copy(File, filename:join(DestDir, File))}
|
||||||
|
|| File <- filelib:wildcard("{ebin,priv,conf,include}/**")]),
|
||||||
|
Result = case Errors of
|
||||||
|
[{F, {error, E}}|_] ->
|
||||||
|
{error, {F, E}};
|
||||||
|
[] ->
|
||||||
|
SpecPath = proplists:get_value(path, Spec),
|
||||||
SpecFile = filename:flatten([Module, ".spec"]),
|
SpecFile = filename:flatten([Module, ".spec"]),
|
||||||
[copy_file(File, filename:join(DestDir, File))
|
copy(filename:join(SpecPath, SpecFile), filename:join(DestDir, SpecFile))
|
||||||
|| File <- [SpecFile | filelib:wildcard("{ebin,priv,conf,include}/**")]],
|
end,
|
||||||
ok.
|
case Result of
|
||||||
|
{ok, _} -> ok;
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
|
|
||||||
%% -- YAML spec parser
|
%% -- YAML spec parser
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user