From 394c0f43f88ce7fba9f16f634fd9d006cf42e949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 2 Jul 2012 12:12:17 +0300 Subject: [PATCH] Move erl_opts/1 and src_dirs/1 to rebar_utils.erl These functions will be necessary in rebar_eunit.erl, too. --- src/rebar_erlc_compiler.erl | 45 ++-------------------------------- src/rebar_utils.erl | 48 ++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 7f5268d..be2b59d 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -122,12 +122,12 @@ doterl_compile(Config, OutDir) -> doterl_compile(Config, OutDir, MoreSources) -> 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]), %% 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 = 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, not lists:member(Source, FirstErls)], @@ -166,18 +166,6 @@ doterl_compile(Config, OutDir, MoreSources) -> %% 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(), Config::rebar_config:config()) -> [file:filename(), ...]. include_path(Source, Config) -> @@ -322,11 +310,6 @@ gather_src([], Srcs) -> gather_src([Dir|Rest], Srcs) -> 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()]. dirs(Dir) -> @@ -374,30 +357,6 @@ compile_priority(File) -> lists:foldl(F, normal, Trees) 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 %% diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index ec816b8..f2290e0 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -48,7 +48,9 @@ get_deprecated_global/3, get_deprecated_global/4, get_deprecated_list/4, get_deprecated_list/5, get_deprecated_local/4, get_deprecated_local/5, - delayed_halt/1]). + delayed_halt/1, + erl_opts/1, src_dirs/1 + ]). -include("rebar.hrl"). @@ -452,3 +454,47 @@ vcs_vsn_cmd(Version) -> {unknown, Version}. vcs_vsn_invoke(Cmd, Dir) -> {ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]), 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]).