summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_port_compiler.erl21
-rw-r--r--src/rebar_utils.erl23
2 files changed, 41 insertions, 3 deletions
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index de3950e..d07b369 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -307,7 +307,8 @@ erts_dir() ->
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
os_env() ->
- [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) || S <- os:getenv()].
+ Os = [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) || S <- os:getenv()],
+ lists:keydelete([],1,Os). %% Remove Windows current disk and path
default_env() ->
[
@@ -344,6 +345,24 @@ source_to_bin(Source) ->
filename:rootname(Source, Ext) ++ ".o".
so_specs(Config, AppFile, Bins) ->
+ Specs = make_so_specs(Config, AppFile, Bins),
+ case os:type() of
+ {win32, nt} ->
+ [switch_so_to_dll(SoSpec) || SoSpec <- Specs];
+ _ ->
+ Specs
+ end.
+
+switch_so_to_dll(Orig = {Name, Spec}) ->
+ case filename:extension(Name) of
+ ".so" ->
+ {filename:rootname(Name, ".so") ++ ".dll", Spec};
+ _ ->
+ %% Not a .so; leave it
+ Orig
+ end.
+
+make_so_specs(Config, AppFile, Bins) ->
case rebar_config:get(Config, so_specs, undefined) of
undefined ->
%% New form of so_specs is not provided. See if the old form of {so_name} is available
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 95981a3..056618b 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -77,8 +77,9 @@ get_os() ->
sh(Command, Env) ->
sh(Command, Env, get_cwd()).
-sh(Command, Env, Dir) ->
- ?INFO("sh: ~s\n~p\n", [Command, Env]),
+sh(Command0, Env, Dir) ->
+ ?INFO("sh: ~s\n~p\n", [Command0, Env]),
+ Command = patch_on_windows(Command0, os:type()),
Port = open_port({spawn, Command}, [{cd, Dir}, {env, Env}, exit_status, {line, 16384},
use_stdio, stderr_to_stdout]),
case sh_loop(Port) of
@@ -88,6 +89,18 @@ sh(Command, Env, Dir) ->
?ABORT("~s failed with error: ~w\n", [Command, Rc])
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, {win32,nt}) ->
+ case os:find_executable(bash) of
+ false -> Cmd;
+ Bash ->
+ Bash ++ " -c \"" ++ Cmd ++ "; echo _port_cmd_status_ $?\" "
+ end;
+patch_on_windows(Command, _) ->
+ Command.
+
sh_failfast(Command, Env) ->
sh(Command, Env).
@@ -145,6 +158,12 @@ match_first([{Regex, MatchValue} | Rest], Val) ->
sh_loop(Port) ->
receive
+ {Port, {data, {_, "_port_cmd_status_ " ++ Status}}} ->
+ (catch erlang:port_close(Port)), % sigh () for indentation
+ case list_to_integer(Status) of
+ 0 -> ok;
+ Rc -> {error, Rc}
+ end;
{Port, {data, {_, Line}}} ->
?CONSOLE("~s\n", [Line]),
sh_loop(Port);