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:
Carlos Martín Nieto
2013-07-24 23:41:22 +02:00
parent 08ca3b33c2
commit bed2e19ede

28
mix.exs
View File

@@ -6,8 +6,8 @@ defmodule Mix.Tasks.Compile.Nif do
file = Keyword.fetch!(config, :file)
paths = Keyword.fetch!(config, :paths)
flags = Keyword.fetch!(config, :flags)
exts = Keyword.fetch!(config, :exts)
flags = Keyword.get(config, :flags, [])
exts = Keyword.get(config, :exts, [:c, :cpp])
compiler =
Keyword.get(config, :compilers, ["cc", "gcc", "clang"])
|> find_compiler
@@ -23,12 +23,14 @@ defmodule Mix.Tasks.Compile.Nif do
[] ->
:noop
_ ->
cmd =
[compiler, "-shared", "-fpic", "-o #{file}", to_compile, flags]
|> List.flatten
|> Enum.join(" ")
IO.puts System.cmd(cmd)
Mix.shell.info("* Compiling #{file}")
args = ["-shared", "-fpic", "-o", file, to_compile, flags] |> List.flatten
port = Port.open({:spawn_executable, compiler},
[:stream, :binary, :use_stdio, :stderr_to_stdout, :hide,
:exit_status, {:args, args}])
if do_cmd(port) != 0 do
raise Mix.Error, message: "Error compiling #{file}"
end
end
end
@@ -41,6 +43,16 @@ defmodule Mix.Tasks.Compile.Nif do
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
defmodule Geef.Mixfile do