Add support for template_wildcarding; allows files from many directories to be templated.

This commit is contained in:
Dave Smith 2011-03-29 16:42:53 -06:00
parent b7111dce85
commit 3e2baf1a07

View file

@ -290,6 +290,21 @@ execute_overlay([{copy, In, Out} | Rest], Vars, BaseDir, TargetDir) ->
end, end,
rebar_file_utils:cp_r([InFile], OutFile), rebar_file_utils:cp_r([InFile], OutFile),
execute_overlay(Rest, Vars, BaseDir, TargetDir); execute_overlay(Rest, Vars, BaseDir, TargetDir);
execute_overlay([{template_wildcard, Wildcard, OutDir} | Rest], Vars, BaseDir, TargetDir) ->
%% Generate a series of {template, In, Out} instructions from the wildcard
%% that will get processed per normal
Ifun = fun(F, Acc0) ->
[{template, F, filename:join(OutDir, filename:basename(F))} | Acc0]
end,
NewInstrs = lists:foldl(Ifun, Rest, filelib:wildcard(Wildcard, BaseDir)),
case length(NewInstrs) == length(Rest) of
true ->
?WARN("template_wildcard: ~s did not match any files!\n", [Wildcard]);
false ->
ok
end,
?DEBUG("template_wildcard: ~s expanded to ~p\n", [Wildcard, NewInstrs]),
execute_overlay(NewInstrs, Vars, BaseDir, TargetDir);
execute_overlay([{template, In, Out} | Rest], Vars, BaseDir, TargetDir) -> execute_overlay([{template, In, Out} | Rest], Vars, BaseDir, TargetDir) ->
InFile = render(filename:join(BaseDir, In), Vars), InFile = render(filename:join(BaseDir, In), Vars),
{ok, InFileData} = file:read_file(InFile), {ok, InFileData} = file:read_file(InFile),