summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-04-19 20:21:37 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-04-19 20:21:37 -0400
commit520855ee42c01da17a27dc721fddee0ca1e79b72 (patch)
tree4f818bc04f16bce1e7b772b688fbe66c9414a0ee /src
parent71dfa8eca6a87b29887b0faf09bf2f61b8409485 (diff)
parent8ed91ab761e775cd18cf1b4925421784822215fa (diff)
Merge pull request #351 from tsloughter/dep_hooks
set the dep as the project app before running hooks
Diffstat (limited to 'src')
-rw-r--r--src/rebar_base_compiler.erl2
-rw-r--r--src/rebar_prv_erlydtl_compiler.erl57
-rw-r--r--src/rebar_prv_escriptize.erl62
3 files changed, 71 insertions, 50 deletions
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index df950d7..0101218 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -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]),
diff --git a/src/rebar_prv_erlydtl_compiler.erl b/src/rebar_prv_erlydtl_compiler.erl
index c5fb77a..a7442af 100644
--- a/src/rebar_prv_erlydtl_compiler.erl
+++ b/src/rebar_prv_erlydtl_compiler.erl
@@ -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) ->
diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl
index 12ceaca..03332a0 100644
--- a/src/rebar_prv_escriptize.erl
+++ b/src/rebar_prv_escriptize.erl
@@ -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) ->