   end
 
   defp module_from_artifact(artifact) do
-    artifact |> Path.basename |> Path.rootname |> String.to_atom
+    artifact |> Path.basename() |> Path.rootname() |> String.to_atom()
   end
 end

  end

  defp do_run([], _, _, _), do: :noop
  defp do_run(files, opts, project, source_paths) do
    include_path = to_erl_file project[:erlc_include_path]
    compile_path = to_erl_file Mix.Project.compile_path(project)

    erlc_options = project[:erlc_options] || []
    unless is_list(erlc_options) do
      Mix.raise ":erlc_options should be a list of options, got: #{inspect(erlc_options)}"
    end
    erlc_options = erlc_options ++ [:return, :report, outdir: compile_path, i: include_path]
    erlc_options = Enum.map erlc_options, fn
      {kind, dir} when kind in [:i, :outdir] ->
        {kind, to_erl_file(dir)}
      opt ->
        opt
    end

    compile_path = Path.relative_to(compile_path, File.cwd!)

    tuples = files
             |> scan_sources(include_path, source_paths)
             |> sort_dependencies
             |> Enum.map(&annotate_target(&1, compile_path, opts[:force]))

    Mix.Compilers.Erlang.compile(manifest(), tuples, opts, fn
      input, _output ->
        # We're purging the module because a previous compiler (e.g. Phoenix)
        # might have already loaded the previous version of it.
        module = Path.basename(input, ".erl") |> String.to_atom
        :code.purge(module)
        :code.delete(module)

        file = to_erl_file(Path.rootname(input, ".erl"))
        case :compile.file(file, erlc_options) do
          {:error, :badarg} ->
            Mix.raise "Compiling Erlang #{inspect file} failed with ArgumentError, probably because of invalid :erlc_options"
          result ->
            result
        end
    end)
  end



  defp scan_sources(files, include_path, source_paths) do
    include_paths = [include_path | source_paths]
    Enum.reduce(files, [], &scan_source(&2, &1, include_paths)) |> Enum.reverse()
  end

  defp scan_source(acc, file, include_paths) do
    erl_file = %{
      file: file,
      module: module_from_artifact(file),
      behaviours: [],
      compile: [],
      includes: [],
      invalid: false
    }

    case :epp.parse_file(to_erl_file(file), include_paths, []) do
      {:ok, forms} ->
        [List.foldl(tl(forms), erl_file, &do_form(file, &1, &2)) | acc]

      {:error, _error} ->
        acc
    end
