summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Smith <dizzyd@dizzyd.com>2009-12-01 10:38:20 -0700
committerDave Smith <dizzyd@dizzyd.com>2009-12-01 10:38:20 -0700
commitdbd576fc331950eaa449bce16c0b52190d763e01 (patch)
treebe53cea8fbca3533dd8870d862cf6b3d49e01ca7 /src
parentcf6738928d74dec321349f5fad59959d5131fdd9 (diff)
Adding more flexible arch check; adding sh command
Diffstat (limited to 'src')
-rw-r--r--src/rebar_utils.erl42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index d3717cc..cda6f60 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -25,8 +25,12 @@
-module(rebar_utils).
-export([get_cwd/0,
- get_os/0]).
+ is_arch/1,
+ get_os/0,
+ sh/2,
+ sh_failfast/2]).
+-include("rebar.hrl").
%% ====================================================================
%% Public API
@@ -37,6 +41,15 @@ get_cwd() ->
Dir.
+is_arch(ArchRegex) ->
+ Arch = erlang:system_info(system_architecture),
+ case re:run(Arch, ArchRegex, [{capture, none}]) of
+ match ->
+ true;
+ nomatch ->
+ false
+ end.
+
get_os() ->
Arch = erlang:system_info(system_architecture),
case match_first([{"linux", linux}, {"darwin", darwin}], Arch) of
@@ -47,6 +60,22 @@ get_os() ->
end.
+sh(Command, Env) ->
+ ?INFO("sh: ~s\n~p\n", [Command, Env]),
+ Port = open_port({spawn, Command}, [{env, Env}, exit_status, {line, 16384},
+ use_stdio, stderr_to_stdout]),
+ sh_loop(Port).
+
+sh_failfast(Command, Env) ->
+ case sh(Command, Env) of
+ ok ->
+ ok;
+ {error, Rc} ->
+ ?ERROR("~s failed with error: ~w\n", [Command, Rc]),
+ ?FAIL
+ end.
+
+
%% ====================================================================
%% Internal functions
%% ====================================================================
@@ -60,3 +89,14 @@ match_first([{Regex, MatchValue} | Rest], Val) ->
nomatch ->
match_first(Rest, Val)
end.
+
+sh_loop(Port) ->
+ receive
+ {Port, {data, {_, Line}}} ->
+ ?INFO("> ~s\n", [Line]),
+ sh_loop(Port);
+ {Port, {exit_status, 0}} ->
+ ok;
+ {Port, {exit_status, Rc}} ->
+ {error, Rc}
+ end.