Skip to content

Commit 59b6e2e

Browse files
committed
Remove unecessary .fetch file from fetchable deps
1 parent 0b95ca4 commit 59b6e2e

File tree

5 files changed

+17
-43
lines changed

5 files changed

+17
-43
lines changed

lib/mix/lib/mix/compilers/elixir.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule Mix.Compilers.Elixir do
6868
do: [Mix.Project | stale],
6969
else: stale
7070

71-
# If the lock has changed or a local dependency was added ore removed,
71+
# If the lock has changed or a local dependency was added or removed,
7272
# we need to traverse lock/config files.
7373
deps_changed? =
7474
Mix.Utils.stale?([Mix.Project.config_mtime()], [modified]) or

lib/mix/lib/mix/dep/fetcher.ex

+11-19
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,7 @@ defmodule Mix.Dep.Fetcher do
6565
end
6666

6767
if new do
68-
# There is a race condition where if you compile deps
69-
# and then immediately update them, we would not detect
70-
# a mismatch with .mix/compile.fetch, so we go ahead and
71-
# delete all of them.
72-
Mix.Project.build_path()
73-
|> Path.dirname()
74-
|> Path.join("*/lib/#{dep.app}/.mix/compile.fetch")
75-
|> Path.wildcard(match_dot: true)
76-
|> Enum.each(&File.rm/1)
77-
78-
File.touch!(Path.join(opts[:dest], ".fetch"))
68+
mark_as_fetched([dep])
7969
dep = put_in(dep.opts[:lock], new)
8070
{dep, [app | acc], Map.put(lock, app, new)}
8171
else
@@ -123,14 +113,16 @@ defmodule Mix.Dep.Fetcher do
123113
end
124114

125115
defp mark_as_fetched(deps) do
126-
# If the dependency is fetchable, we are going to write a .fetch
127-
# file to it. Each build, regardless of the environment and location,
128-
# will compared against this .fetch file to know if the dependency
129-
# needs recompiling.
130-
_ =
131-
for %Mix.Dep{scm: scm, opts: opts} <- deps, scm.fetchable?() do
132-
File.touch!(Path.join(opts[:dest], ".fetch"))
133-
end
116+
build_path =
117+
Mix.Project.build_path()
118+
|> Path.dirname()
119+
120+
for %Mix.Dep{app: app, scm: scm} <- deps, scm.fetchable?() do
121+
build_path
122+
|> Path.join("*/lib/#{app}/.mix/compile.fetch")
123+
|> Path.wildcard(match_dot: true)
124+
|> Enum.each(&File.rm/1)
125+
end
134126

135127
:ok
136128
end

lib/mix/lib/mix/dep/loader.ex

+1-9
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,7 @@ defmodule Mix.Dep.Loader do
403403
end
404404

405405
defp recently_fetched?(%Mix.Dep{opts: opts, scm: scm}) do
406-
scm.fetchable?() &&
407-
Mix.Utils.stale?(
408-
join_stale(opts, :dest, ".fetch"),
409-
join_stale(opts, :build, ".mix/compile.fetch")
410-
)
411-
end
412-
413-
defp join_stale(opts, key, file) do
414-
[Path.join(opts[key], file)]
406+
scm.fetchable?() and not File.exists?(Path.join(opts[:build], ".mix/compile.fetch"))
415407
end
416408

417409
defp app_status(app_path, app, req) do

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ defmodule Mix.Tasks.DepsGitTest do
147147
assert_received {:mix_shell, :info, [^message]}
148148

149149
assert File.exists?("deps/deps_on_git_repo/mix.exs")
150-
assert File.rm("deps/deps_on_git_repo/.fetch") == :ok
151150
assert File.exists?("deps/git_repo/mix.exs")
152-
assert File.rm("deps/git_repo/.fetch") == :ok
153151

154152
# Compile the dependencies
155153
Mix.Tasks.Deps.Compile.run([])
154+
assert File.exists?("_build/dev/lib/deps_on_git_repo/.mix/compile.fetch")
155+
assert File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
156156

157157
# Now update children and make sure it propagates
158158
Mix.Tasks.Deps.Update.run(["git_repo"])
159-
assert File.exists?("deps/deps_on_git_repo/.fetch")
160-
assert File.exists?("deps/git_repo/.fetch")
159+
refute File.exists?("_build/dev/lib/deps_on_git_repo/.mix/compile.fetch")
160+
refute File.exists?("_build/dev/lib/git_repo/.mix/compile.fetch")
161161

162162
# Clear tasks to recompile Git repo but unload it so...
163163
purge([GitRepo])

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

-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ defmodule Mix.Tasks.DepsPathTest do
2727
end
2828
end
2929

30-
@tag apps: [:raw_sample]
31-
test "does not mark for compilation on get/update" do
32-
in_fixture("deps_status", fn ->
33-
Mix.Project.push(DepsApp)
34-
35-
Mix.Tasks.Deps.Get.run(["--all"])
36-
refute File.exists?("custom/raw_repo/.fetch")
37-
end)
38-
end
39-
4030
@tag apps: [:raw_sample]
4131
test "compiles and runs even if lock does not match" do
4232
in_fixture("deps_status", fn ->

0 commit comments

Comments
 (0)