Skip to content

Commit b982822

Browse files
author
José Valim
committed
Do not compile after deps.get and deps.update
1 parent 50820df commit b982822

File tree

10 files changed

+91
-168
lines changed

10 files changed

+91
-168
lines changed

lib/mix/lib/mix/deps.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ defmodule Mix.Deps do
295295
end
296296
end
297297

298+
@doc """
299+
Returns true if the dependency is ok.
300+
"""
301+
def ok?(Mix.Dep[status: { :ok, _ }]), do: true
302+
def ok?(Mix.Dep[]), do: false
303+
298304
@doc """
299305
Checks if a dependency is available. Available dependencies
300306
are the ones that can be loaded.

lib/mix/lib/mix/deps/fetcher.ex

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
defmodule Mix.Deps.Fetcher do
88
@moduledoc false
99

10-
import Mix.Deps, only: [format_dep: 1, check_lock: 2, out_of_date?: 1, available?: 1]
10+
import Mix.Deps, only: [format_dep: 1, check_lock: 2, out_of_date?: 1, available?: 1, ok?: 1]
1111

1212
@doc """
1313
Fetches all dependencies.
1414
"""
15-
def all(old_lock, new_lock, opts) do
16-
{ apps, _deps } = do_finalize Mix.Deps.unloaded({ [], new_lock }, &do_fetch/2), old_lock, opts
15+
def all(old_lock, new_lock) do
16+
{ apps, _deps } = do_finalize Mix.Deps.unloaded({ [], new_lock }, &do_fetch/2), old_lock
1717
apps
1818
end
1919

2020
@doc """
2121
Fetches the dependencies with the given names and their children recursively.
2222
"""
23-
def by_name(names, old_lock, new_lock, opts) do
24-
{ apps, deps } = do_finalize Mix.Deps.unloaded_by_name(names, { [], new_lock }, &do_fetch/2), old_lock, opts
23+
def by_name(names, old_lock, new_lock) do
24+
{ apps, deps } = do_finalize Mix.Deps.unloaded_by_name(names, { [], new_lock }, &do_fetch/2), old_lock
2525
Mix.Deps.loaded_by_name(names, deps) # Check all given dependencies are loaded or fail
2626
apps
2727
end
@@ -57,12 +57,11 @@ defmodule Mix.Deps.Fetcher do
5757
end
5858
end
5959

60-
defp do_finalize({ all_deps, { apps, new_lock } }, old_lock, opts) do
60+
defp do_finalize({ all_deps, { apps, new_lock } }, old_lock) do
6161
# Let's get the loaded versions of deps
6262
deps = Mix.Deps.loaded_by_name(apps, all_deps)
6363

64-
# Do not attempt to compile dependencies that are not available.
65-
# mix deps.check at the end will emit proper status in case they failed.
64+
# Do not mark dependencies that are not available
6665
deps = Enum.filter(deps, &available?/1)
6766

6867
# Note we only retrieve the parent dependencies of the updated
@@ -84,38 +83,17 @@ defmodule Mix.Deps.Fetcher do
8483
Mix.Deps.Lock.write(lock)
8584

8685
require_compilation(deps)
87-
do_compile(deps, opts)
8886
{ apps, all_deps }
8987
end
9088

9189
defp require_compilation(deps) do
92-
envs = Mix.Project.build_path
93-
|> Path.join("*/lib")
94-
|> Path.wildcard()
90+
envs = Path.wildcard("_build/*/lib")
9591

9692
lc Mix.Dep[app: app] inlist deps, env inlist envs do
9793
File.touch Path.join [env, app, ".compile"]
9894
end
9995
end
10096

101-
defp do_compile(deps, opts) do
102-
apps = Enum.map(deps, &(&1.app)) |> Enum.uniq
103-
104-
unless opts[:no_compile] do
105-
if apps != [] do
106-
args = if opts[:quiet], do: ["--quiet"|apps], else: apps
107-
Mix.Task.run "deps.compile", args
108-
end
109-
110-
unless opts[:no_deps_check] do
111-
Mix.Task.run "deps.check", ["--no-compile"]
112-
end
113-
end
114-
end
115-
116-
defp ok?(Mix.Dep[status: { :ok, _ }]), do: true
117-
defp ok?(Mix.Dep[]), do: false
118-
11997
defp with_depending(deps, all_deps) do
12098
(deps ++ do_with_depending(deps, all_deps)) |> Enum.uniq(&(&1.app))
12199
end
Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
defmodule Mix.Tasks.Deps.Check do
22
use Mix.Task
33

4-
import Mix.Deps, only: [loaded: 0, format_dep: 1, format_status: 1, check_lock: 2]
4+
import Mix.Deps, only: [loaded: 0, loaded_by_name: 1, format_dep: 1,
5+
format_status: 1, check_lock: 2, ok?: 1]
56

67
@moduledoc """
78
Checks if all dependencies are valid and if not, abort.
@@ -13,9 +14,11 @@ defmodule Mix.Tasks.Deps.Check do
1314
## Command line options
1415
1516
* `--no-compile` - do not compile dependencies
17+
* `--quiet` - do not output on compilation
1618
1719
"""
1820
def run(args) do
21+
{ opts, _, _ } = OptionParser.parse(args, switches: [quiet: :boolean])
1922
lock = Mix.Deps.Lock.read
2023
all = Enum.map loaded, &check_lock(&1, lock)
2124

@@ -24,36 +27,33 @@ defmodule Mix.Tasks.Deps.Check do
2427

2528
cond do
2629
not_ok != [] ->
27-
shell = Mix.shell
28-
shell.error "Unchecked dependencies for environment #{Mix.env}:"
29-
30-
Enum.each not_ok, fn(dep) ->
31-
shell.error "* #{format_dep(dep)}"
32-
shell.error " #{format_status dep}"
33-
end
34-
35-
raise Mix.Error, message: "Can't continue due to errors on dependencies"
36-
compile == [] or "--no-compile" in args ->
30+
show_not_ok(not_ok)
31+
compile == [] or opts[:no_compile] ->
3732
:ok
3833
true ->
39-
Mix.Task.run "deps.compile", Enum.map(compile, & &1.app)
34+
Mix.Tasks.Deps.Compile.compile(compile, opts)
35+
show_not_ok compile
36+
|> Enum.map(& &1.app)
37+
|> loaded_by_name
38+
|> Enum.filter(&(not ok?(&1)))
4039
end
4140
end
4241

43-
defp partition_deps([Mix.Dep[status: { :ok, _ }]|deps], not_ok, compile),
44-
do: partition_deps(deps, not_ok, compile)
45-
46-
defp partition_deps([Mix.Dep[status: :compile] = dep|deps], not_ok, compile),
47-
do: partition_deps(deps, not_ok, [dep|compile])
48-
49-
defp partition_deps([Mix.Dep[status: { :noappfile, _ }] = dep|deps], not_ok, compile),
50-
do: partition_deps(deps, not_ok, [dep|compile])
42+
defp partition_deps([dep|deps], not_ok, compile) do
43+
cond do
44+
ok?(dep) -> partition_deps(deps, not_ok, compile)
45+
compile?(dep) -> partition_deps(deps, not_ok, [dep|compile])
46+
true -> partition_deps(deps, [dep|not_ok], compile)
47+
end
48+
end
5149

52-
defp partition_deps([dep|deps], not_ok, compile),
53-
do: partition_deps(deps, [dep|not_ok], compile)
50+
defp partition_deps([], not_ok, compile) do
51+
{ not_ok, compile }
52+
end
5453

55-
defp partition_deps([], not_ok, compile),
56-
do: { not_ok, compile }
54+
defp compile?(Mix.Dep[status: { :noappfile, _ }]), do: true
55+
defp compile?(Mix.Dep[status: :compile]), do: true
56+
defp compile?(_), do: false
5757

5858
# If the build is per environment, we should be able to look
5959
# at all dependencies and remove the builds that no longer
@@ -79,4 +79,20 @@ defmodule Mix.Tasks.Deps.Check do
7979
end)
8080
end
8181
end
82+
83+
defp show_not_ok([]) do
84+
:ok
85+
end
86+
87+
defp show_not_ok(deps) do
88+
shell = Mix.shell
89+
shell.error "Unchecked dependencies for environment #{Mix.env}:"
90+
91+
Enum.each deps, fn(dep) ->
92+
shell.error "* #{format_dep(dep)}"
93+
shell.error " #{format_status dep}"
94+
end
95+
96+
raise Mix.Error, message: "Can't continue due to errors on dependencies"
97+
end
8298
end

lib/mix/lib/mix/tasks/deps.compile.ex

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,14 @@ defmodule Mix.Tasks.Deps.Compile do
3535

3636
case OptionParser.parse(args, switches: [quiet: :boolean]) do
3737
{ opts, [], _ } ->
38-
do_run(Enum.filter(loaded, &compilable?/1), opts)
38+
compile(Enum.filter(loaded, &compilable?/1), opts)
3939
{ opts, tail, _ } ->
40-
do_run(loaded_by_name(tail), opts)
40+
compile(loaded_by_name(tail), opts)
4141
end
4242
end
4343

44-
# All available dependencies can be compiled
45-
# except for umbrella applications.
46-
defp compilable?(Mix.Dep[manager: manager, extra: extra] = dep) do
47-
available?(dep) and (manager != :mix or !extra[:umbrella?])
48-
end
49-
50-
defp do_run(deps, run_opts) do
44+
@doc false
45+
def compile(deps, run_opts) do
5146
shell = Mix.shell
5247
config = Mix.Project.deps_config
5348

@@ -82,6 +77,12 @@ defmodule Mix.Tasks.Deps.Compile do
8277
if Enum.any?(compiled), do: Mix.Deps.Lock.touch
8378
end
8479

80+
# All available dependencies can be compiled
81+
# except for umbrella applications.
82+
defp compilable?(Mix.Dep[manager: manager, extra: extra] = dep) do
83+
available?(dep) and (manager != :mix or !extra[:umbrella?])
84+
end
85+
8586
defp check_unavailable!(app, { :unavailable, _ }) do
8687
raise Mix.Error, message: "Cannot compile dependency #{app} because " <>
8788
"it isn't available, run `mix deps.get` first"

lib/mix/lib/mix/tasks/deps.get.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,17 @@ defmodule Mix.Tasks.Deps.Get do
99
1010
## Command line options
1111
12-
* `--no-compile` - skip compilation of dependencies
13-
* `--no-deps-check` - skip dependency check
1412
* `--quiet` - do not output verbose messages
15-
1613
"""
17-
1814
def run(args) do
1915
Mix.Project.get! # Require the project to be available
2016
{ opts, rest, _ } = OptionParser.parse(args, switches: [no_compile: :boolean, quiet: :boolean])
2117

