mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Basic tweaks for compiling ports/nifs on mingw
This commit is contained in:
parent
0f486c8cc1
commit
83cece0f80
2 changed files with 41 additions and 3 deletions
|
@ -307,7 +307,8 @@ erts_dir() ->
|
||||||
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
|
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
|
||||||
|
|
||||||
os_env() ->
|
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() ->
|
default_env() ->
|
||||||
[
|
[
|
||||||
|
@ -344,6 +345,24 @@ source_to_bin(Source) ->
|
||||||
filename:rootname(Source, Ext) ++ ".o".
|
filename:rootname(Source, Ext) ++ ".o".
|
||||||
|
|
||||||
so_specs(Config, AppFile, Bins) ->
|
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
|
case rebar_config:get(Config, so_specs, undefined) of
|
||||||
undefined ->
|
undefined ->
|
||||||
%% New form of so_specs is not provided. See if the old form of {so_name} is available
|
%% New form of so_specs is not provided. See if the old form of {so_name} is available
|
||||||
|
|
|
@ -77,8 +77,9 @@ get_os() ->
|
||||||
sh(Command, Env) ->
|
sh(Command, Env) ->
|
||||||
sh(Command, Env, get_cwd()).
|
sh(Command, Env, get_cwd()).
|
||||||
|
|
||||||
sh(Command, Env, Dir) ->
|
sh(Command0, Env, Dir) ->
|
||||||
?INFO("sh: ~s\n~p\n", [Command, Env]),
|
?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},
|
Port = open_port({spawn, Command}, [{cd, Dir}, {env, Env}, exit_status, {line, 16384},
|
||||||
use_stdio, stderr_to_stdout]),
|
use_stdio, stderr_to_stdout]),
|
||||||
case sh_loop(Port) of
|
case sh_loop(Port) of
|
||||||
|
@ -88,6 +89,18 @@ sh(Command, Env, Dir) ->
|
||||||
?ABORT("~s failed with error: ~w\n", [Command, Rc])
|
?ABORT("~s failed with error: ~w\n", [Command, Rc])
|
||||||
end.
|
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_failfast(Command, Env) ->
|
||||||
sh(Command, Env).
|
sh(Command, Env).
|
||||||
|
|
||||||
|
@ -145,6 +158,12 @@ match_first([{Regex, MatchValue} | Rest], Val) ->
|
||||||
|
|
||||||
sh_loop(Port) ->
|
sh_loop(Port) ->
|
||||||
receive
|
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}}} ->
|
{Port, {data, {_, Line}}} ->
|
||||||
?CONSOLE("~s\n", [Line]),
|
?CONSOLE("~s\n", [Line]),
|
||||||
sh_loop(Port);
|
sh_loop(Port);
|
||||||
|
|
Loading…
Reference in a new issue