Skip to content

Commit bf9e190

Browse files
committed
Optional deps should be kept for the project that specifies them
1 parent 0f6459e commit bf9e190

File tree

4 files changed

+12
-60
lines changed

4 files changed

+12
-60
lines changed

lib/mix/lib/mix/deps/retriever.ex

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ defmodule Mix.Deps.Retriever do
88
Gets all direct children of the current `Mix.Project`
99
as a `Mix.Dep` record. Umbrella project dependencies
1010
are included as children.
11-
12-
Optional dependencies are filtered out as they only
13-
matter as a dependency children.
1411
"""
1512
def children do
16-
mix_children |> Enum.reject(fn Mix.Dep[opts: opts] -> opts[:optional] end)
13+
scms = Mix.SCM.available
14+
from = Path.absname("mix.exs")
15+
Enum.map(Mix.project[:deps] || [], &to_dep(&1, scms, from)) ++
16+
Mix.Deps.Umbrella.unfetched
1717
end
1818

1919
@doc """
@@ -96,7 +96,7 @@ defmodule Mix.Deps.Retriever do
9696
]
9797
else
9898
raise Mix.Error, message: "#{inspect Mix.Project.get} did not specify a supported scm " <>
99-
"for app #{inspect app}, expected one of :git, :path, :in_umbrella or :optional"
99+
"for app #{inspect app}, expected one of :git, :path or :in_umbrella"
100100
end
101101
end
102102

@@ -153,17 +153,10 @@ defmodule Mix.Deps.Retriever do
153153
true -> status
154154
end
155155

156-
{ dep.manager(:mix).opts(opts).status(stat), mix_children }
156+
{ dep.manager(:mix).opts(opts).status(stat), children }
157157
end)
158158
end
159159

160-
defp mix_children do
161-
scms = Mix.SCM.available
162-
from = Path.absname("mix.exs")
163-
Enum.map(Mix.project[:deps] || [], &to_dep(&1, scms, from)) ++
164-
Mix.Deps.Umbrella.unfetched
165-
end
166-
167160
defp rebar_dep(Mix.Dep[opts: opts] = dep, _config) do
168161
File.cd!(opts[:dest], fn ->
169162
config = Mix.Rebar.load_config(".")

lib/mix/lib/mix/scm.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,5 @@ defmodule Mix.SCM do
125125
def register_builtin do
126126
register Mix.SCM.Git
127127
register Mix.SCM.Path
128-
register Mix.SCM.Optional
129128
end
130129
end

lib/mix/lib/mix/scm/optional.ex

Lines changed: 0 additions & 40 deletions
This file was deleted.

lib/mix/test/mix/deps_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ defmodule Mix.DepsTest do
1212
{ :invalidapp, "0.1.0", path: "deps/invalidapp" },
1313
{ :noappfile, "0.1.0", path: "deps/noappfile" },
1414
{ :uncloned, git: "https://github.com/elixir-lang/uncloned.git" },
15-
{ :optional, optional: true },
16-
{ :optional_git, optional: true, git: "https://github.com/elixir-lang/optinal.git" }
15+
{ :optional, git: "https://github.com/elixir-lang/optional.git", optional: true }
1716
]
1817
]
1918
end
@@ -36,12 +35,13 @@ defmodule Mix.DepsTest do
3635

3736
in_fixture "deps_status", fn ->
3837
deps = Mix.Deps.fetched
39-
assert length(deps) == 5
38+
assert length(deps) == 6
4039
assert Enum.find deps, &match?(Mix.Dep[app: :ok, status: { :ok, _ }], &1)
4140
assert Enum.find deps, &match?(Mix.Dep[app: :invalidvsn, status: { :invalidvsn, :ok }], &1)
4241
assert Enum.find deps, &match?(Mix.Dep[app: :invalidapp, status: { :invalidapp, _ }], &1)
4342
assert Enum.find deps, &match?(Mix.Dep[app: :noappfile, status: { :noappfile, _ }], &1)
4443
assert Enum.find deps, &match?(Mix.Dep[app: :uncloned, status: { :unavailable, _ }], &1)
44+
assert Enum.find deps, &match?(Mix.Dep[app: :optional, status: { :unavailable, _ }], &1)
4545
end
4646
after
4747
Mix.Project.pop
@@ -63,7 +63,7 @@ defmodule Mix.DepsTest do
6363

6464
in_fixture "deps_status", fn ->
6565
msg = "Mix.DepsTest.NoSCMApp did not specify a supported scm for app :ok, " <>
66-
"expected one of :git, :path, :in_umbrella or :optional"
66+
"expected one of :git, :path or :in_umbrella"
6767
assert_raise Mix.Error, msg, fn -> Mix.Deps.fetched end
6868
end
6969
after
@@ -120,7 +120,7 @@ defmodule Mix.DepsTest do
120120
app: :deps_repo,
121121
version: "0.1.0",
122122
deps: [
123-
{ :git_repo, "0.2.0", optional: true }
123+
{ :git_repo, "0.2.0", git: MixTest.Case.fixture_path("git_repo"), optional: true }
124124
]
125125
]
126126
end
@@ -169,7 +169,7 @@ defmodule Mix.DepsTest do
169169
app: :deps_repo,
170170
version: "0.1.0",
171171
deps: [
172-
{ :git_repo, "0.2.0", optional: true }
172+
{ :git_repo, "0.2.0", git: MixTest.Case.fixture_path("git_repo"), optional: true }
173173
]
174174
]
175175
end

0 commit comments

Comments
 (0)