From d05103a4a878c7c65d9fa90df6a6c223d0542d94 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Tue, 19 May 2015 11:41:18 -0700 Subject: methods for retrieving `src_dirs` and `extra_src_dirs` note that now ALL `src_dirs` across included profiles are compiled. previously only the last included profile's `src_dirs` were used --- src/rebar_dir.erl | 37 ++++++++++++++++++++++++++++++++++++- src/rebar_erlc_compiler.erl | 3 +-- src/rebar_otp_app.erl | 5 ++--- src/rebar_prv_compile.erl | 4 +--- 4 files changed, 40 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 8d8a39e..9bff2ab 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -20,7 +20,10 @@ template_dir/1, processing_base_dir/1, processing_base_dir/2, - make_relative_path/2]). + make_relative_path/2, + src_dirs/1, src_dirs/2, + extra_src_dirs/1, extra_src_dirs/2, + all_src_dirs/1, all_src_dirs/3]). -include("rebar.hrl"). @@ -121,3 +124,35 @@ do_make_relative_path([H|T1], [H|T2]) -> do_make_relative_path(Source, Target) -> Base = lists:duplicate(max(length(Target) - 1, 0), ".."), filename:join(Base ++ Source). + +-spec src_dirs(rebar_state:t()) -> list(file:filename_all()). +src_dirs(State) -> src_dirs(State, []). + +-spec src_dirs(rebar_state:t(), list(file:filename_all())) -> list(file:filename_all()). +src_dirs(State, Default) -> + ErlOpts = rebar_utils:erl_opts(State), + Vs = proplists:get_all_values(src_dirs, ErlOpts), + case lists:append(Vs) of + [] -> Default; + Dirs -> Dirs + end. + +-spec extra_src_dirs(rebar_state:t()) -> list(file:filename_all()). +extra_src_dirs(State) -> extra_src_dirs(State, []). + +-spec extra_src_dirs(rebar_state:t(), list(file:filename_all())) -> list(file:filename_all()). +extra_src_dirs(State, Default) -> + ErlOpts = rebar_utils:erl_opts(State), + Vs = proplists:get_all_values(extra_src_dirs, ErlOpts), + case lists:append(Vs) of + [] -> Default; + Dirs -> Dirs + end. + +-spec all_src_dirs(rebar_state:t()) -> list(file:filename_all()). +all_src_dirs(State) -> all_src_dirs(State, [], []). + +-spec all_src_dirs(rebar_state:t(), list(file:filename_all()), list(file:filename_all())) -> + list(file:filename_all()). +all_src_dirs(State, SrcDefault, ExtraDefault) -> + src_dirs(State, SrcDefault) ++ extra_src_dirs(State, ExtraDefault). diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index c7a3474..b9072a3 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -143,8 +143,7 @@ doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> %% Support the src_dirs option allowing multiple directories to %% contain erlang source. This might be used, for example, should %% eunit tests be separated from the core application source. - SrcDirs = [filename:join(Dir, X) || X <- proplists:get_value(src_dirs, ErlOpts, ["src"]) ++ - proplists:get_value(extra_src_dirs, ErlOpts, [])], + SrcDirs = [filename:join(Dir, X) || X <- rebar_dir:all_src_dirs(Config, ["src"], [])], AllErlFiles = gather_src(SrcDirs, []) ++ MoreSources, %% Make sure that ebin/ exists and is on the path diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index e5ad1d2..c457999 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -160,9 +160,8 @@ ebin_modules(State, App, Dir) -> [rebar_utils:beam_to_mod(N) || N <- Filtered]. extra_dirs(State) -> - ErlOpts = rebar_utils:erl_opts(State), - Extras = proplists:get_value(extra_src_dirs, ErlOpts, []), - SrcDirs = proplists:get_value(src_dirs, ErlOpts, ["src"]), + Extras = rebar_dir:extra_src_dirs(State), + SrcDirs = rebar_dir:src_dirs(State, ["src"]), %% remove any dirs that are defined in `src_dirs` from `extra_src_dirs` Extras -- SrcDirs. diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index f70ca28..3265e58 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -119,9 +119,7 @@ copy_app_dirs(State, OldAppDir, AppDir) -> end, filelib:ensure_dir(filename:join(AppDir, "dummy")), %% link to src_dirs to be adjacent to ebin is needed for R15 use of cover/xref - ErlOpts = rebar_utils:erl_opts(State), - SrcDirs = proplists:get_value(src_dirs, ErlOpts, ["src"]) ++ - proplists:get_value(extra_src_dirs, ErlOpts, []), + SrcDirs = rebar_dir:all_src_dirs(State, ["src"], []), [symlink_or_copy(OldAppDir, AppDir, Dir) || Dir <- ["priv", "include"] ++ SrcDirs]; false -> ok -- cgit v1.1