summaryrefslogtreecommitdiff
path: root/src/rebar_prv_erlydtl_compiler.erl
diff options
context:
space:
mode:
authorViacheslav V. Kovalev <kovyl2404@gmail.com>2015-05-01 00:23:51 +0300
committerViacheslav V. Kovalev <kovyl2404@gmail.com>2015-05-01 00:23:51 +0300
commit33736f32a9a8bfd30711270e8f1376280915d697 (patch)
tree11924915352287650253a73ae7254af241c07625 /src/rebar_prv_erlydtl_compiler.erl
parent29a855d31c7fe7fd7504f5d0ec95c9a55e27276f (diff)
parent7645a1118f0e5cdc27e010905f5072021559ddfd (diff)
Merge branch 'master' into app-discover-profile-duplication
Conflicts: test/rebar_profiles_SUITE.erl
Diffstat (limited to 'src/rebar_prv_erlydtl_compiler.erl')
-rw-r--r--src/rebar_prv_erlydtl_compiler.erl57
1 files changed, 33 insertions, 24 deletions
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) ->