Skip to content

Commit ea21b23

Browse files
committed
Add version 0.2.0-rc1
1 parent f9dc79d commit ea21b23

File tree

6 files changed

+135
-25
lines changed

6 files changed

+135
-25
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ It is a Mix compiler which uses the Erlang Mix compiler.
66

77
Lisp is a great language to get into the functional way of thinking and LFE is Lisp 2+ which runs on the greatest platform (personal opinion).
88
Elixir's Mix is a great (or the greatest) configuration/package/build manager, so why not use it to compile LFE?
9-
Also Elixir developers should try LFE! This little project has the purpose to make that an easier.
9+
Also Elixir developers should try LFE! This little project has the purpose to make that easier.
1010

1111
## Installation
1212

@@ -15,7 +15,7 @@ You can create a Mix project with `mix new <project_name>` and add this as depen
1515
```elixir
1616
def deps do
1717
[
18-
{:mix_lfe, "~> 0.1.0"}
18+
{:mix_lfe, "0.2.0-rc1"}
1919
]
2020
end
2121
```
@@ -37,6 +37,17 @@ To use the compiled modules with the LFE REPL, you can run:
3737

3838
Also if you want to just run `mix compile` add `compilers: Mix.compilers() ++ [:lfe]` to the list returned by `project/0` which is defined in your `mix.exs`.
3939

