Skip to content

Commit c447868

Browse files
committed
Fix Mix lock files to use maps
1 parent 681d5aa commit c447868

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

lib/mix/lib/mix/dep/lock.ex

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ defmodule Mix.Dep.Lock do
99
@doc """
1010
Returns the manifest file for dependencies.
1111
"""
12+
@spec manifest(Path.t) :: Path.t
1213
def manifest(manifest_path \\ Mix.Project.manifest_path) do
1314
Path.join(manifest_path, @manifest)
1415
end
1516

1617
@doc """
1718
Touches the manifest timestamp unless it is an umbrella application.
1819
"""
20+
@spec touch() :: :ok
1921
def touch() do
20-
unless Mix.Project.umbrella?, do: touch(Mix.Project.manifest_path)
22+
_ = unless Mix.Project.umbrella?, do: touch(Mix.Project.manifest_path)
23+
:ok
2124
end
2225

2326
@doc """
2427
Touches the manifest timestamp and updates the elixir version.
2528
"""
29+
@spec touch(Path.t) :: :ok
2630
def touch(manifest_path) do
2731
File.mkdir_p!(manifest_path)
2832
File.write!(Path.join(manifest_path, @manifest), System.version)
@@ -31,13 +35,15 @@ defmodule Mix.Dep.Lock do
3135
@doc """
3236
Returns the elixir version in the lock manifest.
3337
"""
38+
@spec elixir_vsn() :: binary | nil
3439
def elixir_vsn() do
3540
elixir_vsn(Mix.Project.manifest_path)
3641
end
3742

3843
@doc """
3944
Returns the elixir version in the lock manifest in the given path.
4045
"""
46+
@spec elixir_vsn(Path.t) :: binary | nil
4147
def elixir_vsn(manifest_path) do
4248
case File.read(manifest(manifest_path)) do
4349
{:ok, contents} ->
@@ -48,22 +54,28 @@ defmodule Mix.Dep.Lock do
4854
end
4955

5056
@doc """
51-
Read the lockfile, returns a keyword list containing
57+
Read the lockfile, returns a map containing
5258
each app name and its current lock information.
5359
"""
60+
@spec read() :: map
5461
def read() do
5562
case File.read(lockfile) do
5663
{:ok, info} ->
57-
{value, _binding} = Code.eval_string(info)
58-
value || %{}
64+
case Code.eval_string(info) do
65+
# lock could be a keyword list
66+
{lock, _binding} when is_list(lock) -> Enum.into(lock, %{})
67+
{lock, _binding} when is_map(lock) -> lock
68+
{nil, _binding} -> %{}
69+
end
5970
{:error, _} ->
6071
%{}
6172
end
6273
end
6374

6475
@doc """
65-
Receives a keyword list and writes it as the latest lock.
76+
Receives a map and writes it as the latest lock.
6677
"""
78+
@spec write(map) :: :ok
6779
def write(map) do
6880
unless map == read do
6981
lines =
@@ -73,6 +85,7 @@ defmodule Mix.Dep.Lock do
7385
File.write! lockfile, "%{" <> Enum.join(lines, ",\n ") <> "}\n"
7486
touch
7587
end
88+
:ok
7689
end
7790

7891
defp lockfile do

lib/mix/test/mix/tasks/deps.git_test.exs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ defmodule Mix.Tasks.DepsGitTest do
181181
[last, first|_] = get_git_repo_revs
182182

183183
in_fixture "no_mixfile", fn ->
184-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
184+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
185185

186186
Mix.Tasks.Deps.Get.run []
187187
refute File.exists?("deps/git_repo/lib/git_repo.ex")
@@ -207,14 +207,14 @@ defmodule Mix.Tasks.DepsGitTest do
207207
[last, first|_] = get_git_repo_revs
208208

209209
in_fixture "no_mixfile", fn ->
210-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
210+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
211211

212212
Mix.Tasks.Deps.Get.run []
213213
refute File.exists?("deps/git_repo/lib/git_repo.ex")
214214
assert File.read!("mix.lock") =~ first
215215

216216
# Update the lock and now we should get an error
217-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), last, []}]
217+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), last, []}}
218218
assert_raise Mix.Error, fn ->
219219
Mix.Tasks.Deps.Check.run []
220220
end
@@ -244,7 +244,7 @@ defmodule Mix.Tasks.DepsGitTest do
244244

245245
in_fixture "no_mixfile", fn ->
246246
# Move to the first version
247-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
247+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
248248

249249
Mix.Tasks.Deps.Get.run []
250250
assert File.read!("mix.lock") =~ first
@@ -286,10 +286,10 @@ defmodule Mix.Tasks.DepsGitTest do
286286
[last, _, bad|_] = get_git_repo_revs
287287

288288
in_fixture "no_mixfile", fn ->
289-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), bad, []}]
289+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}}
290290
catch_error(Mix.Tasks.Deps.Get.run [])
291291

292-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), last, []}]
292+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), last, []}}
293293
Mix.Tasks.Deps.Get.run []
294294
assert File.read!("mix.lock") =~ last
295295
end
@@ -302,7 +302,7 @@ defmodule Mix.Tasks.DepsGitTest do
302302
[last, _, bad|_] = get_git_repo_revs
303303

304304
in_fixture "no_mixfile", fn ->
305-
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), bad, []}]
305+
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}}
306306
catch_error(Mix.Tasks.Deps.Get.run [])
307307

308308
Mix.Tasks.Deps.Update.run ["git_repo"]

lib/mix/test/mix/tasks/deps.path_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Mix.Tasks.DepsPathTest do
2828
Mix.Project.push DepsApp
2929

3030
in_fixture "deps_status", fn ->
31-
Mix.Dep.Lock.write [raw_repo: "abcdef"]
31+
Mix.Dep.Lock.write %{raw_repo: "abcdef"}
3232
Mix.Tasks.Run.run ["-e", "Mix.shell.info RawRepo.hello"]
3333
assert_received {:mix_shell, :info, ["==> raw_repo"]}
3434
assert_received {:mix_shell, :info, ["world"]}

lib/mix/test/mix/tasks/deps_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Mix.Tasks.DepsTest do
111111
assert_received {:mix_shell, :info, [" locked at abcdefg"]}
112112
assert_received {:mix_shell, :info, [" lock mismatch: the dependency is out of date"]}
113113

114-
Mix.Dep.Lock.write [ok: {:git, "git://github.com/elixir-lang/another.git", "abcdefghi", []}]
114+
Mix.Dep.Lock.write %{ok: {:git, "git://github.com/elixir-lang/another.git", "abcdefghi", []}}
115115
Mix.Tasks.Deps.run []
116116

117117
assert_received {:mix_shell, :info, ["* ok (git://github.com/elixir-lang/ok.git)"]}

0 commit comments

Comments
 (0)