@@ -218,6 +218,8 @@ defmodule Mix.Rebar do
218
218
[ fun . ( config ) | subs ]
219
219
end
220
220
221
+ # Translate a rebar dependency declaration to a mix declaration
222
+ # From http://www.rebar3.org/docs/dependencies#section-declaring-dependencies
221
223
defp parse_dep ( app ) when is_atom ( app ) do
222
224
{ app , ">= 0.0.0" }
223
225
end
@@ -226,10 +228,6 @@ defmodule Mix.Rebar do
226
228
{ app , List . to_string ( req ) }
227
229
end
228
230
229
- defp parse_dep ( { app , req , { :pkg , package } } ) when is_list ( req ) do
230
- { app , List . to_string ( req ) , hex: package }
231
- end
232
-
233
231
defp parse_dep ( { app , source } ) when is_tuple ( source ) do
234
232
parse_dep ( { app , nil , source , [ ] } )
235
233
end
@@ -239,37 +237,52 @@ defmodule Mix.Rebar do
239
237
end
240
238
241
239
defp parse_dep ( { app , req , source , opts } ) do
240
+ source = parse_source ( source )
241
+
242
+ compile =
243
+ if :proplists . get_value ( :raw , opts , false ) ,
244
+ do: [ compile: false ] ,
245
+ else: [ ]
246
+
247
+ { app , compile_req ( req ) , source ++ compile }
248
+ end
249
+
250
+ defp parse_source ( { :pkg , pkg } ) do
251
+ [ hex: pkg ]
252
+ end
253
+ defp parse_source ( source ) do
242
254
[ scm , url | source ] = Tuple . to_list ( source )
243
255
244
256
ref =
245
257
case source do
246
- [ "" | _ ] -> [ branch: "HEAD" ]
258
+ [ "" | _ ] -> [ branch: "HEAD" ]
247
259
[ { :branch , branch } | _ ] -> [ branch: to_string ( branch ) ]
248
- [ { :tag , tag } | _ ] -> [ tag: to_string ( tag ) ]
249
- [ { :ref , ref } | _ ] -> [ ref: to_string ( ref ) ]
250
- [ ref | _ ] -> [ ref: to_string ( ref ) ]
251
- _ -> [ ]
260
+ [ { :tag , tag } | _ ] -> [ tag: to_string ( tag ) ]
261
+ [ { :ref , ref } | _ ] -> [ ref: to_string ( ref ) ]
262
+ [ ref | _ ] -> [ ref: to_string ( ref ) ]
263
+ _ -> [ ]
252
264
end
253
265
254
- compile =
255
- if :proplists . get_value ( :raw , opts , false ) ,
256
- do: [ compile: false ] ,
257
- else: [ ]
258
-
259
- mix_opts = [ { scm , to_string ( url ) } ] ++ ref ++ compile
260
- { app , compile_req ( req ) , mix_opts }
266
+ [ { scm , to_string ( url ) } ] ++ ref
261
267
end
262
268
263
269
defp compile_req ( nil ) do
264
270
">= 0.0.0"
265
271
end
266
272
267
273
defp compile_req ( req ) do
268
- case Regex . compile ( List . to_string ( req ) ) do
269
- { :ok , re } ->
270
- re
271
- { :error , reason } ->
272
- Mix . raise "Unable to compile version regex: #{ inspect req } , #{ reason } "
274
+ req = List . to_string ( req )
275
+
276
+ case Version . parse_requirement ( req ) do
277
+ { :ok , _ } ->
278
+ req
279
+ :error ->
280
+ case Regex . compile ( req ) do
281
+ { :ok , re } ->
282
+ re
283
+ { :error , reason } ->
284
+ Mix . raise "Unable to compile version regex: #{ inspect req } , #{ reason } "
285
+ end
273
286
end
274
287
end
275
288
0 commit comments