summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl3
-rw-r--r--src/rebar_config.erl21
-rw-r--r--src/rebar_core.erl5
-rw-r--r--src/rebar_eunit.erl16
-rw-r--r--src/rebar_port_compiler.erl28
-rw-r--r--src/rebar_utils.erl33
6 files changed, 57 insertions, 49 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index c0c6c97..b6e0ce4 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -108,9 +108,10 @@ run_aux(Commands) ->
false ->
rebar_config:new()
end,
+ BaseConfig = rebar_config:base_config(GlobalConfig),
%% Process each command, resetting any state between each one
- rebar_core:process_commands(CommandAtoms, GlobalConfig).
+ rebar_core:process_commands(CommandAtoms, BaseConfig).
%%
%% print help/usage string
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 9d2acf3..06396d8 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -26,7 +26,7 @@
%% -------------------------------------------------------------------
-module(rebar_config).
--export([new/0, new/1,
+-export([new/0, new/1, base_config/1,
get/3, get_local/3, get_list/3,
get_all/2,
set/3,
@@ -48,9 +48,13 @@
%% Public API
%% ===================================================================
+base_config(#config{opts=Opts0}) ->
+ ConfName = rebar_config:get_global(config, "rebar.config"),
+ new(Opts0, ConfName).
+
new() ->
#config { dir = rebar_utils:get_cwd(),
- opts = []}.
+ opts = [] }.
new(ConfigFile) when is_list(ConfigFile) ->
case consult_file(ConfigFile) of
@@ -60,17 +64,10 @@ new(ConfigFile) when is_list(ConfigFile) ->
Other ->
?ABORT("Failed to load ~s: ~p~n", [ConfigFile, Other])
end;
-new(#config{opts=Opts0}=ParentConfig)->
- %% If we are at the top level we might want to load another rebar.config
- %% We can be certain that we are at the top level if we don't have any
- %% configs yet since if we are at another level we must have some config.
- ConfName = case ParentConfig of
- {config, _, []} ->
- rebar_config:get_global(config, "rebar.config");
- _ ->
- "rebar.config"
- end,
+new(_ParentConfig=#config{opts=Opts0})->
+ new(Opts0, "rebar.config").
+new(Opts0, ConfName) ->
%% Load terms from rebar.config, if it exists
Dir = rebar_utils:get_cwd(),
ConfigFile = filename:join([Dir, ConfName]),
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 790edc9..75569b4 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -85,7 +85,8 @@ process_commands([Command | Rest], ParentConfig) ->
case erlang:get(operations) of
Operations ->
%% This command didn't do anything
- ?CONSOLE("Command '~p' not understood\n", [Command]);
+ ?CONSOLE("Command '~p' not understood or not applicable~n",
+ [Command]);
_ ->
ok
end,
@@ -361,7 +362,7 @@ acc_modules([Module | Rest], Command, Config, File, Acc) ->
%% Return a flat list of rebar plugin modules.
%%
plugin_modules(Config) ->
- Modules = lists:flatten(rebar_config:get_all(Config, rebar_plugins)),
+ Modules = lists:flatten(rebar_config:get_all(Config, plugins)),
plugin_modules(Config, ulist(Modules)).
ulist(L) ->
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index 96f1978..040e739 100644
--- a/src/rebar_eunit.erl
+++ b/src/rebar_eunit.erl
@@ -309,17 +309,17 @@ cover_init(true, BeamFiles) ->
%% to stdout. If the cover server is already started we'll reuse that
%% pid.
{ok, CoverPid} = case cover:start() of
- {ok, P} ->
- {ok, P};
+ {ok, _P} = OkStart ->
+ OkStart;
{error,{already_started, P}} ->
{ok, P};
- {error, Reason} ->
- {error, Reason}
+ {error, _Reason} = ErrorStart ->
+ ErrorStart
end,
- {ok, F} = file:open(
- filename:join([?EUNIT_DIR, "cover.log"]),
- [write]),
+ {ok, F} = OkOpen = file:open(
+ filename:join([?EUNIT_DIR, "cover.log"]),
+ [write]),
group_leader(F, CoverPid),
@@ -345,7 +345,7 @@ cover_init(true, BeamFiles) ->
[Beam, Desc])
end,
_ = [PrintWarning(Beam, Desc) || {Beam, {error, Desc}} <- Compiled],
- {ok, F}
+ OkOpen
end;
cover_init(Config, BeamFiles) ->
cover_init(rebar_config:get(Config, cover_enabled, false), BeamFiles).
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index c2430e7..74be18c 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -247,8 +247,9 @@ apply_defaults(Vars, Defaults) ->
dict:merge(fun(Key, VarValue, DefaultValue) ->
case is_expandable(DefaultValue) of
true ->
- expand_env_variable(DefaultValue,
- Key, VarValue);
+ rebar_utils:expand_env_variable(DefaultValue,
+ Key,
+ VarValue);
false -> VarValue
end
end,
@@ -267,10 +268,10 @@ merge_each_var([{Key, Value} | Rest], Vars) ->
error ->
%% Nothing yet defined for this key/value.
%% Expand any self-references as blank.
- expand_env_variable(Value, Key, "");
+ rebar_utils:expand_env_variable(Value, Key, "");
{ok, Value0} ->
%% Use previous definition in expansion
- expand_env_variable(Value, Key, Value0)
+ rebar_utils:expand_env_variable(Value, Key, Value0)
end,
merge_each_var(Rest, orddict:store(Key, Evalue, Vars)).
@@ -305,7 +306,8 @@ expand_vars(Key, Value, Vars) ->
Key ->
AValue;
_ ->
- expand_env_variable(AValue, Key, Value)
+ rebar_utils:expand_env_variable(AValue,
+ Key, Value)
end,
[{AKey, NewValue} | Acc]
end,
@@ -313,8 +315,8 @@ expand_vars(Key, Value, Vars) ->
expand_command(TmplName, Env, InFiles, OutFile) ->
Cmd0 = proplists:get_value(TmplName, Env),
- Cmd1 = expand_env_variable(Cmd0, "PORT_IN_FILES", InFiles),
- Cmd2 = expand_env_variable(Cmd1, "PORT_OUT_FILE", OutFile),
+ Cmd1 = rebar_utils:expand_env_variable(Cmd0, "PORT_IN_FILES", InFiles),
+ Cmd2 = rebar_utils:expand_env_variable(Cmd1, "PORT_OUT_FILE", OutFile),
re:replace(Cmd2, "\\\$\\w+|\\\${\\w+}", "", [global, {return, list}]).
%%
@@ -327,18 +329,6 @@ is_expandable(InStr) ->
end.
%%
-%% Given env. variable FOO we want to expand all references to
-%% it in InStr. References can have two forms: $FOO and ${FOO}
-%% The end of form $FOO is delimited with whitespace or eol
-%%
-expand_env_variable(InStr, VarName, VarValue) ->
- R1 = re:replace(InStr, "\\\$" ++ VarName ++ "\\s", VarValue ++ " ",
- [global]),
- R2 = re:replace(R1, "\\\$" ++ VarName ++ "\$", VarValue),
- re:replace(R2, "\\\${" ++ VarName ++ "}", VarValue,
- [global, {return, list}]).
-
-%%
%% Filter a list of env vars such that only those which match the provided
%% architecture regex (or do not have a regex) are returned.
%%
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 4571d17..ca254eb 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -41,7 +41,8 @@
find_executable/1,
prop_check/3,
expand_code_path/0,
- deprecated/5]).
+ deprecated/5,
+ expand_env_variable/3]).
-include("rebar.hrl").
@@ -85,7 +86,8 @@ wordsize() ->
%% Val = string() | false
%%
sh(Command0, Options0) ->
- ?INFO("sh info:\n\tcwd: ~p\n\tcmd: ~s\n\topts: ~p\n", [get_cwd(), Command0, Options0]),
+ ?INFO("sh info:\n\tcwd: ~p\n\tcmd: ~s\n\topts: ~p\n",
+ [get_cwd(), Command0, Options0]),
DefaultOptions = [use_stdout, abort_on_error],
Options = [expand_sh_flag(V)
@@ -94,7 +96,7 @@ sh(Command0, Options0) ->
ErrorHandler = proplists:get_value(error_handler, Options),
OutputHandler = proplists:get_value(output_handler, Options),
- Command = patch_on_windows(Command0),
+ Command = patch_on_windows(Command0, proplists:get_value(env, Options, [])),
PortSettings = proplists:get_all_values(port_settings, Options) ++
[exit_status, {line, 16384}, use_stdio, stderr_to_stdout, hide],
Port = open_port({spawn, Command}, PortSettings),
@@ -106,9 +108,11 @@ sh(Command0, Options0) ->
ErrorHandler(Command, Err)
end.
-%% We need a bash shell to execute on windows
-%% also the port doesn't seem to close from time to time (mingw)
-patch_on_windows(Cmd) ->
+%% We use a bash shell to execute on windows if available. Otherwise we do the
+%% shell variable substitution ourselves and hope that the command doesn't use
+%% any shell magic. Also the port doesn't seem to close from time to time
+%% (mingw).
+patch_on_windows(Cmd, Env) ->
case os:type() of
{win32,nt} ->
case find_executable("bash") of
@@ -117,7 +121,9 @@ patch_on_windows(Cmd) ->
Bash ++ " -c \"" ++ Cmd ++ "; echo _port_cmd_status_ $?\" "
end;
_ ->
- Cmd
+ lists:foldl(fun({Key, Value}, Acc) ->
+ expand_env_variable(Acc, Key, Value)
+ end, Cmd, Env)
end.
find_files(Dir, Regex) ->
@@ -175,6 +181,19 @@ expand_code_path() ->
end, [], code:get_path()),
code:set_path(lists:reverse(CodePath)).
+%%
+%% Given env. variable FOO we want to expand all references to
+%% it in InStr. References can have two forms: $FOO and ${FOO}
+%% The end of form $FOO is delimited with whitespace or eol
+%%
+expand_env_variable(InStr, VarName, RawVarValue) ->
+ ReOpts = [global, {return, list}],
+ VarValue = re:replace(RawVarValue, "\\\\", "\\\\\\\\", ReOpts),
+ R1 = re:replace(InStr, "\\\$" ++ VarName ++ "\\s", VarValue ++ " ",
+ [global]),
+ R2 = re:replace(R1, "\\\$" ++ VarName ++ "\$", VarValue),
+ re:replace(R2, "\\\${" ++ VarName ++ "}", VarValue, ReOpts).
+
%% ====================================================================
%% Internal functions