2218
apps =
2319
if rest != [] do
24-
Mix.Deps.Fetcher.by_name(rest, [], Mix.Deps.Lock.read, opts)
20+
Mix.Deps.Fetcher.by_name(rest, [], Mix.Deps.Lock.read)
2521
else
26-
Mix.Deps.Fetcher.all([], Mix.Deps.Lock.read, opts)
22+
Mix.Deps.Fetcher.all([], Mix.Deps.Lock.read)
2723
end
2824

2925
if apps == [] && !opts[:quiet] do

lib/mix/lib/mix/tasks/deps.update.ex

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ defmodule Mix.Tasks.Deps.Update do
1414
## Command line options
1515
1616
* `--all` - update all dependencies
17-
* `--no-compile` - skip compilation of dependencies
18-
* `--no-deps-check` - skip dependency check
19-
* `--quiet` - do not output verbose messages
20-
2117
"""
22-
2318
def run(args) do
2419
Mix.Project.get! # Require the project to be available
2520
{ opts, rest, _ } = OptionParser.parse(args, switches: [no_compile: :boolean, all: :boolean])
2621

2722
cond do
2823
opts[:all] ->
29-
Mix.Deps.Fetcher.all(Mix.Deps.Lock.read, [], opts)
24+
Mix.Deps.Fetcher.all(Mix.Deps.Lock.read, [])
3025
rest != [] ->
3126
{ old, new } = Dict.split(Mix.Deps.Lock.read, to_app_names(rest))
32-
Mix.Deps.Fetcher.by_name(rest, old, new, opts)
27+
Mix.Deps.Fetcher.by_name(rest, old, new)
3328
true ->
3429
raise Mix.Error, message: "mix deps.update expects dependencies as arguments or " <>
3530
"the --all option to update all dependencies"

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

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,11 @@ defmodule Mix.Tasks.DepsGitTest do
4848
Mix.Tasks.Deps.Get.run []
4949
message = "* Getting git_repo (#{fixture_path("git_repo")})"
5050
assert_received { :mix_shell, :info, [^message] }
51-
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
52-
assert_received { :mix_shell, :info, ["Compiled lib/git_repo.ex"] }
53-
assert_received { :mix_shell, :info, ["Generated git_repo.app"] }
54-
assert File.exists?("_build/dev/lib/git_repo/ebin/Elixir.GitRepo.beam")
5551
assert File.read!("mix.lock") =~ ~r/"git_repo": {:git, #{inspect fixture_path("git_repo")}, "[a-f0-9]+", \[\]}/
5652

57-
purge [GitRepo]
58-
File.touch!("_build/dev/lib/git_repo/.compile.elixir", { { 2010, 4, 17 }, { 14, 0, 0 } })
59-
Mix.Task.clear
60-
6153
Mix.Tasks.Deps.Update.run ["--all"]
6254
message = "* Updating git_repo (#{fixture_path("git_repo")})"
6355
assert_received { :mix_shell, :info, [^message] }
64-
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
65-
assert_received { :mix_shell, :info, ["Compiled lib/git_repo.ex"] }
6656
end
6757
end
6858

@@ -74,12 +64,9 @@ defmodule Mix.Tasks.DepsGitTest do
7464

7565
message = "* Getting git_repo (#{fixture_path("git_repo")})"
7666
assert_received { :mix_shell, :info, [^message] }
77-
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
78-
7967

8068
message = "* Getting deps_on_git_repo (#{fixture_path("deps_on_git_repo")})"
8169
assert_received { :mix_shell, :info, [^message] }
82-
assert_received { :mix_shell, :info, ["* Compiling deps_on_git_repo"] }
8370

8471
assert File.exists?("deps/deps_on_git_repo/mix.exs")
8572
assert File.exists?("deps/git_repo/mix.exs")
@@ -99,6 +86,7 @@ defmodule Mix.Tasks.DepsGitTest do
9986
# We can compile just fine
10087
Mix.Task.clear
10188
Mix.Tasks.Run.run ["-e", "1+2"]
89+
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
10290

10391
# Now let's add a submodules option
10492
Mix.Project.pop
@@ -141,32 +129,13 @@ defmodule Mix.Tasks.DepsGitTest do
141129
purge [GitRepo, GitRepo.Mix]
142130
end
143131

144-
test "does not recompiles dependencies if nothing changed" do
145-
Mix.Project.push GitApp
146-
147-
in_fixture "no_mixfile", fn ->
148-
Mix.Tasks.Deps.Get.run []
149-
message = "* Getting git_repo (#{fixture_path("git_repo")})"
150-
assert File.rm("_build/dev/lib/git_app/.compile.lock") == :ok
151-
assert_received { :mix_shell, :info, [^message] }
152-
153-
Mix.Tasks.Deps.Compile.run ["git_repo"]
154-
refute_received { :mix_shell, :info, ["Compiled lib/a.ex"] }
155-
refute File.exists?("_build/dev/lib/git_app/.compile.lock")
156-
end
157-
after
158-
purge [GitRepo, GitRepo.Mix]
159-
end
160-
161132
test "all up to date dependencies" do
162133
Mix.Project.push GitApp
163134

164135
in_fixture "no_mixfile", fn ->
165136
Mix.Tasks.Deps.Get.run []
166-
167137
message = "* Getting git_repo (#{fixture_path("git_repo")})"
168138
assert_received { :mix_shell, :info, [^message] }
169-
assert_received { :mix_shell, :info, ["* Compiling git_repo"] }
170139

171140
Mix.Tasks.Deps.Get.run []
172141
assert_received { :mix_shell, :info, ["All dependencies up to date"] }
@@ -175,18 +144,6 @@ defmodule Mix.Tasks.DepsGitTest do
175144
purge [GitRepo, GitRepo.Mix]
176145
end
177146

178-
test "requires dependencies before compilation" do
179-
Mix.Project.push GitApp
180-
181-
in_fixture "no_mixfile", fn ->
182-
assert_raise Mix.Error, fn ->
183-
Mix.Tasks.Compile.run []
184-
end
185-
end
186-
after
187-
purge [GitRepo, GitRepo.Mix]
188-
end
189-
190147
test "updates the lock when the repo updates" do
191148
Mix.Project.push GitApp
192149

0 commit comments

Comments
 (0)