PageRenderTime 50ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/mix/lib/mix/tasks/compile.yecc.ex

https://github.com/vanstee/elixir
Elixir | 62 lines | 50 code | 10 blank | 2 comment | 1 complexity | 44ce4eb46d96aefcd5f824c9947ec955 MD5 | raw file
Possible License(s): Apache-2.0
  1. defmodule Mix.Tasks.Compile.Yecc do
  2. alias Mix.Tasks.Compile.Erlang
  3. use Mix.Task
  4. @hidden true
  5. @shortdoc "Compile Yecc source files"
  6. @recursive true
  7. @manifest ".compile.yecc"
  8. @moduledoc """
  9. A task to compile Yecc 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. * `:yecc_options` - compilation options that apply
  24. to Yecc's compiler. There are many other available
  25. options here: http://www.erlang.org/doc/man/yecc.html#file-1
  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[:yecc_options] || []
  36. Erlang.compile_mappings(manifest(), mappings, :yrl, :erl, opts[:force], fn
  37. input, output ->
  38. options = options ++ [parserfile: Erlang.to_erl_file(output), report: true]
  39. :yecc.file(Erlang.to_erl_file(input), options)
  40. end)
  41. end
  42. @doc """
  43. Returns Yecc manifests.
  44. """
  45. def manifests, do: [manifest]
  46. defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest)
  47. end