From e4cb1584efc20fa10d11e0404e9841e7865ea9c1 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 11 Feb 2016 12:11:13 -0600 Subject: [PATCH] Move config/2 and ensure_dir/1 to lr3_util_comp ... and inline SourceExt and TargetExt in run/7 call in compile_dir/4. --- src/lr3_comp.erl | 25 +++++-------------------- src/lr3_comp_util.erl | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/lr3_comp.erl b/src/lr3_comp.erl index 536b87d..b123014 100644 --- a/src/lr3_comp.erl +++ b/src/lr3_comp.erl @@ -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 ...", []), @@ -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]), @@ -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. diff --git a/src/lr3_comp_util.erl b/src/lr3_comp_util.erl index 2ab5b8a..b51c039 100644 --- a/src/lr3_comp_util.erl +++ b/src/lr3_comp_util.erl @@ -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, @@ -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), @@ -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 ->