1
1
defmodule Mix.Compilers.Elixir do
2
2
@ moduledoc false
3
3
4
- @ manifest_vsn :v6
4
+ @ manifest_vsn :v7
5
5
6
6
import Record
7
7
@@ -13,7 +13,8 @@ defmodule Mix.Compilers.Elixir do
13
13
runtime_references: [ ] ,
14
14
compile_dispatches: [ ] ,
15
15
runtime_dispatches: [ ] ,
16
- external: [ ]
16
+ external: [ ] ,
17
+ warnings: [ ]
17
18
]
18
19
19
20
@ doc """
@@ -78,6 +79,8 @@ defmodule Mix.Compilers.Elixir do
78
79
stale = changed -- removed
79
80
sources = update_stale_sources ( all_sources , removed , changed )
80
81
82
+ if opts [ :all_warnings ] , do: show_warnings ( sources )
83
+
81
84
cond do
82
85
stale != [ ] ->
83
86
compile_manifest ( manifest , exts , modules , sources , stale , dest , timestamp , opts )
@@ -149,18 +152,19 @@ defmodule Mix.Compilers.Elixir do
149
152
150
153
# Starts a server responsible for keeping track which files
151
154
# were compiled and the dependencies between them.
152
- { :ok , pid } = Agent . start_link ( fn -> { modules , sources } end )
155
+ { :ok , pid } = Agent . start_link ( fn -> { modules , sources , % { } } end )
153
156
long_compilation_threshold = opts [ :long_compilation_threshold ] || 10
154
157
155
158
try do
156
159
_ = Kernel.ParallelCompiler . files stale ,
157
160
[ each_module: & each_module ( pid , cwd , & 1 , & 2 , & 3 ) ,
158
161
each_long_compilation: & each_long_compilation ( & 1 , long_compilation_threshold ) ,
162
+ each_warning: & each_warning ( pid , cwd , & 1 , & 2 , & 3 ) ,
159
163
long_compilation_threshold: long_compilation_threshold ,
160
164
dest: dest ] ++ extra
161
- Agent . cast pid , fn { modules , sources } ->
165
+ Agent . cast pid , fn { modules , sources , warnings } ->
162
166
write_manifest ( manifest , modules , sources , dest , timestamp )
163
- { modules , sources }
167
+ { modules , sources , warnings }
164
168
end
165
169
after
166
170
Agent . stop ( pid , :normal , :infinity )
@@ -201,7 +205,7 @@ defmodule Mix.Compilers.Elixir do
201
205
source = Path . relative_to ( source , cwd )
202
206
external = get_external_resources ( module , cwd )
203
207
204
- Agent . cast pid , fn { modules , sources } ->
208
+ Agent . cast pid , fn { modules , sources , warnings } ->
205
209
source_external = case List . keyfind ( sources , source , source ( :source ) ) do
206
210
source ( external: old_external ) -> external ++ old_external
207
211
nil -> external
@@ -227,12 +231,13 @@ defmodule Mix.Compilers.Elixir do
227
231
runtime_references: runtime_references ,
228
232
compile_dispatches: compile_dispatches ,
229
233
runtime_dispatches: runtime_dispatches ,
230
- external: source_external
234
+ external: source_external ,
235
+ warnings: Map . get ( warnings , source , [ ] )
231
236
)
232
237
233
238
modules = List . keystore ( modules , module , module ( :module ) , new_module )
234
239
sources = List . keystore ( sources , source , source ( :source ) , new_source )
235
- { modules , sources }
240
+ { modules , sources , warnings }
236
241
end
237
242
end
238
243
@@ -262,6 +267,15 @@ defmodule Mix.Compilers.Elixir do
262
267
Mix . shell . info "Compiling #{ source } (it's taking more than #{ threshold } s)"
263
268
end
264
269
270
+ defp each_warning ( pid , cwd , file , line , message ) do
271
+ Agent . cast pid , fn { modules , sources , warnings } ->
272
+ source_path = Path . relative_to ( file , cwd )
273
+ warning = { line , message }
274
+ warnings = Map . update ( warnings , source_path , [ warning ] , & ( [ warning | & 1 ] ) )
275
+ { modules , sources , warnings }
276
+ end
277
+ end
278
+
265
279
## Resolution
266
280
267
281
defp update_stale_sources ( sources , removed , changed ) do
@@ -350,6 +364,15 @@ defmodule Mix.Compilers.Elixir do
350
364
_ = :code . delete ( module )
351
365
end
352
366
367
+ defp show_warnings ( sources ) do
368
+ for source ( source: source , warnings: warnings ) <- sources do
369
+ file = Path . join ( File . cwd! , source )
370
+ for { line , message } <- warnings do
371
+ :elixir_errors . warn ( line , file , message )
372
+ end
373
+ end
374
+ end
375
+
353
376
## Manifest handling
354
377
355
378
# Similar to read_manifest, but supports data migration.
@@ -361,7 +384,7 @@ defmodule Mix.Compilers.Elixir do
361
384
else
362
385
[ @ manifest_vsn | data ] ->
363
386
split_manifest ( data , compile_path )
364
- [ v | data ] when v in [ :v4 , :v5 ] ->
387
+ [ v | data ] when v in [ :v4 , :v5 , :v6 ] ->
365
388
for module ( beam: beam ) <- data , do: File . rm ( Path . join ( compile_path , beam ) )
366
389
{ [ ] , [ ] }
367
390
_ ->
0 commit comments