Skip to content

Commit

Permalink
Remove unecessary .fetch file from fetchable deps
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 30, 2024
1 parent 0b95ca4 commit 59b6e2e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 43 deletions.
2 changes: 1 addition & 1 deletion lib/mix/lib/mix/compilers/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule Mix.Compilers.Elixir do
do: [Mix.Project | stale],
else: stale

# If the lock has changed or a local dependency was added ore removed,
# If the lock has changed or a local dependency was added or removed,
# we need to traverse lock/config files.
deps_changed? =
Mix.Utils.stale?([Mix.Project.config_mtime()], [modified]) or
Expand Down
30 changes: 11 additions & 19 deletions lib/mix/lib/mix/dep/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,7 @@ defmodule Mix.Dep.Fetcher do
end

if new do
# There is a race condition where if you compile deps
# and then immediately update them, we would not detect
# a mismatch with .mix/compile.fetch, so we go ahead and
# delete all of them.
Mix.Project.build_path()
|> Path.dirname()
|> Path.join("*/lib/#{dep.app}/.mix/compile.fetch")
|> Path.wildcard(match_dot: true)
|> Enum.each(&File.rm/1)

File.touch!(Path.join(opts[:dest], ".fetch"))
mark_as_fetched([dep])
dep = put_in(dep.opts[:lock], new)
{dep, [app | acc], Map.put(lock, app, new)}
else
Expand Down Expand Up @@ -123,14 +113,16 @@ defmodule Mix.Dep.Fetcher do
end

defp mark_as_fetched(deps) do
# If the dependency is fetchable, we are going to write a .fetch
# file to it. Each build, regardless of the environment and location,
# will compared against this .fetch file to know if the dependency
# needs recompiling.
_ =
for %Mix.Dep{scm: scm, opts: opts} <- deps, scm.fetchable?() do
File.touch!(Path.join(opts[:dest], ".fetch"))
end
build_path =
Mix.Project.build_path()
|> Path.dirname()

for %Mix.Dep{app: app, scm: scm} <- deps, scm.fetchable?() do
build_path
|> Path.join("*/lib/#{app}/.mix/compile.fetch")
|> Path.wildcard(match_dot: true)
|> Enum.each(&File.rm/1)
end

:ok
end
Expand Down
10 changes: 1 addition & 9 deletions lib/mix/lib/mix/dep/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,7 @@ defmodule Mix.Dep.Loader do
end

defp recently_fetched?(%Mix.Dep{opts: opts, scm: scm}) do
scm.fetchable?() &&
Mix.Utils.stale?(
join_stale(opts, :dest, ".fetch"),
join_stale(opts, :build, ".mix/compile.fetch")
)
end

defp join_stale(opts, key, file) do
[Path.join(opts[key], file)]
scm.fetchable?() and not File.exists?(Path.join(opts[:build], ".mix/compile.fetch"))
end

defp app_status(app_path, app, req) do
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/test/mix/tasks/deps.git_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ defmodule Mix.Tasks.DepsGitTest do
assert_received {:mix_shell, :info, [^message]}

assert File.exists?("deps/deps_on_git_repo/mix.exs")
assert File.rm("deps/deps_on_git_repo/.fetch") == :ok
assert File.exists?("deps/git_repo/mix.exs")
assert File.rm("deps/git_repo/.fetch") == :ok

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

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

# Clear tasks to recompile Git repo but unload it so...
purge([GitRepo])
Expand Down
10 changes: 0 additions & 10 deletions lib/mix/test/mix/tasks/deps.path_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ defmodule Mix.Tasks.DepsPathTest do
end
end

@tag apps: [:raw_sample]
test "does not mark for compilation on get/update" do
in_fixture("deps_status", fn ->
Mix.Project.push(DepsApp)

Mix.Tasks.Deps.Get.run(["--all"])
refute File.exists?("custom/raw_repo/.fetch")
end)
end

@tag apps: [:raw_sample]
test "compiles and runs even if lock does not match" do
in_fixture("deps_status", fn ->
Expand Down

0 comments on commit 59b6e2e

Please sign in to comment.