Browse Source

Merge pull request #351 from tsloughter/dep_hooks

set the dep as the project app before running hooks
pull/356/head
Fred Hebert 10 years ago
parent
commit
520855ee42
3 changed files with 71 additions and 50 deletions
  1. +1
    -1
      src/rebar_base_compiler.erl
  2. +33
    -24
      src/rebar_prv_erlydtl_compiler.erl
  3. +37
    -25
      src/rebar_prv_escriptize.erl

+ 1
- 1
src/rebar_base_compiler.erl View File

@ -114,7 +114,7 @@ compile_each([Source | Rest], Config, CompileFn) ->
skipped ->
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]);
Error ->
?INFO("Compiling ~s failed:",
?ERROR("Compiling ~s failed",
[maybe_absname(Config, Source)]),
maybe_report(Error),
?DEBUG("Compilation failed: ~p", [Error]),

+ 33
- 24
src/rebar_prv_erlydtl_compiler.erl View File

@ -125,39 +125,48 @@ init(State) ->
do(State) ->
?INFO("Running erlydtl...", []),
DtlOpts = proplists:unfold(rebar_state:get(State, erlydtl_opts, [])),
%% We need a project app to store the results under in _build
%% If there is more than 1 project app, check for an app config
%% if that doesn't exist, error out.
case rebar_state:project_apps(State) of
[App] ->
run_erlydtl(App, DtlOpts, State),
{ok, State};
Apps ->
case option(app, DtlOpts) of
undefined ->
?PRV_ERROR(no_main_app);
Name ->
run_erlydtl(rebar_app_utils:find(Name, Apps), DtlOpts, State),
{ok, State}
end
case rebar_state:get(State, escript_main_app, undefined) of
undefined ->
Dir = rebar_state:dir(State),
case rebar_app_discover:find_app(Dir, all) of
{true, AppInfo} ->
AllApps = rebar_state:project_apps(State) ++ rebar_state:all_deps(State),
case rebar_app_utils:find(rebar_app_info:name(AppInfo), AllApps) of
{ok, AppInfo1} ->
%% Use the existing app info instead of newly created one
run_erlydtl(AppInfo1, State);
_ ->
run_erlydtl(AppInfo, State)
end,
{ok, State};
_ ->
?PRV_ERROR(no_main_app)
end;
Name ->
AllApps = rebar_state:project_apps(State) ++ rebar_state:all_deps(State),
{ok, App} = rebar_app_utils:find(Name, AllApps),
run_erlydtl(App, State),
{ok, State}
end.
run_erlydtl(App, DtlOpts, State) ->
Dir = rebar_app_info:dir(App),
run_erlydtl(App, State) ->
Dir = rebar_state:dir(State),
DtlOpts = proplists:unfold(rebar_state:get(State, erlydtl_opts, [])),
TemplateDir = filename:join(Dir, option(doc_root, DtlOpts)),
DtlOpts2 = [{doc_root, TemplateDir} | proplists:delete(doc_root, DtlOpts)],
OutDir = rebar_app_info:ebin_dir(App),
filelib:ensure_dir(filename:join(OutDir, "dummy.beam")),
rebar_base_compiler:run(State,
[],
filename:join(Dir, option(doc_root, DtlOpts)),
option(source_ext, DtlOpts),
TemplateDir,
option(source_ext, DtlOpts2),
OutDir,
option(module_ext, DtlOpts) ++ ".beam",
option(module_ext, DtlOpts2) ++ ".beam",
fun(S, T, C) ->
compile_dtl(C, S, T, DtlOpts, Dir, OutDir)
compile_dtl(C, S, T, DtlOpts2, Dir, OutDir)
end,
[{check_last_mod, false},
{recursive, option(recursive, DtlOpts)}]).
{recursive, option(recursive, DtlOpts2)}]).
-spec format_error(any()) -> iolist().
format_error(no_main_app) ->

+ 37
- 25
src/rebar_prv_escriptize.erl View File

@ -62,17 +62,18 @@ desc() ->
do(State) ->
?INFO("Building escript...", []),
case rebar_state:project_apps(State) of
[App] ->
escriptize(State, App);
Apps ->
case rebar_state:get(State, escript_main_app, undefined) of
undefined ->
?PRV_ERROR(no_main_app);
Name ->
AppInfo = rebar_app_utils:find(Name, Apps),
escriptize(State, AppInfo)
end
case rebar_state:get(State, escript_main_app, undefined) of
undefined ->
case rebar_state:project_apps(State) of
[App] ->
escriptize(State, App);
_ ->
?PRV_ERROR(no_main_app)
end;
Name ->
AllApps = rebar_state:all_deps(State)++rebar_state:project_apps(State),
AppInfo = rebar_app_utils:find(Name, AllApps),
escriptize(State, AppInfo)
end.
escriptize(State0, App) ->
@ -89,8 +90,9 @@ escriptize(State0, App) ->
%% in the output file. We then use the .app files for each of these
%% to pull in all the .beam files.
InclApps = lists:usort(rebar_state:get(State, escript_incl_apps, [])
++ all_deps(State)),
InclBeams = get_app_beams(InclApps),
++ all_deps(State)),
AllApps = rebar_state:all_deps(State)++rebar_state:project_apps(State),
InclBeams = get_apps_beams(InclApps, AllApps),
%% Look for a list of extra files to include in the output file.
%% For internal rebar-private use only. Do not use outside rebar.
@ -139,22 +141,32 @@ format_error(no_main_app) ->
%% Internal functions
%% ===================================================================
get_app_beams(Apps) ->
get_app_beams(Apps, []).
get_apps_beams(Apps, AllApps) ->
get_apps_beams(Apps, AllApps, []).
get_app_beams([], Acc) ->
get_apps_beams([], _, Acc) ->
Acc;
get_app_beams([App | Rest], Acc) ->
case code:lib_dir(App, ebin) of
{error, bad_name} ->
throw(?PRV_ERROR({bad_name, App}));
Path ->
Prefix = filename:join(atom_to_list(App), "ebin"),
Acc2 = load_files(Prefix, "*.beam", Path),
Acc3 = load_files(Prefix, "*.app", Path),
get_app_beams(Rest, Acc3 ++ Acc2 ++ Acc)
get_apps_beams([App | Rest], AllApps, Acc) ->
case rebar_app_utils:find(ec_cnv:to_binary(App), AllApps) of
{ok, App1} ->
OutDir = filename:absname(rebar_app_info:ebin_dir(App1)),
Beams = get_app_beams(App, OutDir),
get_apps_beams(Rest, AllApps, Beams ++ Acc);
_->
case code:lib_dir(App, ebin) of
{error, bad_name} ->
throw(?PRV_ERROR({bad_name, App}));
Path ->
Beams = get_app_beams(App, Path),
get_apps_beams(Rest, AllApps, Beams ++ Acc)
end
end.
get_app_beams(App, Path) ->
Prefix = filename:join(atom_to_list(App), "ebin"),
load_files(Prefix, "*.beam", Path) ++
load_files(Prefix, "*.app", Path).
get_extra(State) ->
Extra = rebar_state:get(State, escript_incl_extra, []),
lists:foldl(fun({Wildcard, Dir}, Files) ->

Loading…
Cancel
Save