Fix Mix lock files to use maps
This commit is contained in:
@@ -9,6 +9,7 @@ defmodule Mix.Dep.Lock do
|
||||
@doc """
|
||||
Returns the manifest file for dependencies.
|
||||
"""
|
||||
@spec manifest(Path.t) :: Path.t
|
||||
def manifest(manifest_path \\ Mix.Project.manifest_path) do
|
||||
Path.join(manifest_path, @manifest)
|
||||
end
|
||||
@@ -16,13 +17,16 @@ defmodule Mix.Dep.Lock do
|
||||
@doc """
|
||||
Touches the manifest timestamp unless it is an umbrella application.
|
||||
"""
|
||||
@spec touch() :: :ok
|
||||
def touch() do
|
||||
unless Mix.Project.umbrella?, do: touch(Mix.Project.manifest_path)
|
||||
_ = unless Mix.Project.umbrella?, do: touch(Mix.Project.manifest_path)
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
Touches the manifest timestamp and updates the elixir version.
|
||||
"""
|
||||
@spec touch(Path.t) :: :ok
|
||||
def touch(manifest_path) do
|
||||
File.mkdir_p!(manifest_path)
|
||||
File.write!(Path.join(manifest_path, @manifest), System.version)
|
||||
@@ -31,6 +35,7 @@ defmodule Mix.Dep.Lock do
|
||||
@doc """
|
||||
Returns the elixir version in the lock manifest.
|
||||
"""
|
||||
@spec elixir_vsn() :: binary | nil
|
||||
def elixir_vsn() do
|
||||
elixir_vsn(Mix.Project.manifest_path)
|
||||
end
|
||||
@@ -38,6 +43,7 @@ defmodule Mix.Dep.Lock do
|
||||
@doc """
|
||||
Returns the elixir version in the lock manifest in the given path.
|
||||
"""
|
||||
@spec elixir_vsn(Path.t) :: binary | nil
|
||||
def elixir_vsn(manifest_path) do
|
||||
case File.read(manifest(manifest_path)) do
|
||||
{:ok, contents} ->
|
||||
@@ -48,22 +54,28 @@ defmodule Mix.Dep.Lock do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Read the lockfile, returns a keyword list containing
|
||||
Read the lockfile, returns a map containing
|
||||
each app name and its current lock information.
|
||||
"""
|
||||
@spec read() :: map
|
||||
def read() do
|
||||
case File.read(lockfile) do
|
||||
{:ok, info} ->
|
||||
{value, _binding} = Code.eval_string(info)
|
||||
value || %{}
|
||||
case Code.eval_string(info) do
|
||||
# lock could be a keyword list
|
||||
{lock, _binding} when is_list(lock) -> Enum.into(lock, %{})
|
||||
{lock, _binding} when is_map(lock) -> lock
|
||||
{nil, _binding} -> %{}
|
||||
end
|
||||
{:error, _} ->
|
||||
%{}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Receives a keyword list and writes it as the latest lock.
|
||||
Receives a map and writes it as the latest lock.
|
||||
"""
|
||||
@spec write(map) :: :ok
|
||||
def write(map) do
|
||||
unless map == read do
|
||||
lines =
|
||||
@@ -73,6 +85,7 @@ defmodule Mix.Dep.Lock do
|
||||
File.write! lockfile, "%{" <> Enum.join(lines, ",\n ") <> "}\n"
|
||||
touch
|
||||
end
|
||||
:ok
|
||||
end
|
||||
|
||||
defp lockfile do
|
||||
|
||||
@@ -181,7 +181,7 @@ defmodule Mix.Tasks.DepsGitTest do
|
||||
[last, first|_] = get_git_repo_revs
|
||||
|
||||
in_fixture "no_mixfile", fn ->
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
|
||||
|
||||
Mix.Tasks.Deps.Get.run []
|
||||
refute File.exists?("deps/git_repo/lib/git_repo.ex")
|
||||
@@ -207,14 +207,14 @@ defmodule Mix.Tasks.DepsGitTest do
|
||||
[last, first|_] = get_git_repo_revs
|
||||
|
||||
in_fixture "no_mixfile", fn ->
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
|
||||
|
||||
Mix.Tasks.Deps.Get.run []
|
||||
refute File.exists?("deps/git_repo/lib/git_repo.ex")
|
||||
assert File.read!("mix.lock") =~ first
|
||||
|
||||
# Update the lock and now we should get an error
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), last, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), last, []}}
|
||||
assert_raise Mix.Error, fn ->
|
||||
Mix.Tasks.Deps.Check.run []
|
||||
end
|
||||
@@ -244,7 +244,7 @@ defmodule Mix.Tasks.DepsGitTest do
|
||||
|
||||
in_fixture "no_mixfile", fn ->
|
||||
# Move to the first version
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), first, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), first, []}}
|
||||
|
||||
Mix.Tasks.Deps.Get.run []
|
||||
assert File.read!("mix.lock") =~ first
|
||||
@@ -286,10 +286,10 @@ defmodule Mix.Tasks.DepsGitTest do
|
||||
[last, _, bad|_] = get_git_repo_revs
|
||||
|
||||
in_fixture "no_mixfile", fn ->
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), bad, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}}
|
||||
catch_error(Mix.Tasks.Deps.Get.run [])
|
||||
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), last, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), last, []}}
|
||||
Mix.Tasks.Deps.Get.run []
|
||||
assert File.read!("mix.lock") =~ last
|
||||
end
|
||||
@@ -302,7 +302,7 @@ defmodule Mix.Tasks.DepsGitTest do
|
||||
[last, _, bad|_] = get_git_repo_revs
|
||||
|
||||
in_fixture "no_mixfile", fn ->
|
||||
Mix.Dep.Lock.write [git_repo: {:git, fixture_path("git_repo"), bad, []}]
|
||||
Mix.Dep.Lock.write %{git_repo: {:git, fixture_path("git_repo"), bad, []}}
|
||||
catch_error(Mix.Tasks.Deps.Get.run [])
|
||||
|
||||
Mix.Tasks.Deps.Update.run ["git_repo"]
|
||||
|
||||
@@ -28,7 +28,7 @@ defmodule Mix.Tasks.DepsPathTest do
|
||||
Mix.Project.push DepsApp
|
||||
|
||||
in_fixture "deps_status", fn ->
|
||||
Mix.Dep.Lock.write [raw_repo: "abcdef"]
|
||||
Mix.Dep.Lock.write %{raw_repo: "abcdef"}
|
||||
Mix.Tasks.Run.run ["-e", "Mix.shell.info RawRepo.hello"]
|
||||
assert_received {:mix_shell, :info, ["==> raw_repo"]}
|
||||
assert_received {:mix_shell, :info, ["world"]}
|
||||
|
||||
@@ -111,7 +111,7 @@ defmodule Mix.Tasks.DepsTest do
|
||||
assert_received {:mix_shell, :info, [" locked at abcdefg"]}
|
||||
assert_received {:mix_shell, :info, [" lock mismatch: the dependency is out of date"]}
|
||||
|
||||
Mix.Dep.Lock.write [ok: {:git, "git://github.com/elixir-lang/another.git", "abcdefghi", []}]
|
||||
Mix.Dep.Lock.write %{ok: {:git, "git://github.com/elixir-lang/another.git", "abcdefghi", []}}
|
||||
Mix.Tasks.Deps.run []
|
||||
|
||||
assert_received {:mix_shell, :info, ["* ok (git://github.com/elixir-lang/ok.git)"]}
|
||||
|
||||
Reference in New Issue
Block a user