@@ -4,20 +4,23 @@ defmodule Mix.Compilers.Erlang do
4
4
@ manifest_vsn 1
5
5
6
6
@ doc """
7
- Compiles the files in `mappings` with given extensions into
8
- the destination, automatically invoking the callback for each
9
- stale input and output pair (or for all if `force` is `true`) and
10
- removing files that no longer have a source, while keeping the
11
- `manifest` up to date.
7
+ Compiles the given `mappings`.
12
8
13
- `mappings` should be a list of tuples in the form of `{src, dest}` paths.
9
+ `mappings` is a list of `{src, dest}` pairs, where the source
10
+ extensions are compiled into the destination extension,
11
+ automatically invoking the callback for each stale pair (or for
12
+ all if `force` is `true`) and removing files that no longer have
13
+ a source, while keeping the `manifest` up to date.
14
14
15
15
## Options
16
16
17
17
* `:force` - forces compilation regardless of modification times
18
18
19
19
* `:parallel` - a mapset of files to compile in parallel
20
20
21
+ * `:preload` - any code that must be preloaded if any pending
22
+ entry needs to be compiled
23
+
21
24
## Examples
22
25
23
26
For example, a simple compiler for Lisp Flavored Erlang
@@ -54,22 +57,25 @@ defmodule Mix.Compilers.Erlang do
54
57
def compile ( manifest , mappings , src_ext , dest_ext , opts , callback ) when is_list ( opts ) do
55
58
force = opts [ :force ]
56
59
57
- files =
60
+ entries =
58
61
for { src , dest } <- mappings ,
59
- target <- extract_targets ( src , src_ext , dest , dest_ext , force ) ,
62
+ target <- extract_entries ( src , src_ext , dest , dest_ext , force ) ,
60
63
do: target
61
64
62
- compile ( manifest , files , src_ext , opts , callback )
65
+ if preload = entries != [ ] && opts [ :preload ] do
66
+ preload . ( )
67
+ end
68
+
69
+ compile ( manifest , entries , src_ext , opts , callback )
63
70
end
64
71
65
72
@ doc """
66
- Compiles the given `mappings `.
73
+ Compiles the given `entries `.
67
74
68
- `mappings` should be a list of tuples in the form of `{ src, dest}`.
75
+ `entries` are a list of `{:ok | :stale, src, dest}` tuples .
69
76
70
- A `manifest` file and a `callback` to be invoked for each src/dest pair
71
- must be given. A src/dest pair where destination is `nil` is considered
72
- to be up to date and won't be (re-)compiled.
77
+ A `manifest` file and a `callback` to be invoked for each stale
78
+ src/dest pair must also be given.
73
79
74
80
## Options
75
81
@@ -78,8 +84,8 @@ defmodule Mix.Compilers.Erlang do
78
84
* `:parallel` - a mapset of files to compile in parallel
79
85
80
86
"""
81
- def compile ( manifest , mappings , opts \\ [ ] , callback ) do
82
- compile ( manifest , mappings , :erl , opts , callback )
87
+ def compile ( manifest , entries , opts \\ [ ] , callback ) do
88
+ compile ( manifest , entries , :erl , opts , callback )
83
89
end
84
90
85
91
defp compile ( manifest , mappings , ext , opts , callback ) do
@@ -102,7 +108,7 @@ defmodule Mix.Compilers.Erlang do
102
108
# Clear stale and removed files from manifest
103
109
entries =
104
110
Enum . reject ( entries , fn { dest , _warnings } ->
105
- dest in removed || Enum . any ?( stale , fn { _ , stale_dest } -> dest == stale_dest end )
111
+ dest in removed || List . keymember ?( stale , dest , 1 )
106
112
end )
107
113
108
114
if Keyword . get ( opts , :all_warnings , true ) , do: show_warnings ( entries )
@@ -156,9 +162,8 @@ defmodule Mix.Compilers.Erlang do
156
162
end
157
163
end
158
164
159
- @ doc """
160
- Ensures the native OTP application is available.
161
- """
165
+ # TODO: Deprecate this in favor of `Mix.ensure_application!/1` in Elixir v1.19.
166
+ @ doc false
162
167
def ensure_application! ( app , _input ) do
163
168
Mix . ensure_application! ( app )
164
169
{ :ok , _ } = Application . ensure_all_started ( app )
@@ -202,7 +207,7 @@ defmodule Mix.Compilers.Erlang do
202
207
manifest |> read_manifest ( ) |> Enum . map ( & elem ( & 1 , 0 ) )
203
208
end
204
209
205
- defp extract_targets ( src_dir , src_ext , dest_dir , dest_ext , force ) do
210
+ defp extract_entries ( src_dir , src_ext , dest_dir , dest_ext , force ) do
206
211
files = Mix.Utils . extract_files ( List . wrap ( src_dir ) , List . wrap ( src_ext ) )
207
212
208
213
for file <- files do
0 commit comments