Move erl_opts/1 and src_dirs/1 to rebar_utils.erl

These functions will be necessary in rebar_eunit.erl, too.
This commit is contained in:
Motiejus Jakštys 2012-07-02 12:12:17 +03:00 committed by Tuncer Ayaz
parent ec2f67def8
commit 394c0f43f8
2 changed files with 49 additions and 44 deletions

View file

@ -122,12 +122,12 @@ doterl_compile(Config, OutDir) ->
doterl_compile(Config, OutDir, MoreSources) -> doterl_compile(Config, OutDir, MoreSources) ->
FirstErls = rebar_config:get_list(Config, erl_first_files, []), FirstErls = rebar_config:get_list(Config, erl_first_files, []),
ErlOpts = erl_opts(Config), ErlOpts = rebar_utils:erl_opts(Config),
?DEBUG("erl_opts ~p~n", [ErlOpts]), ?DEBUG("erl_opts ~p~n", [ErlOpts]),
%% Support the src_dirs option allowing multiple directories to %% Support the src_dirs option allowing multiple directories to
%% contain erlang source. This might be used, for example, should %% contain erlang source. This might be used, for example, should
%% eunit tests be separated from the core application source. %% eunit tests be separated from the core application source.
SrcDirs = src_dirs(proplists:append_values(src_dirs, ErlOpts)), SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts)),
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources, RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
not lists:member(Source, FirstErls)], not lists:member(Source, FirstErls)],
@ -166,18 +166,6 @@ doterl_compile(Config, OutDir, MoreSources) ->
%% Internal functions %% Internal functions
%% =================================================================== %% ===================================================================
erl_opts(Config) ->
RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []),
GlobalDefines = [{d, list_to_atom(D)} ||
D <- rebar_config:get_global(defines, [])],
Opts = GlobalDefines ++ RawErlOpts,
case proplists:is_defined(no_debug_info, Opts) of
true ->
[O || O <- Opts, O =/= no_debug_info];
false ->
[debug_info|Opts]
end.
-spec include_path(Source::file:filename(), -spec include_path(Source::file:filename(),
Config::rebar_config:config()) -> [file:filename(), ...]. Config::rebar_config:config()) -> [file:filename(), ...].
include_path(Source, Config) -> include_path(Source, Config) ->
@ -322,11 +310,6 @@ gather_src([], Srcs) ->
gather_src([Dir|Rest], Srcs) -> gather_src([Dir|Rest], Srcs) ->
gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")). gather_src(Rest, Srcs ++ rebar_utils:find_files(Dir, ".*\\.erl\$")).
-spec src_dirs(SrcDirs::[string()]) -> [file:filename(), ...].
src_dirs([]) ->
["src"];
src_dirs(SrcDirs) ->
SrcDirs.
-spec dirs(Dir::file:filename()) -> [file:filename()]. -spec dirs(Dir::file:filename()) -> [file:filename()].
dirs(Dir) -> dirs(Dir) ->
@ -374,30 +357,6 @@ compile_priority(File) ->
lists:foldl(F, normal, Trees) lists:foldl(F, normal, Trees)
end. end.
%%
%% Filter a list of erl_opts platform_define options such that only
%% those which match the provided architecture regex are returned.
%%
-spec filter_defines(ErlOpts::list(), Acc::list()) -> list().
filter_defines([], Acc) ->
lists:reverse(Acc);
filter_defines([{platform_define, ArchRegex, Key} | Rest], Acc) ->
case rebar_utils:is_arch(ArchRegex) of
true ->
filter_defines(Rest, [{d, Key} | Acc]);
false ->
filter_defines(Rest, Acc)
end;
filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
case rebar_utils:is_arch(ArchRegex) of
true ->
filter_defines(Rest, [{d, Key, Value} | Acc]);
false ->
filter_defines(Rest, Acc)
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).
%% %%
%% Ensure all files in a list are present and abort if one is missing %% Ensure all files in a list are present and abort if one is missing
%% %%

View file

@ -48,7 +48,9 @@
get_deprecated_global/3, get_deprecated_global/4, get_deprecated_global/3, get_deprecated_global/4,
get_deprecated_list/4, get_deprecated_list/5, get_deprecated_list/4, get_deprecated_list/5,
get_deprecated_local/4, get_deprecated_local/5, get_deprecated_local/4, get_deprecated_local/5,
delayed_halt/1]). delayed_halt/1,
erl_opts/1, src_dirs/1
]).
-include("rebar.hrl"). -include("rebar.hrl").
@ -452,3 +454,47 @@ vcs_vsn_cmd(Version) -> {unknown, Version}.
vcs_vsn_invoke(Cmd, Dir) -> vcs_vsn_invoke(Cmd, Dir) ->
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]), {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
string:strip(VsnString, right, $\n). string:strip(VsnString, right, $\n).
%% @doc Return list of erl_opts
-spec erl_opts(rebar_config:config()) -> list().
erl_opts(Config) ->
RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []),
GlobalDefines = [{d, list_to_atom(D)} ||
D <- rebar_config:get_global(defines, [])],
Opts = GlobalDefines ++ RawErlOpts,
case proplists:is_defined(no_debug_info, Opts) of
true ->
[O || O <- Opts, O =/= no_debug_info];
false ->
[debug_info|Opts]
end.
-spec src_dirs(SrcDirs::[string()]) -> [file:filename(), ...].
src_dirs([]) ->
["src"];
src_dirs(SrcDirs) ->
SrcDirs.
%%
%% Filter a list of erl_opts platform_define options such that only
%% those which match the provided architecture regex are returned.
%%
-spec filter_defines(ErlOpts::list(), Acc::list()) -> list().
filter_defines([], Acc) ->
lists:reverse(Acc);
filter_defines([{platform_define, ArchRegex, Key} | Rest], Acc) ->
case rebar_utils:is_arch(ArchRegex) of
true ->
filter_defines(Rest, [{d, Key} | Acc]);
false ->
filter_defines(Rest, Acc)
end;
filter_defines([{platform_define, ArchRegex, Key, Value} | Rest], Acc) ->
case rebar_utils:is_arch(ArchRegex) of
true ->
filter_defines(Rest, [{d, Key, Value} | Acc]);
false ->
filter_defines(Rest, Acc)
end;
filter_defines([Opt | Rest], Acc) ->
filter_defines(Rest, [Opt | Acc]).