@@ -30,59 +30,68 @@ defmodule Mix.Tasks.Deps.Compile do
30
30
`b` is included in the compilation step, pass `--include-children`.
31
31
"""
32
32
33
- import Mix.Dep , only: [ loaded: 1 , available?: 1 , loaded_by_name: 2 ,
34
- make?: 1 , mix?: 1 ]
33
+ import Mix.Dep , only: [ loaded: 1 , available?: 1 , loaded_by_name: 2 , make?: 1 , mix?: 1 ]
35
34
36
35
@ switches [ include_children: :boolean , force: :boolean ]
37
36
38
- @ spec run ( OptionParser . argv ) :: :ok
37
+ @ spec run ( OptionParser . argv ( ) ) :: :ok
39
38
def run ( args ) do
40
39
unless "--no-archives-check" in args do
41
- Mix.Task . run "archive.check" , args
40
+ Mix.Task . run ( "archive.check" , args )
42
41
end
43
42
44
- Mix.Project . get!
43
+ Mix.Project . get! ( )
45
44
46
45
case OptionParser . parse ( args , switches: @ switches ) do
47
46
{ opts , [ ] , _ } ->
48
47
# Because this command may be invoked explicitly with
49
48
# deps.compile, we simply try to compile any available
50
49
# dependency.
51
- compile ( Enum . filter ( loaded ( env: Mix . env ) , & available? / 1 ) , opts )
50
+ compile ( Enum . filter ( loaded ( env: Mix . env ( ) ) , & available? / 1 ) , opts )
51
+
52
52
{ opts , tail , _ } ->
53
- compile ( loaded_by_name ( tail , [ env: Mix . env ] ++ opts ) , opts )
53
+ compile ( loaded_by_name ( tail , [ env: Mix . env ( ) ] ++ opts ) , opts )
54
54
end
55
55
end
56
56
57
57
@ doc false
58
58
def compile ( deps , options \\ [ ] ) do
59
- shell = Mix . shell
60
- config = Mix.Project . deps_config
59
+ shell = Mix . shell ( )
60
+ config = Mix.Project . deps_config ( )
61
61
62
- Mix.Task . run "deps.precompile"
62
+ Mix.Task . run ( "deps.precompile" )
63
63
64
64
compiled =
65
65
Enum . map ( deps , fn % Mix.Dep { app: app , status: status , opts: opts , scm: scm } = dep ->
66
66
check_unavailable! ( app , status )
67
67
68
68
maybe_clean ( app , options )
69
69
70
- compiled? = cond do
71
- not is_nil ( opts [ :compile ] ) ->
72
- do_compile dep , config
73
- mix? ( dep ) ->
74
- do_mix dep , config
75
- make? ( dep ) ->
76
- do_make dep , config
77
- dep . manager == :rebar ->
78
- do_rebar dep , config
79
- dep . manager == :rebar3 ->
80
- do_rebar3 dep , config
81
- true ->
82
- shell . error "Could not compile #{ inspect app } , no \" mix.exs\" , \" rebar.config\" or \" Makefile\" " <>
83
- "(pass :compile as an option to customize compilation, set it to \" false\" to do nothing)"
84
- false
85
- end
70
+ compiled? =
71
+ cond do
72
+ not is_nil ( opts [ :compile ] ) ->
73
+ do_compile ( dep , config )
74
+
75
+ mix? ( dep ) ->
76
+ do_mix ( dep , config )
77
+
78
+ make? ( dep ) ->
79
+ do_make ( dep , config )
80
+
81
+ dep . manager == :rebar ->
82
+ do_rebar ( dep , config )
83
+
84
+ dep . manager == :rebar3 ->
85
+ do_rebar3 ( dep , config )
86
+
87
+ true ->
88
+ shell . error (
89
+ "Could not compile #{ inspect ( app ) } , no \" mix.exs\" , \" rebar.config\" or \" Makefile\" " <>
90
+ "(pass :compile as an option to customize compilation, set it to \" false\" to do nothing)"
91
+ )
92
+
93
+ false
94
+ end
86
95
87
96
unless mix? ( dep ) , do: build_structure ( dep , config )
88
97
# We should touch fetchable dependencies even if they
@@ -92,12 +101,12 @@ defmodule Mix.Tasks.Deps.Compile do
92
101
compiled? and fetchable?
93
102
end )
94
103
95
- if true in compiled , do: Mix.Dep.Lock . touch_manifest , else: :ok
104
+ if true in compiled , do: Mix.Dep.Lock . touch_manifest ( ) , else: :ok
96
105
end
97
106
98
107
defp maybe_clean ( app , opts ) do
99
108
if Keyword . get ( opts , :force , false ) do
100
- File . rm_rf! Path . join [ Mix.Project . build_path , "lib" , Atom . to_string ( app ) ]
109
+ File . rm_rf! ( Path . join ( [ Mix.Project . build_path ( ) , "lib" , Atom . to_string ( app ) ] ) )
101
110
end
102
111
end
103
112
@@ -112,83 +121,109 @@ defmodule Mix.Tasks.Deps.Compile do
112
121
end
113
122
114
123
defp check_unavailable! ( app , { :unavailable , _ } ) do
115
- Mix . raise "Cannot compile dependency #{ inspect app } because " <>
116
- "it isn't available, run \" mix deps.get\" first"
124
+ Mix . raise (
125
+ "Cannot compile dependency #{ inspect ( app ) } because " <>
126
+ "it isn't available, run \" mix deps.get\" first"
127
+ )
117
128
end
118
129
119
130
defp check_unavailable! ( _ , _ ) do
120
131
:ok
121
132
end
122
133
123
134
defp do_mix ( dep , _config ) do
124
- Mix.Dep . in_dependency dep , fn _ ->
125
- if req = old_elixir_req ( Mix.Project . config ) do
126
- Mix . shell . error "warning: the dependency #{ inspect dep . app } requires Elixir #{ inspect req } " <>
127
- "but you are running on v#{ System . version } "
135
+ Mix.Dep . in_dependency ( dep , fn _ ->
136
+ if req = old_elixir_req ( Mix.Project . config ( ) ) do
137
+ Mix . shell ( ) . error (
138
+ "warning: the dependency #{ inspect ( dep . app ) } requires Elixir #{ inspect ( req ) } " <>
139
+ "but you are running on v#{ System . version ( ) } "
140
+ )
128
141
end
129
142
130
143
# Force recompilation on compile status
131
144
if dep . status == :compile do
132
- Mix.Dep.Lock . touch_manifest
145
+ Mix.Dep.Lock . touch_manifest ( )
133
146
end
134
147
135
148
try do
136
- res = Mix.Task . run ( "compile" , [ "--no-deps" , "--no-archives-check" ,
137
- "--no-elixir-version-check" , "--no-warnings-as-errors" ] )
149
+ options = [
150
+ "--no-deps" ,
151
+ "--no-archives-check" ,
152
+ "--no-elixir-version-check" ,
153
+ "--no-warnings-as-errors"
154
+ ]
155
+
156
+ res = Mix.Task . run ( "compile" , options )
157
+
138
158
match? ( { :ok , _ } , res )
139
159
catch
140
160
kind , reason ->
141
- stacktrace = System . stacktrace
161
+ stacktrace = System . stacktrace ( )
142
162
app = dep . app
143
- Mix . shell . error "could not compile dependency #{ inspect app } , \" mix compile\" failed. " <>
144
- "You can recompile this dependency with \" mix deps.compile #{ app } \" , update it " <>
145
- "with \" mix deps.update #{ app } \" or clean it with \" mix deps.clean #{ app } \" "
163
+
164
+ Mix . shell ( ) . error (
165
+ "could not compile dependency #{ inspect ( app ) } , \" mix compile\" failed. " <>
166
+ "You can recompile this dependency with \" mix deps.compile #{ app } \" , update it " <>
167
+ "with \" mix deps.update #{ app } \" or clean it with \" mix deps.clean #{ app } \" "
168
+ )
169
+
146
170
:erlang . raise ( kind , reason , stacktrace )
147
171
end
148
- end
172
+ end )
149
173
end
150
174
151
175
defp do_rebar ( dep , config ) do
152
176
lib_path = Path . join ( config [ :env_path ] , "lib" )
153
- cmd = "#{ rebar_cmd ( dep ) } compile skip_deps=true deps_dir=#{ inspect lib_path } "
154
- do_command dep , config , cmd , false
177
+ cmd = "#{ rebar_cmd ( dep ) } compile skip_deps=true deps_dir=#{ inspect ( lib_path ) } "
178
+ do_command ( dep , config , cmd , false )
155
179
end
156
180
157
181
defp do_rebar3 ( % Mix.Dep { opts: opts } = dep , config ) do
158
- dep_path = opts [ :build ]
182
+ dep_path = opts [ :build ]
159
183
config_path = Path . join ( dep_path , "mix.rebar.config" )
160
- lib_path = Path . join ( config [ :env_path ] , "lib/*/ebin" )
184
+ lib_path = Path . join ( config [ :env_path ] , "lib/*/ebin" )
161
185
162
186
env = [ { "REBAR_CONFIG" , config_path } , { "TERM" , "dumb" } ]
163
- cmd = "#{ rebar_cmd ( dep ) } bare compile --paths #{ inspect lib_path } "
187
+ cmd = "#{ rebar_cmd ( dep ) } bare compile --paths #{ inspect ( lib_path ) } "
164
188
165
189
File . mkdir_p! ( dep_path )
166
190
File . write! ( config_path , rebar_config ( dep ) )
167
- do_command dep , config , cmd , false , env
191
+ do_command ( dep , config , cmd , false , env )
168
192
end
169
193
170
194
defp rebar_config ( dep ) do
171
195
dep . extra
172
- |> Mix.Rebar . dependency_config
173
- |> Mix.Rebar . serialize_config
196
+ |> Mix.Rebar . dependency_config ( )
197
+ |> Mix.Rebar . serialize_config ( )
174
198
end
175
199
176
200
defp rebar_cmd ( % Mix.Dep { manager: manager } = dep ) do
177
201
Mix.Rebar . rebar_cmd ( manager ) || handle_rebar_not_found ( dep )
178
202
end
179
203
180
204
defp handle_rebar_not_found ( % Mix.Dep { app: app , manager: manager } ) do
181
- shell = Mix . shell
182
- shell . info "Could not find \" #{ manager } \" , which is needed to build dependency #{ inspect app } "
183
- shell . info "I can install a local copy which is just used by Mix"
205
+ shell = Mix . shell ( )
206
+
207
+ shell . info (
208
+ "Could not find \" #{ manager } \" , which is needed to build dependency #{ inspect ( app ) } "
209
+ )
184
210
185
- unless shell . yes? ( "Shall I install #{ manager } ? (if running non-interactively, use \" mix local.rebar --force\" )" ) do
186
- Mix . raise "Could not find \" #{ manager } \" to compile " <>
187
- "dependency #{ inspect app } , please ensure \" #{ manager } \" is available"
211
+ shell . info ( "I can install a local copy which is just used by Mix" )
212
+
213
+ install_question =
214
+ "Shall I install #{ manager } ? (if running non-interactively, " <>
215
+ "use \" mix local.rebar --force\" )"
216
+
217
+ unless shell . yes? ( install_question ) do
218
+ error_message =
219
+ "Could not find \" #{ manager } \" to compile " <>
220
+ "dependency #{ inspect ( app ) } , please ensure \" #{ manager } \" is available"
221
+
222
+ Mix . raise ( error_message )
188
223
end
189
224
190
225
( Mix.Tasks.Local.Rebar . run ( [ ] ) && Mix.Rebar . local_rebar_cmd ( manager ) ) ||
191
- Mix . raise "\" #{ manager } \" installation failed"
226
+ Mix . raise ( "\" #{ manager } \" installation failed" )
192
227
end
193
228
194
229
defp do_make ( dep , config ) do
@@ -200,11 +235,13 @@ defmodule Mix.Tasks.Deps.Compile do
200
235
makefile_win? = makefile_win? ( dep )
201
236
202
237
command =
203
- case :os . type do
238
+ case :os . type ( ) do
204
239
{ :win32 , _ } when makefile_win? ->
205
240
"nmake /F Makefile.win"
241
+
206
242
{ :unix , type } when type in [ :freebsd , :openbsd ] ->
207
243
"gmake"
244
+
208
245
_ ->
209
246
"make"
210
247
end
@@ -227,34 +264,40 @@ defmodule Mix.Tasks.Deps.Compile do
227
264
defp do_command ( % Mix.Dep { app: app , opts: opts } , config , command , print_app? , env \\ [ ] ) do
228
265
File . cd! ( opts [ :dest ] , fn ->
229
266
env = [ { "ERL_LIBS" , Path . join ( config [ :env_path ] , "lib" ) } ] ++ env
267
+
230
268
if Mix.Shell . cmd ( command , env: env , into: % Mix.Shell { print_app?: print_app? } ) != 0 do
231
- Mix . raise "Could not compile dependency #{ inspect app } , \" #{ command } \" command failed. " <>
232
- "You can recompile this dependency with \" mix deps.compile #{ app } \" , update it " <>
233
- "with \" mix deps.update #{ app } \" or clean it with \" mix deps.clean #{ app } \" "
269
+ Mix . raise (
270
+ "Could not compile dependency #{ inspect ( app ) } , \" #{ command } \" command failed. " <>
271
+ "You can recompile this dependency with \" mix deps.compile #{ app } \" , update it " <>
272
+ "with \" mix deps.update #{ app } \" or clean it with \" mix deps.clean #{ app } \" "
273
+ )
234
274
end
235
275
end )
276
+
236
277
true
237
278
end
238
279
239
280
defp build_structure ( % Mix.Dep { opts: opts } = dep , config ) do
240
281
build_path = Path . dirname ( opts [ :build ] )
241
- Enum . each Mix.Dep . source_paths ( dep ) , fn { source , base } ->
282
+
283
+ Enum . each ( Mix.Dep . source_paths ( dep ) , fn { source , base } ->
242
284
app = Path . join ( build_path , base )
243
285
build_structure ( source , app , config )
244
286
Code . prepend_path ( Path . join ( app , "ebin" ) )
245
- end
287
+ end )
246
288
end
247
289
248
290
defp build_structure ( dest , build , config ) do
249
- File . cd! dest , fn ->
291
+ File . cd! ( dest , fn ->
250
292
config = Keyword . put ( config , :app_path , build )
251
293
Mix.Project . build_structure ( config , symlink_ebin: true )
252
- end
294
+ end )
253
295
end
254
296
255
297
defp old_elixir_req ( config ) do
256
298
req = config [ :elixir ]
257
- if req && not Version . match? ( System . version , req ) do
299
+
300
+ if req && not Version . match? ( System . version ( ) , req ) do
258
301
req
259
302
end
260
303
end
0 commit comments