|
@ -266,17 +266,29 @@ replace_var([H|T], Acc, Vars) -> |
|
|
|
|
|
|
|
|
%% Load a list of all the files in the escript and on disk |
|
|
%% Load a list of all the files in the escript and on disk |
|
|
find_templates(State) -> |
|
|
find_templates(State) -> |
|
|
%% Cache the files since we'll potentially need to walk it several times |
|
|
|
|
|
%% over the course of a run. |
|
|
|
|
|
Files = cache_escript_files(State), |
|
|
|
|
|
|
|
|
DiskTemplates = find_disk_templates(State), |
|
|
|
|
|
{MainTemplates, Files} = |
|
|
|
|
|
case rebar_state:escript_path(State) of |
|
|
|
|
|
undefined -> |
|
|
|
|
|
{find_priv_templates(State), []}; |
|
|
|
|
|
_ -> |
|
|
|
|
|
%% Cache the files since we'll potentially need to walk it several times |
|
|
|
|
|
%% over the course of a run. |
|
|
|
|
|
F = cache_escript_files(State), |
|
|
|
|
|
{find_escript_templates(F), F} |
|
|
|
|
|
end, |
|
|
|
|
|
AvailTemplates = find_available_templates(DiskTemplates, |
|
|
|
|
|
MainTemplates), |
|
|
|
|
|
?DEBUG("Available templates: ~p\n", [AvailTemplates]), |
|
|
|
|
|
{AvailTemplates, Files}. |
|
|
|
|
|
|
|
|
%% Build a list of available templates |
|
|
|
|
|
|
|
|
find_available_templates(TemplateList1, TemplateList2) -> |
|
|
AvailTemplates = prioritize_templates( |
|
|
AvailTemplates = prioritize_templates( |
|
|
tag_names(find_disk_templates(State)), |
|
|
|
|
|
tag_names(find_escript_templates(Files))), |
|
|
|
|
|
|
|
|
tag_names(TemplateList1), |
|
|
|
|
|
tag_names(TemplateList2)), |
|
|
|
|
|
|
|
|
?DEBUG("Available templates: ~p\n", [AvailTemplates]), |
|
|
?DEBUG("Available templates: ~p\n", [AvailTemplates]), |
|
|
{AvailTemplates, Files}. |
|
|
|
|
|
|
|
|
AvailTemplates. |
|
|
|
|
|
|
|
|
%% Scan the current escript for available files |
|
|
%% Scan the current escript for available files |
|
|
cache_escript_files(State) -> |
|
|
cache_escript_files(State) -> |
|
@ -293,6 +305,12 @@ find_escript_templates(Files) -> |
|
|
|| {Name, _Bin} <- Files, |
|
|
|| {Name, _Bin} <- Files, |
|
|
re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match]. |
|
|
re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match]. |
|
|
|
|
|
|
|
|
|
|
|
find_priv_templates(State) -> |
|
|
|
|
|
OtherTemplates = rebar_utils:find_files(code:priv_dir(rebar), ?TEMPLATE_RE), |
|
|
|
|
|
HomeFiles = rebar_utils:find_files(rebar_dir:template_dir(State), |
|
|
|
|
|
?TEMPLATE_RE, true), % recursive |
|
|
|
|
|
[{file, F} || F <- OtherTemplates ++ HomeFiles]. |
|
|
|
|
|
|
|
|
%% Fetch template indexes that sit on disk in the user's HOME |
|
|
%% Fetch template indexes that sit on disk in the user's HOME |
|
|
find_disk_templates(State) -> |
|
|
find_disk_templates(State) -> |
|
|
OtherTemplates = find_other_templates(State), |
|
|
OtherTemplates = find_other_templates(State), |
|
|