Skip to content

Commit e6a8bbd

Browse files
committed
Merge pull request #4089 from tuvistavie/mix_deps_clean_build_flag
Add --build flag to deps.clean mix task. Close #4088.
2 parents 80e6942 + 91d6856 commit e6a8bbd

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

lib/mix/lib/mix/tasks/deps.clean.ex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ defmodule Mix.Tasks.Deps.Clean do
2020
is given.
2121
"""
2222

23-
@switches [unlock: :boolean, all: :boolean, only: :string, unused: :boolean]
23+
@switches [unlock: :boolean, all: :boolean, only: :string, unused: :boolean,
24+
build: :boolean]
2425

2526
@spec run(OptionParser.argv) :: :ok
2627
def run(args) do
@@ -32,20 +33,19 @@ defmodule Mix.Tasks.Deps.Clean do
3233
|> Path.join("#{opts[:only] || :*}/lib")
3334
deps = Mix.Project.deps_path
3435

35-
cond do
36-
opts[:all] ->
37-
checked_deps(build, deps) |> do_clean(build, deps)
38-
opts[:unused] ->
39-
checked_deps(build, deps) |> filter_loaded(opts) |> do_clean(build, deps)
40-
apps != [] ->
41-
do_clean(apps, build, deps)
36+
apps_to_clean = cond do
37+
opts[:all] -> checked_deps(build, deps)
38+
opts[:unused] -> checked_deps(build, deps) |> filter_loaded(opts)
39+
apps != [] -> apps
4240
true ->
4341
Mix.raise "\"mix deps.clean\" expects dependencies as arguments or " <>
4442
"a flag indicating which dependencies to clean. " <>
4543
"The --all option will clean all dependencies while " <>
4644
"the --unused option cleans unused dependencies"
4745
end
4846

47+
do_clean(apps_to_clean, build, deps, opts[:build])
48+
4949
if opts[:unlock] do
5050
Mix.Task.run "deps.unlock", args
5151
else
@@ -69,7 +69,7 @@ defmodule Mix.Tasks.Deps.Clean do
6969
Enum.reject(apps, &(&1 in load_deps))
7070
end
7171

72-
defp do_clean(apps, build, deps) do
72+
defp do_clean(apps, build, deps, build_only) do
7373
shell = Mix.shell
7474

7575
Enum.each apps, fn(app) ->
@@ -80,9 +80,11 @@ defmodule Mix.Tasks.Deps.Clean do
8080
|> Path.wildcard
8181
|> Enum.each(&File.rm_rf!/1)
8282

83-
deps
84-
|> Path.join(to_string(app))
85-
|> File.rm_rf!
83+
unless build_only do
84+
deps
85+
|> Path.join(to_string(app))
86+
|> File.rm_rf!
87+
end
8688
end
8789
end
8890
end

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,17 @@ defmodule Mix.Tasks.DepsTest do
659659
assert File.exists?("_build/dev/lib/raw_sample")
660660
end
661661
end
662+
663+
test "cleans dependencies build" do
664+
Mix.Project.push CleanDepsApp
665+
666+
in_fixture "deps_status", fn ->
667+
File.mkdir_p!("deps/raw_sample")
668+
File.mkdir_p!("_build/dev/lib/raw_sample")
669+
670+
Mix.Tasks.Deps.Clean.run ["raw_sample", "--build"]
671+
assert File.exists?("deps/raw_sample")
672+
refute File.exists?("_build/dev/lib/raw_sample")
673+
end
674+
end
662675
end

0 commit comments

Comments
 (0)