Skip to content

Commit 49af97a

Browse files
ericmjJosé Valim
authored and
José Valim
committed
Support rebar3 dependency package declaration (#5678)
Currently only {app, “~> 1.0.0”, {pkg, hex_package}} is supported. This change will also support {app, {pkg, hex_package}}. Signed-off-by: José Valim <[email protected]>
1 parent b806ee8 commit 49af97a

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

lib/mix/lib/mix/rebar.ex

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ defmodule Mix.Rebar do
218218
[fun.(config) | subs]
219219
end
220220

221+
# Translate a rebar dependency declaration to a mix declaration
222+
# From http://www.rebar3.org/docs/dependencies#section-declaring-dependencies
221223
defp parse_dep(app) when is_atom(app) do
222224
{app, ">= 0.0.0"}
223225
end
@@ -226,10 +228,6 @@ defmodule Mix.Rebar do
226228
{app, List.to_string(req)}
227229
end
228230

229-
defp parse_dep({app, req, {:pkg, package}}) when is_list(req) do
230-
{app, List.to_string(req), hex: package}
231-
end
232-
233231
defp parse_dep({app, source}) when is_tuple(source) do
234232
parse_dep({app, nil, source, []})
235233
end
@@ -239,37 +237,52 @@ defmodule Mix.Rebar do
239237
end
240238

241239
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
242254
[scm, url | source] = Tuple.to_list(source)
243255

244256
ref =
245257
case source do
246-
["" | _] -> [branch: "HEAD"]
258+
["" | _] -> [branch: "HEAD"]
247259
[{: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+
_ -> []
252264
end
253265

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
261267
end
262268

263269
defp compile_req(nil) do
264270
">= 0.0.0"
265271
end
266272

267273
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
273286
end
274287
end
275288

lib/mix/test/mix/rebar_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ defmodule Mix.RebarTest do
5555
assert [{:git_rebar, "~> 1.0", hex: :rebar_fork}] ==
5656
Mix.Rebar.deps(:foo, config, [])
5757

58+
config = [deps: [{:git_rebar, {:pkg, :rebar_fork}}]]
59+
assert [{:git_rebar, ">= 0.0.0", hex: :rebar_fork}] ==
60+
Mix.Rebar.deps(:foo, config, [])
61+
5862
config = [deps: [{:git_rebar, '0.1..*', {:git, '../../test/fixtures/git_rebar', :master}}]]
5963
assert [{:git_rebar, ~r"0.1..*", [git: "../../test/fixtures/git_rebar", ref: "master"]}] ==
6064
Mix.Rebar.deps(:foo, config, [])

0 commit comments

Comments
 (0)