diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-05-22 11:49:57 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-05-22 19:10:20 -0500 |
commit | 8a50331898e3c5def85a3c7158c7cefe22a36a5f (patch) | |
tree | 7b1f4a283dc00b61f49c21a06b4f054a13c317d3 | |
parent | b4786b804c8b31a220e9daea753bd0ec3f7a62dd (diff) |
move handling of undefined app state to function
-rw-r--r-- | src/rebar_app_info.erl | 9 | ||||
-rw-r--r-- | src/rebar_prv_clean.erl | 9 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 10 | ||||
-rw-r--r-- | src/rebar_prv_eunit.erl | 9 |
4 files changed, 12 insertions, 25 deletions
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 1b87e0b..9db20e7 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -34,6 +34,7 @@ source/2, state/1, state/2, + state_or_new/2, is_lock/1, is_lock/2, is_checkout/1, @@ -260,6 +261,14 @@ state(AppInfo=#app_info_t{}, State) -> state(#app_info_t{state=State}) -> State. +-spec state_or_new(rebar_state:t(), t()) -> rebar_state:t(). +state_or_new(State, AppInfo=#app_info_t{state=undefined}) -> + AppDir = dir(AppInfo), + C = rebar_config:consult(AppDir), + rebar_state:new(State, C, AppDir); +state_or_new(_State, #app_info_t{state=State}) -> + State. + -spec is_lock(t(), boolean()) -> t(). is_lock(AppInfo=#app_info_t{}, IsLock) -> AppInfo#app_info_t{is_lock=IsLock}. diff --git a/src/rebar_prv_clean.erl b/src/rebar_prv_clean.erl index 272ac26..666ae13 100644 --- a/src/rebar_prv_clean.erl +++ b/src/rebar_prv_clean.erl @@ -67,16 +67,9 @@ format_error(Reason) -> clean_apps(State, Providers, Apps) -> lists:foreach(fun(AppInfo) -> AppDir = rebar_app_info:dir(AppInfo), - S = case rebar_app_info:state(AppInfo) of - undefined -> - C = rebar_config:consult(AppDir), - rebar_state:new(State, C, AppDir); - AppState -> - AppState - end, + S = rebar_app_info:state_or_new(State, AppInfo), ?INFO("Cleaning out ~s...", [rebar_app_info:name(AppInfo)]), - %% Legacy hook support rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, S), rebar_erlc_compiler:clean(State, rebar_app_info:out_dir(AppInfo)), rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, S) diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 5a2e379..4a0fea8 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -71,17 +71,9 @@ build_apps(State, Providers, Apps) -> build_app(State, Providers, AppInfo) -> AppDir = rebar_app_info:dir(AppInfo), OutDir = rebar_app_info:out_dir(AppInfo), - copy_app_dirs(State, AppDir, OutDir), - S = case rebar_app_info:state(AppInfo) of - undefined -> - C = rebar_config:consult(AppDir), - rebar_state:new(State, C, AppDir); - AppState -> - AppState - end, - + S = rebar_app_info:state_or_new(State, AppInfo), compile(S, Providers, AppInfo). compile(State, Providers, AppInfo) -> diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 3ad593d..ff871c8 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -134,14 +134,7 @@ resolve_suites(State, Apps, RawOpts) -> compile_tests(State, TestApps, Suites, RawOpts) -> F = fun(AppInfo) -> - AppDir = rebar_app_info:dir(AppInfo), - S = case rebar_app_info:state(AppInfo) of - undefined -> - C = rebar_config:consult(AppDir), - rebar_state:new(State, C, AppDir); - AppState -> - AppState - end, + S = rebar_app_info:state_or_new(State, AppInfo), ok = rebar_erlc_compiler:compile(replace_src_dirs(S), ec_cnv:to_list(rebar_app_info:out_dir(AppInfo))) end, |