summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--THANKS1
-rwxr-xr-xbootstrap37
-rw-r--r--inttest/t_custom_config/custom.config1
-rw-r--r--inttest/t_custom_config/custom_config.erl6
-rw-r--r--inttest/t_custom_config/t_custom_config_rt.erl31
-rw-r--r--rebar.config.sample4
-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
12 files changed, 121 insertions, 65 deletions
diff --git a/THANKS b/THANKS
index 4e38e79..eebe41f 100644
--- a/THANKS
+++ b/THANKS
@@ -64,3 +64,4 @@ Tino Breddin
David Nonnenmacher
Anders Nygren
Scott Lystig Fritchie
+Uwe Dauernheim
diff --git a/bootstrap b/bootstrap
index 15fe60a..024fa6d 100755
--- a/bootstrap
+++ b/bootstrap
@@ -25,10 +25,11 @@ main(Args) ->
end,
%% Compile all src/*.erl to ebin
- case make:files(filelib:wildcard("src/*.erl"), [{outdir, "ebin"}, {i, "include"},
- DebugFlag,
- {d, 'BUILD_TIME', Built},
- {d, 'VCS_INFO', VcsInfo}]) of
+ case make:files(filelib:wildcard("src/*.erl"),
+ [{outdir, "ebin"}, {i, "include"},
+ DebugFlag,
+ {d, 'BUILD_TIME', Built},
+ {d, 'VCS_INFO', VcsInfo}]) of
up_to_date ->
ok;
error ->
@@ -51,25 +52,30 @@ main(Args) ->
%% Run rebar to do proper .app validation and such
rebar:main(["compile"] ++ Args),
- %% Read the contents of the files in ebin and templates; note that we place
- %% all the beam files at the top level of the code archive so that code loading
- %% works properly.
+ %% Read the contents of the files in ebin and templates; note that we
+ %% place all the beam files at the top level of the code archive so
+ %% that code loading works properly.
Files = load_files("*", "ebin") ++ load_files("priv/templates/*", "."),
case zip:create("mem", Files, [memory]) of
{ok, {"mem", ZipBin}} ->
%% Archive was successfully created. Prefix that binary with our
- %% header and write to "rebar" file
- Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n", ZipBin/binary>>,
+ %% header and write to "rebar" file.
+ %% Without -noshell -noinput escript consumes all input that would
+ %% otherwise go to the shell for the next command.
+ Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n",
+ ZipBin/binary>>,
case file:write_file("rebar", Script) of
ok ->
ok;
{error, WriteError} ->
- io:format("Failed to write rebar script: ~p\n", [WriteError]),
+ io:format("Failed to write rebar script: ~p\n",
+ [WriteError]),
halt(1)
end;
{error, ZipError} ->
- io:format("Failed to construct rebar script archive: ~p\n", [ZipError]),
+ io:format("Failed to construct rebar script archive: ~p\n",
+ [ZipError]),
halt(1)
end,
@@ -83,8 +89,10 @@ main(Args) ->
end,
%% Add a helpful message
- io:format("Congratulations! You now have a self-contained script called \"rebar\" in\n"
- "your current working directory. Place this script anywhere in your path\n"
+ io:format("Congratulations! You now have a self-contained script called"
+ " \"rebar\" in\n"
+ "your current working directory. "
+ "Place this script anywhere in your path\n"
"and you can use rebar to build OTP-compliant apps.\n").
rm(Path) ->
@@ -98,7 +106,8 @@ rm(Path) ->
build_time() ->
{{Y, M, D}, {H, Min, S}} = calendar:now_to_universal_time(now()),
- lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w", [Y, M, D, H, Min, S])).
+ lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
+ [Y, M, D, H, Min, S])).
load_files(Wildcard, Dir) ->
diff --git a/inttest/t_custom_config/custom.config b/inttest/t_custom_config/custom.config
new file mode 100644
index 0000000..6e6cd92
--- /dev/null
+++ b/inttest/t_custom_config/custom.config
@@ -0,0 +1 @@
+{erl_opts, [warnings_as_errors]}.
diff --git a/inttest/t_custom_config/custom_config.erl b/inttest/t_custom_config/custom_config.erl
new file mode 100644
index 0000000..8656201
--- /dev/null
+++ b/inttest/t_custom_config/custom_config.erl
@@ -0,0 +1,6 @@
+-module(custom_config).
+
+-compile(export_all).
+
+test() ->
+ ok.
diff --git a/inttest/t_custom_config/t_custom_config_rt.erl b/inttest/t_custom_config/t_custom_config_rt.erl
new file mode 100644
index 0000000..8a4e2ab
--- /dev/null
+++ b/inttest/t_custom_config/t_custom_config_rt.erl
@@ -0,0 +1,31 @@
+-module(t_custom_config_rt).
+
+-compile(export_all).
+
+-include_lib("eunit/include/eunit.hrl").
+
+files() ->
+ [{copy, "custom.config", "custom.config"},
+ {create, "ebin/custom_config.app", app(custom_config, [custom_config])}].
+
+run(Dir) ->
+ retest_log:log(debug, "Running in Dir: ~s~n", [Dir]),
+ Ref = retest:sh("rebar -C custom.config check-deps -v", [{async, true}]),
+ {ok, Captured} =
+ retest:sh_expect(Ref,
+ "DEBUG: Consult config file .*/custom.config.*",
+ [{capture, all, list}]),
+ retest_log:log(debug, "[CAPTURED]: ~s~n", [Captured]),
+ ok.
+
+%%
+%% Generate the contents of a simple .app file
+%%
+app(Name, Modules) ->
+ App = {application, Name,
+ [{description, atom_to_list(Name)},
+ {vsn, "1"},
+ {modules, Modules},
+ {registered, []},
+ {applications, [kernel, stdlib]}]},
+ io_lib:format("~p.\n", [App]).
diff --git a/rebar.config.sample b/rebar.config.sample
index 0a7fb11..2053b8b 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -106,10 +106,10 @@
%% == Dependencies ==
-%% Where to put any downloaded depandencies. Default is `deps'
+%% Where to put any downloaded dependencies. Default is `deps'
{deps_dir, ["deps"]}.
-%% What dependancies we have, depandencies can be of 3 forms, an application
+%% What dependencies we have, dependencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
%% an application name, a version and the SCM details on how to fetch it (SCM
%% type, location and revision). Rebar currently supports git, hg, bzr and svn.
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