Skip to content

Commit

Permalink
Update to Elixir master
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jul 10, 2013
1 parent cad008f commit fb99b0b
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions lib/mix/tasks/compile.dynamo.ex
Expand Up @@ -28,9 +28,13 @@ defmodule Mix.Tasks.Compile.Dynamo do
* `--force` - forces compilation regardless of mod times;
"""

@switches [force: :boolean, quick: :boolean, docs: :boolean,
ignore_module_conflict: :boolean, debug_info: :boolean,
warnings_as_errors: :boolean]

def run(args) do
{ opts, _ } = OptionParser.parse(args,
switches: [force: :boolean, quick: :boolean], aliases: [q: :quick])
{ opts, _ } = OptionParser.parse(args, aliases: [q: :quick], switches: @switches)

Enum.reduce Mix.project[:dynamos], :noop, fn(dynamo, acc) ->
if dynamo.config[:dynamo][:compile_on_demand] do
Expand Down Expand Up @@ -59,34 +63,37 @@ defmodule Mix.Tasks.Compile.Dynamo do
to_watch = to_watch ++ Enum.map(templates, template_mtime(&1))

manifest = Path.join(compile_path, @manifest)
stale = Mix.Utils.extract_stale(to_watch, [manifest])

if opts[:force] or stale != [] do
if elixir_opts = project[:elixirc_options] do
Code.compiler_options(elixir_opts)
end
if opts[:force] or Mix.Utils.stale?(to_watch, [manifest]) do
set_compiler_opts(project, opts)

to_compile = Mix.Utils.extract_files(source_paths, compile_exts)
File.mkdir_p!(compile_path)
Code.delete_path compile_path
Code.prepend_path compile_path

previous = Mix.Utils.read_manifest(manifest)
Enum.each previous, fn entry ->
Path.join(compile_path, entry <> ".beam") |> File.rm
end

{ _current, to_remove } =
Mix.Utils.manifest manifest, fn ->
compiled = compile_files to_compile, compile_path, root
lc { mod, _ } inlist compiled, do: atom_to_binary(mod)
end
compiled = compile_files to_compile, compile_path, root
compiled = lc { mod, _ } inlist compiled, do: atom_to_binary(mod)

Mix.Utils.update_manifest(manifest, compiled)
compile_templates mod, dynamo[:compiled_templates], templates, compile_path

lc f inlist to_remove, do: File.rm(Path.join(compile_path, f) <> ".beam")
Code.prepend_path compile_path

:ok
else
acc
end
end

defp set_compiler_opts(project, opts) do
opts = Dict.take(opts, [:docs, :debug_info, :ignore_module_conflict, :warnings_as_errors])
opts = Keyword.merge(project[:elixirc_options] || [], opts)
Code.compiler_options(opts)
end

defp extract_templates(paths) do
lc path inlist paths,
not Dynamo.Templates.Finder.requires_precompilation?(path),
Expand Down

0 comments on commit fb99b0b

Please sign in to comment.