-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9dc79d
commit ea21b23
Showing
6 changed files
with
135 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Mix.Compilers.Lfe do | ||
alias Mix.Compilers.Erlang, as: ErlangCompiler | ||
|
||
@moduledoc false | ||
|
||
@doc """ | ||
Compiles the files in `mappings` with '.lfe' extensions into | ||
the destinations. | ||
Does this for each stale input and output pair (or for all if `force` is `true`) and | ||
removes files that no longer have a source, while keeping the `manifest` up to date. | ||
`mappings` should be a list of tuples in the form of `{src, dest}` paths. | ||
Uses an [idea](https://github.com/elixir-lang/elixir/blob/e1c903a5956e4cb9075f0aac00638145788b0da4/lib/mix/lib/mix/compilers/erlang.ex#L20) from the Erlang Mix compiler to do so. | ||
It supports the options of the Erlang Mix compiler under the covers as it is used. | ||
""" | ||
def compile(manifest, [{_, _} | _] = mappings, opts) do | ||
callback = fn input, output -> | ||
module = input |> Path.basename(".lfe") |> String.to_atom() | ||
:code.purge(module) | ||
:code.delete(module) | ||
|
||
outdir = output |> Path.dirname() |> ErlangCompiler.to_erl_file() | ||
|
||
compile_result(:lfe_comp.file(ErlangCompiler.to_erl_file(input), [{:outdir, outdir}, :return, :report])) | ||
end | ||
|
||
ErlangCompiler.compile(manifest, mappings, :lfe, :beam, opts, callback) | ||
end | ||
|
||
@doc """ | ||
Removes compiled files for the given `manifest`. | ||
""" | ||
def clean(manifest), do: ErlangCompiler.clean(manifest) | ||
|
||
defp compile_result({:error, [{:error, [{file, [error | _]}], []}], [], []}) do | ||
{:error, [{file, [error]}], []} | ||
end | ||
|
||
defp compile_result(result), do: result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
defmodule Mix.Tasks.Test.Lfe do | ||
use Mix.Task.Compiler | ||
import Mix.Compilers.Lfe | ||
|
||
@recursive true | ||
@manifest "test.lfe" | ||
@switches [force: :boolean, all_warnings: :boolean] | ||
|
||
@moduledoc """ | ||
Compiles the source LFE source files of the project, using `Mix.Compilers.Lfe` | ||
and also compiles and runs all the test LFE files with the '-tests.lfe' extension in the | ||
'test' folder of the project. | ||
Uses the [ltest](https://github.com/lfex/ltest) library to do so. | ||
For the compilation it supports the command line options and the configuration of the `Mix.Tasks.Compile.Lfe` task. | ||
""" | ||
|
||
@doc """ | ||
Runs this task. | ||
""" | ||
def run(args) do | ||
{opts, _, _} = OptionParser.parse(args, switches: @switches) | ||
Mix.env(:test) | ||
|
||
do_run(opts) | ||
end | ||
|
||
@doc """ | ||
Returns LFE test manifests. | ||
""" | ||
def manifests, do: [manifest()] | ||
|
||
defp do_run(opts) do | ||
dest = Mix.Project.compile_path() |> String.replace("_build/dev", "_build/test") | ||
location = String.split(dest, "_build") |> List.last() | ||
{:ok, root} = File.cwd() | ||
dest = root |> Path.join("_build") |> Path.join(location) | ||
|
||
File.rmdir(dest) | ||
File.mkdir_p!(dest) | ||
|
||
dest_test = dest |> Path.join("_build") |> Path.join(location) | ||
|
||
File.rmdir(dest_test) | ||
File.mkdir_p!(dest_test) | ||
|
||
compile(manifest(), [{"src", dest}, {"test", dest_test}], opts) | ||
|
||
File.cd(dest) | ||
|
||
:"ltest-runner".unit() | ||
end | ||
|
||
defp manifest, do: Path.join(Mix.Project.manifest_path(), @manifest) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
%{ | ||
"color": {:hex, :erlang_color, "1.0.0", "145fe1d2e65c4516e4f03fefca6c2f47ebad5899d978d70382a5cfe643e4ac9e", [:rebar3], [], "hexpm"}, | ||
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"}, | ||
"erlang_color": {:hex, :erlang_color, "1.0.0", "145fe1d2e65c4516e4f03fefca6c2f47ebad5899d978d70382a5cfe643e4ac9e", [:rebar3], [], "hexpm"}, | ||
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, | ||
"lfe": {:hex, :lfe, "1.2.0", "257708859c0a6949f174cecee6f08bb5d6f08c0f97ec7b75c07072014723ecbc", [:rebar3], [], "hexpm"}, | ||
"ltest": {:hex, :ltest, "0.10.0-rc6", "a605158832d4dc2704cbb572423ec13d1a18dd4d48dec7aff7a3011d0261f9db", [:rebar3], [], "hexpm"}, | ||
"lutil": {:hex, :lutil, "0.10.0-rc6", "c3a560c9ed8cdc34b689591cf60336981ad4ea6ce299624ba87191d3fffb8da2", [:rebar3], [], "hexpm"}, | ||
} |