PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/mix/lib/mix/tasks/compile.leex.ex

https://github.com/vanstee/elixir
Elixir | 62 lines | 50 code | 10 blank | 2 comment | 1 complexity | e0345fb60e5e89e3e007b54cf145e5e4 MD5 | raw file
Possible License(s): Apache-2.0
  1. defmodule Mix.Tasks.Compile.Leex do
  2. alias Mix.Tasks.Compile.Erlang
  3. use Mix.Task
  4. @hidden true
  5. @shortdoc "Compile Leex source files"
  6. @recursive true
  7. @manifest ".compile.leex"
  8. @moduledoc """
  9. A task to compile Leex source files.
  10. When this task runs, it will check the modification time of every file, and
  11. if it has changed, the file will be compiled. Files will be
  12. compiled in the same source directory with a .erl extension.
  13. You can force compilation regardless of modification times by passing
  14. the `--force` option.
  15. ## Command line options
  16. * `--force` - forces compilation regardless of modification times;
  17. ## Configuration
  18. * `:erlc_paths` - directories to find source files.
  19. Defaults to `["src"]`, can be configured as:
  20. ```
  21. [erlc_paths: ["src", "other"]]
  22. ```
  23. * `:leex_options` - compilation options that apply
  24. to Leex's compiler. There are many available options
  25. here: http://www.erlang.org/doc/man/leex.html#file-2
  26. """
  27. @doc """
  28. Runs this task.
  29. """
  30. def run(args) do
  31. { opts, _, _ } = OptionParser.parse(args, switches: [force: :boolean])
  32. project = Mix.project
  33. source_paths = project[:erlc_paths]
  34. mappings = Enum.zip(source_paths, source_paths)
  35. options = project[:leex_options] || []
  36. Erlang.compile_mappings(manifest(), mappings, :xrl, :erl, opts[:force], fn
  37. input, output ->
  38. options = options ++ [scannerfile: Erlang.to_erl_file(output), report: true]
  39. :leex.file(Erlang.to_erl_file(input), options)
  40. end)
  41. end
  42. @doc """
  43. Returns Leex manifests.
  44. """
  45. def manifests, do: [manifest]
  46. defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest)
  47. end