Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions lib/elixir/lib/kernel/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -339,21 +339,46 @@ defmodule Kernel.CLI do
defp process_command({:compile, patterns}, config) do
:filelib.ensure_dir(:filename.join(config.output, "."))

files = Enum.map patterns, &Path.wildcard(&1)
files = Enum.uniq(Enum.concat(files))
files = Enum.filter files, &:filelib.is_regular(&1)

if files != [] do
wrapper fn ->
Code.compiler_options(config.compiler_options)
Kernel.ParallelCompiler.files_to_path(files, config.output,
each_file: fn file -> if config.verbose_compile do IO.puts "Compiled #{file}" end end)
end
else
{ :error, "--compile : No files matched patterns #{Enum.join(patterns, ",")}" }
case match_regular_files(patterns) do
{ :ok, [] } ->
{ :error, "--compile : No files matched provided patterns." }
{ :ok, files } ->
wrapper fn ->
Code.compiler_options(config.compiler_options)
Kernel.ParallelCompiler.files_to_path(files, config.output,
each_file: fn file -> if config.verbose_compile do IO.puts "Compiled #{file}" end end)
end
{ :missing, missing } ->
{ :error, "--compile : No files matched pattern(s) #{Enum.join(missing, ",")}" }
end
end

defp match_regular_files(patterns) do

matched_files = Enum.map patterns, fn(pattern) ->
case Path.wildcard(pattern) do
[] -> {:missing, pattern }
files -> {:ok, files }
end
end

files = Enum.filter_map matched_files,
fn(match) -> elem(match, 0) == :ok end,
&elem(&1, 1)

missing_patterns = Enum.filter_map matched_files,
fn(match) -> elem(match, 0) == :missing end,
&elem(&1, 1)

if missing_patterns == [] do
files = Enum.uniq(Enum.concat(files))
files = Enum.filter files, &:filelib.is_regular(&1)
{ :ok, files }
else
{ :missing, Enum.uniq(missing_patterns) }
end
end

defp wrapper(fun) do
fun.()
:ok
Expand Down
8 changes: 8 additions & 0 deletions lib/elixir/test/elixir/kernel/cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ defmodule Kernel.CLI.CompileTest do
assert :string.str(output, bar) > 0, "expected bar.ex to miss module Foo"
assert :string.str(output, 'elixir_compiler') == 0, "expected elixir_compiler to not be in output"
end

test :compile_missing_patterns do
fixture = fixture_path "compile_sample.ex"
output = elixirc('#{fixture} non_existing.ex -o #{tmp_path}')
assert :string.str(output, 'non_existing.ex') > 0, "expected non_existing.ex to be mentionned"
assert :string.str(output, 'compile_sample.ex') == 0, "expected compile_sample.ex to not be mentionned"
refute File.exists?(tmp_path("Elixir.CompileSample.beam")) , "expected the sample to not be compiled"
end
end

defmodule Kernel.CLI.ParallelCompilerTest do
Expand Down