Skip to content

Commit 6c813a1

Browse files
committed
Change project/rebar to manager/source in Mix.Dep
1 parent dfc4070 commit 6c813a1

File tree

2 files changed

+53
-49
lines changed

2 files changed

+53
-49
lines changed

lib/mix/lib/mix/deps.ex

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defrecord Mix.Dep, [ scm: nil, app: nil, requirement: nil, status: nil, opts: nil,
2-
project: nil, deps: [], rebar: nil ] do
2+
deps: [], source: nil, manager: nil ] do
33
@moduledoc """
44
This is a record that keeps information about your project
55
dependencies. It keeps:
@@ -9,7 +9,9 @@ defrecord Mix.Dep, [ scm: nil, app: nil, requirement: nil, status: nil, opts: ni
99
* requirements - a binary or regexp with the deps requirement;
1010
* status - the current status of dependency, check `Mix.Deps.format_status/1` for more info;
1111
* opts - the options given by the developer
12-
* project - the Mix.Project for the dependency
12+
* source - any possible configuration associated with the manager field,
13+
rebar.config for rebar or the Mix.Project for Mix
14+
* manager - the project management, possible values: :rebar / :mix / nil
1315
"""
1416
end
1517

@@ -95,7 +97,18 @@ defmodule Mix.Deps do
9597
"""
9698
def in_dependency(dep, post_config // [], fun)
9799

98-
def in_dependency(Mix.Dep[app: app, opts: opts, rebar: nil], post_config, fun) do
100+
def in_dependency(Mix.Dep[manager: :rebar, opts: opts], post_config, fun) do
101+
# Use post_config for rebar deps
102+
Mix.Project.post_config(post_config)
103+
Mix.Project.push(Mix.Rebar)
104+
try do
105+
File.cd!(opts[:dest], fn -> fun.(nil) end)
106+
after
107+
Mix.Project.pop
108+
end
109+
end
110+
111+
def in_dependency(Mix.Dep[app: app, opts: opts], post_config, fun) do
99112
env = opts[:env] || :prod
100113
old_env = Mix.env
101114

@@ -107,17 +120,6 @@ defmodule Mix.Deps do
107120
end
108121
end
109122

110-
def in_dependency(Mix.Dep[opts: opts], post_config, fun) do
111-
# Use post_config for rebar deps
112-
Mix.Project.post_config(post_config)
113-
Mix.Project.push(Mix.Rebar)
114-
try do
115-
File.cd!(opts[:dest], fn -> fun.(nil) end)
116-
after
117-
Mix.Project.pop
118-
end
119-
end
120-
121123
@doc """
122124
Formats the status of a dependency.
123125
"""
@@ -220,8 +222,8 @@ defmodule Mix.Deps do
220222
@doc """
221223
Returns all compile paths for the dependency.
222224
"""
223-
def compile_paths(Mix.Dep[app: app, opts: opts] = dep) do
224-
if mix?(dep) do
225+
def compile_paths(Mix.Dep[app: app, opts: opts, manager: manager]) do
226+
if manager == :mix do
225227
Mix.Project.in_project app, opts[:dest], fn _ ->
226228
Mix.Project.compile_paths
227229
end
@@ -233,37 +235,38 @@ defmodule Mix.Deps do
233235
@doc """
234236
Returns all load paths for the dependency.
235237
"""
236-
def load_paths(Mix.Dep[app: app, opts: opts] = dep) do
237-
cond do
238-
mix?(dep) ->
239-
paths = Mix.Project.in_project app, opts[:dest], fn _ ->
240-
Mix.Project.load_paths
241-
end
242-
Enum.uniq paths
243-
rebar?(dep) ->
244-
# Add root dir and all sub dirs with ebin/ directory
245-
[ opts[:dest] | (dep.rebar[:sub_dirs] || []) ]
246-
|> Enum.map(Path.wildcard(&1))
247-
|> List.concat
248-
|> Enum.map(fn path -> Path.join([opts[:dest], path, "ebin"]) end)
249-
|> Enum.filter(File.dir?(&1))
250-
true ->
251-
[ Path.join(opts[:dest], "ebin") ]
238+
def load_paths(Mix.Dep[manager: :mix, app: app, opts: opts]) do
239+
paths = Mix.Project.in_project app, opts[:dest], fn _ ->
240+
Mix.Project.load_paths
252241
end
242+
Enum.uniq paths
243+
end
244+
245+
def load_paths(Mix.Dep[manager: :rebar, opts: opts, source: source]) do
246+
# Add root dir and all sub dirs with ebin/ directory
247+
[ opts[:dest] | (source[:sub_dirs] || []) ]
248+
|> Enum.map(Path.wildcard(&1))
249+
|> List.concat
250+
|> Enum.map(fn path -> Path.join([opts[:dest], path, "ebin"]) end)
251+
|> Enum.filter(File.dir?(&1))
252+
end
253+
254+
def load_paths(Mix.Dep[manager: nil, opts: opts]) do
255+
[ Path.join(opts[:dest], "ebin") ]
253256
end
254257

255258
@doc """
256259
Returns true if dependency is a mix project.
257260
"""
258-
def mix?(dep) do
259-
dep.project != nil
261+
def mix?(Mix.Dep[manager: manager]) do
262+
manager == :mix
260263
end
261264

262265
@doc """
263266
Returns true if dependency is a rebar project.
264267
"""
265-
def rebar?(dep) do
266-
dep.rebar != nil
268+
def rebar?(Mix.Dep[manager: manager]) do
269+
manager == :rebar
267270
end
268271

269272
@doc """

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,34 @@ defmodule Mix.Deps.Retriever do
8989
Enum.map deps, fn dep ->
9090
dep = with_scm_and_status(dep, scms)
9191

92-
if Mix.Deps.available?(dep) and mixfile?(dep) do
93-
dep = Mix.Deps.in_dependency(dep, fn project ->
94-
with_mix_project(dep, project)
95-
end)
96-
end
92+
cond do
93+
Mix.Deps.available?(dep) and mixfile?(dep) ->
94+
Mix.Deps.in_dependency(dep, fn project ->
95+
with_mix_project(dep, project)
96+
end)
9797

98-
if Mix.Deps.available?(dep) and rebarconfig?(dep) do
99-
dep = rebar_dep(dep)
100-
end
98+
Mix.Deps.available?(dep) and rebarconfig?(dep) ->
99+
rebar_dep(dep)
101100

102-
dep
101+
true ->
102+
dep
103+
end
103104
end
104105
end
105106

106-
defp with_mix_project(Mix.Dep[project: nil] = dep, project) do
107+
defp with_mix_project(Mix.Dep[manager: nil] = dep, project) do
107108
if match?({ :noappfile, _ }, dep.status) and Mix.Project.umbrella? do
108109
dep = dep.update_opts(Keyword.put(&1, :app, false))
109110
.status({ :ok, nil })
110111
end
111-
dep.project(project)
112+
dep.manager(:mix).source(project)
112113
end
113114

114115
defp with_mix_project(dep, _project), do: dep
115116

116-
defp rebar_dep(Mix.Dep[rebar: nil, opts: opts] = dep) do
117+
defp rebar_dep(Mix.Dep[manager: nil, opts: opts] = dep) do
117118
config = Mix.Rebar.load_config(opts[:dest])
118-
dep.rebar(config)
119+
dep.manager(:rebar).source(config)
119120
end
120121

121122
defp rebar_dep(dep), do: dep

0 commit comments

Comments
 (0)