Skip to content

Commit

Permalink
Move config/2 and ensure_dir/1 to lr3_util_comp
Browse files Browse the repository at this point in the history
... and inline SourceExt and TargetExt in run/7 call in compile_dir/4.
  • Loading branch information
yurrriq committed Feb 11, 2016
1 parent ae6ef3f commit e4cb158
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
25 changes: 5 additions & 20 deletions src/lr3_comp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ compile(Source, Target, Config) ->
end.

compile_dir(Config, FirstFiles, SourceDir, TargetDir) ->
ensure_dir(TargetDir),
SourceExt = ".lfe",
TargetExt = ".beam",
rebar_base_compiler:run(Config, FirstFiles, SourceDir, SourceExt, TargetDir,
TargetExt, fun compile/3).
lr3_comp_util:ensure_dir(TargetDir),
rebar_base_compiler:run(Config, FirstFiles,
SourceDir, ".lfe", TargetDir, ".beam",
fun compile/3).

compile_normal_apps(State) ->
rebar_api:debug("\tCompiling normal LFE apps ...", []),
Expand All @@ -54,7 +53,7 @@ compile_normal_app(AppInfo) ->
OutDir = lr3_comp_util:relative_out_dir(AppInfo),
FirstFiles = lr3_comp_util:get_first_files(Opts, AppDir),
ErlOpts = rebar_opts:erl_opts(Opts),
Config = config(OutDir, ErlOpts),
Config = lr3_comp_util:config(OutDir, ErlOpts),
rebar_api:debug("\tOtherSrcDirs: ~p", [OtherSrcDirs]),
rebar_api:debug("\tAppInfoDir: ~p", [AppDir]),
rebar_api:debug("\tSourceDirs: ~p", [SourceDirs]),
Expand All @@ -66,17 +65,3 @@ compile_normal_app(AppInfo) ->
rebar_api:debug("\tFinished compile.", []),
lr3_comp_util:copy_beam_files(AppInfo, OutDir),
code:add_patha(lr3_comp_util:out_dir(rebar_app_info:dir(AppInfo))).

-spec config(file:dirname(), list()) -> list().
config(OutDir, ErlOpts) ->
[{outdir, OutDir}] ++ ErlOpts ++
[{i, lr3_comp_util:include_dir()}, return, verbose].

-spec ensure_dir(file:dirname()) -> ok.
ensure_dir(OutDir) ->
%% Make sure that ebin/ exists and is on the path
ok = filelib:ensure_dir(filename:join(OutDir, "dummy.beam")),
AbsOutDir = filename:absname(OutDir),
rebar_api:debug("\t\tAdding ~p to path ...", [AbsOutDir]),
true = code:add_patha(AbsOutDir),
ok.
18 changes: 17 additions & 1 deletion src/lr3_comp_util.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
-module(lr3_comp_util).

-export([copy_app_src/1,
-export([config/2,
copy_app_src/1,
copy_beam_files/2,
out_dir/0, out_dir/1,
include_dir/0, include_dir/1,
ensure_dir/1,
get_apps/1,
get_first_files/2,
get_files/2,
Expand All @@ -13,6 +15,11 @@
target_base/2,
relative/1]).

-spec config(file:dirname(), list()) -> list().
config(OutDir, ErlOpts) ->
[{outdir, OutDir}] ++ ErlOpts ++
[{i, lr3_comp_util:include_dir()}, return, verbose].

copy_app_src(AppInfo) ->
rebar_api:debug("\t\tEntered copy_app_src/1 ...", []),
AppDir = rebar_app_info:dir(AppInfo),
Expand Down Expand Up @@ -62,6 +69,15 @@ include_dir() ->
include_dir(AppDir) ->
filename:join(AppDir, "include").

-spec ensure_dir(file:dirname()) -> ok.
ensure_dir(OutDir) ->
%% Make sure that ebin/ exists and is on the path
ok = filelib:ensure_dir(filename:join(OutDir, "dummy.beam")),
AbsOutDir = filename:absname(OutDir),
rebar_api:debug("\t\tAdding ~p to path ...", [AbsOutDir]),
true = code:add_patha(AbsOutDir),
ok.

get_apps(State) ->
case rebar_state:current_app(State) of
undefined ->
Expand Down

0 comments on commit e4cb158

Please sign in to comment.