Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/mix/lib/mix/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,20 @@ defmodule Mix.Project do
Mix.Lock.with_lock(build_path, fun, on_taken: on_taken)
end

@doc false
def with_deps_lock(config \\ config(), fun) do
# We wrap operations on the deps directory and on mix.lock to
# avoid write conflicts.

deps_path = deps_path(config)

on_taken = fn os_pid ->
Mix.shell().info("Waiting for lock on the deps directory (held by process #{os_pid})")
end

Mix.Lock.with_lock(deps_path, fun, on_taken: on_taken)
end

# Loads mix.exs in the current directory or loads the project from the
# mixfile cache and pushes the project onto the project stack.
defp load_project(app, post_config) do
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/lib/mix/tasks/clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ defmodule Mix.Tasks.Clean do

{opts, _, _} = OptionParser.parse(args, switches: @switches)

Mix.Project.with_build_lock(fn ->
do_run(opts)
end)
end

defp do_run(opts) do
# First, we get the tasks. After that, we clean them.
# This is to avoid a task cleaning a compiler module.
tasks =
Expand Down
8 changes: 8 additions & 0 deletions lib/mix/lib/mix/tasks/deps.clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ defmodule Mix.Tasks.Deps.Clean do
Mix.Project.get!()
{opts, apps} = OptionParser.parse!(args, strict: @switches)

Mix.Project.with_build_lock(fn ->
Mix.Project.with_deps_lock(fn ->
do_run(args, opts, apps)
end)
end)
end

defp do_run(args, opts, apps) do
build_path =
Mix.Project.build_path()
|> Path.dirname()
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/lib/mix/tasks/deps.get.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ defmodule Mix.Tasks.Deps.Get do
{opts, _, _} =
OptionParser.parse(args, switches: [only: :string, target: :string, check_locked: :boolean])

Mix.Project.with_deps_lock(fn ->
do_run(opts)
end)
end

defp do_run(opts) do
fetch_opts =
for {switch, key} <- [only: :env, target: :target, check_locked: :check_locked],
value = opts[switch],
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/lib/mix/tasks/deps.unlock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ defmodule Mix.Tasks.Deps.Unlock do
Mix.Project.get!()
{opts, apps, _} = OptionParser.parse(args, switches: @switches)

Mix.Project.with_deps_lock(fn ->
do_run(opts, apps)
end)
end

defp do_run(opts, apps) do
cond do
opts[:all] ->
Mix.Dep.Lock.write(%{})
Expand Down
6 changes: 6 additions & 0 deletions lib/mix/lib/mix/tasks/deps.update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ defmodule Mix.Tasks.Deps.Update do
{opts, rest, _} =
OptionParser.parse(args, switches: [all: :boolean, only: :string, target: :string])

Mix.Project.with_deps_lock(fn ->
do_run(opts, rest)
end)
end

defp do_run(opts, rest) do
fetch_opts =
for {switch, key} <- [only: :env, target: :target],
value = opts[switch],
Expand Down
Loading