Pass the args as a list to the compiler
Instead of converting into a string and hoping the shell doesn't choke.
This commit is contained in:
28
mix.exs
28
mix.exs
@@ -6,8 +6,8 @@ defmodule Mix.Tasks.Compile.Nif do
|
|||||||
|
|
||||||
file = Keyword.fetch!(config, :file)
|
file = Keyword.fetch!(config, :file)
|
||||||
paths = Keyword.fetch!(config, :paths)
|
paths = Keyword.fetch!(config, :paths)
|
||||||
flags = Keyword.fetch!(config, :flags)
|
flags = Keyword.get(config, :flags, [])
|
||||||
exts = Keyword.fetch!(config, :exts)
|
exts = Keyword.get(config, :exts, [:c, :cpp])
|
||||||
compiler =
|
compiler =
|
||||||
Keyword.get(config, :compilers, ["cc", "gcc", "clang"])
|
Keyword.get(config, :compilers, ["cc", "gcc", "clang"])
|
||||||
|> find_compiler
|
|> find_compiler
|
||||||
@@ -23,12 +23,14 @@ defmodule Mix.Tasks.Compile.Nif do
|
|||||||
[] ->
|
[] ->
|
||||||
:noop
|
:noop
|
||||||
_ ->
|
_ ->
|
||||||
cmd =
|
Mix.shell.info("* Compiling #{file}")
|
||||||
[compiler, "-shared", "-fpic", "-o #{file}", to_compile, flags]
|
args = ["-shared", "-fpic", "-o", file, to_compile, flags] |> List.flatten
|
||||||
|> List.flatten
|
port = Port.open({:spawn_executable, compiler},
|
||||||
|> Enum.join(" ")
|
[:stream, :binary, :use_stdio, :stderr_to_stdout, :hide,
|
||||||
|
:exit_status, {:args, args}])
|
||||||
IO.puts System.cmd(cmd)
|
if do_cmd(port) != 0 do
|
||||||
|
raise Mix.Error, message: "Error compiling #{file}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,6 +43,16 @@ defmodule Mix.Tasks.Compile.Nif do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp do_cmd(port) do
|
||||||
|
receive do
|
||||||
|
{^port, {:data, data}} ->
|
||||||
|
IO.write(data)
|
||||||
|
do_cmd(port)
|
||||||
|
{^port, {:exit_status, status}} ->
|
||||||
|
status
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Geef.Mixfile do
|
defmodule Geef.Mixfile do
|
||||||
|
|||||||
Reference in New Issue
Block a user