mirror of
https://github.com/correl/rebar.git
synced 2025-04-08 17:00:09 -09:00
Merging
This commit is contained in:
commit
c9d175a30d
2 changed files with 74 additions and 59 deletions
|
@ -52,16 +52,11 @@ clean(_Config, _AppFile) ->
|
||||||
%% Erlang compilation is recursive, so it's possible that we have a nested
|
%% Erlang compilation is recursive, so it's possible that we have a nested
|
||||||
%% directory structure in ebin with .beam files within. As such, we want
|
%% directory structure in ebin with .beam files within. As such, we want
|
||||||
%% to scan whatever is left in the ebin/ directory for sub-dirs which
|
%% to scan whatever is left in the ebin/ directory for sub-dirs which
|
||||||
%% satisfy our criteria. TODO: Is there a better way to do this?
|
%% satisfy our criteria.
|
||||||
Dirs = ordsets:from_list([base_dir(F) ||
|
BeamFiles = rebar_utils:find_files("ebin", "^.*\\.beam$"),
|
||||||
F <- rebar_utils:find_files("ebin", "^.*\\.beam\$")]),
|
rebar_file_utils:delete_each(BeamFiles),
|
||||||
case Dirs of
|
lists:foreach(fun(Dir) -> delete_dir(Dir, dirs(Dir)) end, dirs("ebin")),
|
||||||
[] ->
|
ok.
|
||||||
ok;
|
|
||||||
_ ->
|
|
||||||
ok = rebar_file_utils:rm_rf(string:join(Dirs, " "))
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
@ -164,6 +159,11 @@ compile_mib(Source, _Target, Config) ->
|
||||||
?FAIL
|
?FAIL
|
||||||
end.
|
end.
|
||||||
|
|
||||||
base_dir(Filename) ->
|
dirs(Dir) ->
|
||||||
["ebin" | Rest] = filename:split(Filename),
|
[F || F <- filelib:wildcard(filename:join([Dir, "*"])), filelib:is_dir(F)].
|
||||||
filename:join("ebin", hd(Rest)).
|
|
||||||
|
delete_dir(Dir, []) ->
|
||||||
|
file:del_dir(Dir);
|
||||||
|
delete_dir(Dir, Subdirs) ->
|
||||||
|
lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs),
|
||||||
|
file:del_dir(Dir).
|
||||||
|
|
|
@ -103,31 +103,6 @@ default(out_dir) -> "ebin";
|
||||||
default(source_ext) -> ".dtl";
|
default(source_ext) -> ".dtl";
|
||||||
default(module_ext) -> "_dtl".
|
default(module_ext) -> "_dtl".
|
||||||
|
|
||||||
referenced_dtls(Source, _Target, Config) ->
|
|
||||||
Set = referenced_dtls1([Source], Config,
|
|
||||||
sets:add_element(Source, sets:new())),
|
|
||||||
Final = sets:to_list(sets:del_element(Source, Set)),
|
|
||||||
Final.
|
|
||||||
|
|
||||||
referenced_dtls1(Step, Config, Seen) ->
|
|
||||||
DtlOpts = erlydtl_opts(Config),
|
|
||||||
ExtMatch = re:replace(option(source_ext, DtlOpts), "\.", "\\\\.",
|
|
||||||
[{return, list}]),
|
|
||||||
AllRefs = lists:append(
|
|
||||||
[ string:tokens(
|
|
||||||
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
|
||||||
"\n")
|
|
||||||
|| F <- Step]),
|
|
||||||
DocRoot = option(doc_root, DtlOpts),
|
|
||||||
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
|
|
||||||
Existing = lists:filter(fun filelib:is_file/1, WithPaths),
|
|
||||||
New = sets:subtract(sets:from_list(Existing), Seen),
|
|
||||||
case sets:size(New) of
|
|
||||||
0 -> Seen;
|
|
||||||
_ -> referenced_dtls(sets:to_list(New), Config,
|
|
||||||
sets:union(New, Seen))
|
|
||||||
end.
|
|
||||||
|
|
||||||
compile_dtl(Source, Target, Config) ->
|
compile_dtl(Source, Target, Config) ->
|
||||||
case code:which(erlydtl) of
|
case code:which(erlydtl) of
|
||||||
non_existing ->
|
non_existing ->
|
||||||
|
@ -140,27 +115,67 @@ compile_dtl(Source, Target, Config) ->
|
||||||
"===============================================~n~n", []),
|
"===============================================~n~n", []),
|
||||||
?FAIL;
|
?FAIL;
|
||||||
_ ->
|
_ ->
|
||||||
%% TODO: Check last mod on target and referenced DTLs here..
|
case needs_compile(Source, Target, Config) of
|
||||||
DtlOpts = erlydtl_opts(Config),
|
true ->
|
||||||
%% ensure that doc_root and out_dir are defined,
|
do_compile(Source, Target, Config);
|
||||||
%% using defaults if necessary
|
false ->
|
||||||
Opts = [{out_dir, option(out_dir, DtlOpts)},
|
skipped
|
||||||
{doc_root, option(doc_root, DtlOpts)},
|
|
||||||
report, return],
|
|
||||||
case erlydtl:compile(Source,
|
|
||||||
module_name(Source,DtlOpts),
|
|
||||||
Opts++DtlOpts) of
|
|
||||||
ok -> ok;
|
|
||||||
Reason ->
|
|
||||||
?CONSOLE("Compiling template ~s failed:~n ~p~n",
|
|
||||||
[Source, Reason]),
|
|
||||||
?FAIL
|
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
module_name(DtlPath, DtlOpts) ->
|
do_compile(Source, Target, Config) ->
|
||||||
F = filename:basename(DtlPath),
|
%% TODO: Check last mod on target and referenced DTLs here..
|
||||||
SourceExt = option(source_ext, DtlOpts),
|
DtlOpts = erlydtl_opts(Config),
|
||||||
ModuleExt = option(module_ext, DtlOpts),
|
%% ensure that doc_root and out_dir are defined,
|
||||||
list_to_atom(lists:sublist(F, length(F)-length(SourceExt))
|
%% using defaults if necessary
|
||||||
++ModuleExt).
|
Opts = [{out_dir, option(out_dir, DtlOpts)},
|
||||||
|
{doc_root, option(doc_root, DtlOpts)},
|
||||||
|
report, return],
|
||||||
|
case erlydtl:compile(Source,
|
||||||
|
module_name(Target),
|
||||||
|
Opts++DtlOpts) of
|
||||||
|
ok -> ok;
|
||||||
|
Reason ->
|
||||||
|
?CONSOLE("Compiling template ~s failed:~n ~p~n",
|
||||||
|
[Source, Reason]),
|
||||||
|
?FAIL
|
||||||
|
end.
|
||||||
|
|
||||||
|
module_name(Target) ->
|
||||||
|
F = filename:basename(Target),
|
||||||
|
string:substr(F, 1, length(F)-length(".beam")).
|
||||||
|
|
||||||
|
needs_compile(Source, Target, Config) ->
|
||||||
|
LM = filelib:last_modified(Target),
|
||||||
|
case LM < filelib:last_modified(Source) of
|
||||||
|
true -> true;
|
||||||
|
false ->
|
||||||
|
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
||||||
|
referenced_dtls(Source, Config))
|
||||||
|
end.
|
||||||
|
|
||||||
|
referenced_dtls(Source, Config) ->
|
||||||
|
Set = referenced_dtls1([Source], Config,
|
||||||
|
sets:add_element(Source, sets:new())),
|
||||||
|
Final = sets:to_list(sets:del_element(Source, Set)),
|
||||||
|
Final.
|
||||||
|
|
||||||
|
referenced_dtls1(Step, Config, Seen) ->
|
||||||
|
DtlOpts = erlydtl_opts(Config),
|
||||||
|
ExtMatch = re:replace(option(source_ext, DtlOpts), "\.", "\\\\\\\\.",
|
||||||
|
[{return, list}]),
|
||||||
|
AllRefs = lists:append(
|
||||||
|
[ string:tokens(
|
||||||
|
os:cmd(["grep -o [^\\\"]*",ExtMatch," ",F]),
|
||||||
|
"\n")
|
||||||
|
|| F <- Step]),
|
||||||
|
DocRoot = option(doc_root, DtlOpts),
|
||||||
|
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
|
||||||
|
Existing = lists:filter(fun filelib:is_file/1, WithPaths),
|
||||||
|
New = sets:subtract(sets:from_list(Existing), Seen),
|
||||||
|
case sets:size(New) of
|
||||||
|
0 -> Seen;
|
||||||
|
_ -> referenced_dtls1(sets:to_list(New), Config,
|
||||||
|
sets:union(New, Seen))
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue