From a0dcc624d921dec20f796ac858f14582a7fc80a2 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sat, 22 Oct 2011 14:27:19 +0200 Subject: Add -D option --- src/rebar.erl | 4 ++++ src/rebar_erlc_compiler.erl | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/rebar.erl b/src/rebar.erl index 2a23bff..a103d29 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -135,6 +135,9 @@ parse_args(Args) -> %% Check options and maybe halt execution ok = show_info_maybe_halt(Options, NonOptArgs), + GlobalDefines = proplists:get_all_values(defines, Options), + rebar_config:set_global(defines, GlobalDefines), + %% Set global variables based on getopt options set_global_flag(Options, verbose), set_global_flag(Options, force), @@ -263,6 +266,7 @@ option_spec_list() -> {verbose, $v, "verbose", undefined, "Be verbose about what gets done"}, {version, $V, "version", undefined, "Show version information"}, {force, $f, "force", undefined, "Force"}, + {defines, $D, undefined, string, "Define compiler macro"}, {jobs, $j, "jobs", integer, JobsHelp}, {config, $C, "config", string, "Rebar config file to use"} ]. diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 9611097..447cb7c 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -122,14 +122,8 @@ doterl_compile(Config, OutDir) -> doterl_compile(Config, OutDir, MoreSources) -> FirstErls = rebar_config:get_list(Config, erl_first_files, []), - RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []), - ErlOpts = case proplists:is_defined(no_debug_info, RawErlOpts) of - true -> - [O || O <- RawErlOpts, O =/= no_debug_info]; - _ -> - [debug_info|RawErlOpts] - end, - ?DEBUG("erl_opts ~p~n",[ErlOpts]), + ErlOpts = 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. @@ -170,6 +164,18 @@ doterl_compile(Config, OutDir, MoreSources) -> %% Internal functions %% =================================================================== +erl_opts(Config) -> + RawErlOpts = filter_defines(rebar_config:get(Config, erl_opts, []), []), + GlobalDefines = lists:map(fun(D) -> list_to_atom(D) end, + 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]; + _ -> + [debug_info|Opts] + end. + -spec include_path(Source::file:filename(), Config::rebar_config:config()) -> [file:filename(), ...]. include_path(Source, Config) -> -- cgit v1.1