40+
## Using it for running tests
41+
42+
The compiler can compile and run [ltest](https://github.com/lfex/ltest) tests.
43+
Just put all the tests in the `test` folder of the project and run:
44+
45+
```bash
46+
mix test.lfe
47+
```
48+
49+
Works with umbrella applications.
50+
4051
## Example projects
4152

4253
TODO
@@ -47,7 +58,7 @@ The tests of this project mirror the ones for the Erlang Mix compiler.
4758
For now the source is very simple and uses an [idea](https://github.com/elixir-lang/elixir/blob/e1c903a5956e4cb9075f0aac00638145788b0da4/lib/mix/lib/mix/compilers/erlang.ex#L20) from the Erlang Mix compiler.
4859
All works well, but requires some manual work and doesn't support LFE compiler fine tunning, so that's what we'll be after next.
4960

50-
1. Add task for running LFE tests. What kind of tests? Will see...
61+
1. Make it possible to add options when running `mix test.lfe`.
5162
2. Automate the installation & setup process in a way. Maybe by using something similar to the Phoenix generator tasks.
5263
3. Pass more options to the LFE compiler, using mix configuration.
5364
4. Use LFE syntax for configuration (not sure this is needed, really).

lib/mix/compilers/lfe.ex

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
defmodule Mix.Compilers.Lfe do
2+
alias Mix.Compilers.Erlang, as: ErlangCompiler
3+
4+
@moduledoc false
5+
6+
@doc """
7+
Compiles the files in `mappings` with '.lfe' extensions into
8+
the destinations.
9+
Does this for each stale input and output pair (or for all if `force` is `true`) and
10+
removes files that no longer have a source, while keeping the `manifest` up to date.
11+
12+
`mappings` should be a list of tuples in the form of `{src, dest}` paths.
13+
14+
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.
15+
16+
It supports the options of the Erlang Mix compiler under the covers as it is used.
17+
"""
18+
def compile(manifest, [{_, _} | _] = mappings, opts) do
19+
callback = fn input, output ->
20+
module = input |> Path.basename(".lfe") |> String.to_atom()
21+
:code.purge(module)
22+
:code.delete(module)
23+
24+
outdir = output |> Path.dirname() |> ErlangCompiler.to_erl_file()
25+
26+
compile_result(:lfe_comp.file(ErlangCompiler.to_erl_file(input), [{:outdir, outdir}, :return, :report]))
27+
end
28+
29+
ErlangCompiler.compile(manifest, mappings, :lfe, :beam, opts, callback)
30+
end
31+
32+
@doc """
33+
Removes compiled files for the given `manifest`.
34+
"""
35+
def clean(manifest), do: ErlangCompiler.clean(manifest)
36+
37+
defp compile_result({:error, [{:error, [{file, [error | _]}], []}], [], []}) do
38+
{:error, [{file, [error]}], []}
39+
end
40+
41+
defp compile_result(result), do: result
42+
end

lib/mix/tasks/compile.lfe.ex

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule Mix.Tasks.Compile.Lfe do
22
use Mix.Task.Compiler
3-
import Mix.Compilers.Erlang
3+
import Mix.Compilers.Lfe
44

55
@recursive true
66
@manifest "compile.lfe"
@@ -11,8 +11,7 @@ defmodule Mix.Tasks.Compile.Lfe do
1111
1212
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.
1313
14-
It supports the options of the Erlang Mix compiler under the covers at it is used.
15-
This means that these options are supported:
14+
These options are supported:
1615
1716
## Command line options
1817
* `--force` - forces compilation regardless of modification times
@@ -35,17 +34,7 @@ defmodule Mix.Tasks.Compile.Lfe do
3534
defp do_run(opts) do
3635
dest = Mix.Project.compile_path()
3736

38-
callback = fn input, output ->
39-
module = input |> Path.basename(".lfe") |> String.to_atom()
40-
:code.purge(module)
41-
:code.delete(module)
42-
43-
outdir = output |> Path.dirname() |> to_erl_file()
44-
45-
compile_result(:lfe_comp.file(to_erl_file(input), [{:outdir, outdir}, :return, :report]))
46-
end
47-
48-
compile(manifest(), [{"src", dest}], :lfe, :beam, opts, callback)
37+
compile(manifest(), [{"src", dest}], opts)
4938
end
5039

5140
@doc """
@@ -59,10 +48,4 @@ defmodule Mix.Tasks.Compile.Lfe do
5948
def clean, do: clean(manifest())
6049

6150
defp manifest, do: Path.join(Mix.Project.manifest_path(), @manifest)
62-
63-
defp compile_result({:error, [{:error, [{file, [error | _]}], []}], [], []}) do
64-
{:error, [{file, [error]}], []}
65-
end
66-
67-
defp compile_result(result), do: result
6851
end

lib/mix/tasks/test.lfe.ex

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
defmodule Mix.Tasks.Test.Lfe do
2+
use Mix.Task.Compiler
3+
import Mix.Compilers.Lfe
4+
5+
@recursive true
6+
@manifest "test.lfe"
7+
@switches [force: :boolean, all_warnings: :boolean]
8+
9+
@moduledoc """
10+
Compiles the source LFE source files of the project, using `Mix.Compilers.Lfe`
11+
and also compiles and runs all the test LFE files with the '-tests.lfe' extension in the
12+
'test' folder of the project.
13+
14+
Uses the [ltest](https://github.com/lfex/ltest) library to do so.
15+
16+
For the compilation it supports the command line options and the configuration of the `Mix.Tasks.Compile.Lfe` task.
17+
"""
18+
19+
@doc """
20+
Runs this task.
21+
"""
22+
def run(args) do
23+
{opts, _, _} = OptionParser.parse(args, switches: @switches)
24+
Mix.env(:test)
25+
26+
do_run(opts)
27+
end
28+
29+
@doc """
30+
Returns LFE test manifests.
31+
"""
32+
def manifests, do: [manifest()]
33+
34+
defp do_run(opts) do
35+
dest = Mix.Project.compile_path() |> String.replace("_build/dev", "_build/test")
36+
location = String.split(dest, "_build") |> List.last()
37+
{:ok, root} = File.cwd()
38+
dest = root |> Path.join("_build") |> Path.join(location)
39+
40+
File.rmdir(dest)
41+
File.mkdir_p!(dest)
42+
43+
dest_test = dest |> Path.join("_build") |> Path.join(location)
44+
45+
File.rmdir(dest_test)
46+
File.mkdir_p!(dest_test)
47+
48+
compile(manifest(), [{"src", dest}, {"test", dest_test}], opts)
49+
50+
File.cd(dest)
51+
52+
:"ltest-runner".unit()
53+
end
54+
55+
defp manifest, do: Path.join(Mix.Project.manifest_path(), @manifest)
56+
end

mix.exs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
defmodule MixLfe.MixProject do
22
use Mix.Project
33

4+
@version "0.2.0-rc1"
5+
46
def project do
57
[
68
app: :mix_lfe,
7-
version: "0.1.0",
9+
version: @version,
810
elixir: "~> 1.6",
911
start_permanent: Mix.env() == :prod,
1012
description: "A LFE compiler for Mix",
13+
docs: [
14+
extras: ["README.md"],
15+
main: "readme",
16+
source_ref: "v#{@version}",
17+
source_url: "https://github.com/meddle0x53/mix_lfe"
18+
],
1119
package: package(),
1220
deps: deps()
1321
]
@@ -27,7 +35,11 @@ defmodule MixLfe.MixProject do
2735

2836
def deps do
2937
[
30-
{:lfe, "~> 1.2", override: true, manager: :rebar}
38+
{:lfe, "~> 1.2"},
39+
{:ltest, "0.10.0-rc6"},
40+
{:color, "~> 1.0", hex: :erlang_color},
41+
{:lutil, "~> 0.10.0-rc6"},
42+
{:ex_doc, ">= 0.0.0", only: :dev}
3143
]
3244
end
3345
end

mix.lock

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
%{
2+
"color": {:hex, :erlang_color, "1.0.0", "145fe1d2e65c4516e4f03fefca6c2f47ebad5899d978d70382a5cfe643e4ac9e", [:rebar3], [], "hexpm"},
3+
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
4+
"erlang_color": {:hex, :erlang_color, "1.0.0", "145fe1d2e65c4516e4f03fefca6c2f47ebad5899d978d70382a5cfe643e4ac9e", [:rebar3], [], "hexpm"},
5+
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
26
"lfe": {:hex, :lfe, "1.2.0", "257708859c0a6949f174cecee6f08bb5d6f08c0f97ec7b75c07072014723ecbc", [:rebar3], [], "hexpm"},
7+
"ltest": {:hex, :ltest, "0.10.0-rc6", "a605158832d4dc2704cbb572423ec13d1a18dd4d48dec7aff7a3011d0261f9db", [:rebar3], [], "hexpm"},
8+
"lutil": {:hex, :lutil, "0.10.0-rc6", "c3a560c9ed8cdc34b689591cf60336981ad4ea6ce299624ba87191d3fffb8da2", [:rebar3], [], "hexpm"},
39
}

0 commit comments

Comments
 (0)