Skip to content

Commit 7d4d420

Browse files
committed
Restore code paths in archive.install/escript.install
Closes #13079.
1 parent 33e1b57 commit 7d4d420

File tree

1 file changed

+34
-45
lines changed

1 file changed

+34
-45
lines changed

lib/mix/lib/mix/local/installer.ex

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,15 @@ defmodule Mix.Local.Installer do
319319
"""
320320
@spec fetch(tuple, (atom -> any), (atom -> any)) :: any
321321
def fetch(dep_spec, in_fetcher \\ &in_fetcher/1, in_package) do
322-
with_tmp_dir(fn tmp_path ->
322+
tmp_path = tmp_path()
323+
previous_env = Mix.env()
324+
deps_path = System.get_env("MIX_DEPS_PATH")
325+
code_path = :code.get_path()
326+
327+
try do
323328
File.mkdir_p!(tmp_path)
329+
System.delete_env("MIX_DEPS_PATH")
330+
Mix.env(:prod)
324331

325332
File.write!(Path.join(tmp_path, "mix.exs"), """
326333
defmodule Mix.Local.Installer.MixProject do
@@ -336,34 +343,36 @@ defmodule Mix.Local.Installer do
336343
end
337344
""")
338345

339-
with_reset_prod_env(fn ->
340-
Mix.ProjectStack.on_clean_slate(fn ->
341-
tmp_path =
342-
Mix.Project.in_project(:mix_local_installer, tmp_path, [], fn mix_exs ->
343-
in_fetcher.(mix_exs)
346+
Mix.ProjectStack.on_clean_slate(fn ->
347+
tmp_path =
348+
Mix.Project.in_project(:mix_local_installer, tmp_path, [], fn mix_exs ->
349+
in_fetcher.(mix_exs)
344350

345-
# The tmp_dir may have symlinks in it, so we properly resolve
346-
# the directory before customizing deps_path and lockfile.
347-
File.cwd!()
348-
end)
351+
# The tmp_dir may have symlinks in it, so we properly resolve
352+
# the directory before customizing deps_path and lockfile.
353+
File.cwd!()
354+
end)
349355

350-
{package_name, package_path} = package_name_path(dep_spec, tmp_path)
356+
{package_name, package_path} = package_name_path(dep_spec, tmp_path)
351357

352-
post_config = [
353-
deps_path: Path.join(tmp_path, "deps"),
354-
lockfile: Path.join(tmp_path, "mix.lock")
355-
]
358+
post_config = [
359+
deps_path: Path.join(tmp_path, "deps"),
360+
lockfile: Path.join(tmp_path, "mix.lock")
361+
]
356362

357-
Mix.Project.in_project(package_name, package_path, post_config, fn mix_exs ->
358-
in_fetcher.(mix_exs)
359-
in_package.(mix_exs)
360-
end)
363+
Mix.Project.in_project(package_name, package_path, post_config, fn mix_exs ->
364+
in_fetcher.(mix_exs)
365+
in_package.(mix_exs)
361366
end)
362367
end)
363-
end)
364-
after
365-
:code.purge(Mix.Local.Installer.Fetcher)
366-
:code.delete(Mix.Local.Installer.Fetcher)
368+
after
369+
File.rm_rf(tmp_path)
370+
Mix.env(previous_env)
371+
deps_path && System.put_env("MIX_DEPS_PATH", deps_path)
372+
:code.set_path(code_path)
373+
:code.purge(Mix.Local.Installer.Fetcher)
374+
:code.delete(Mix.Local.Installer.Fetcher)
375+
end
367376
end
368377

369378
defp package_name_path(dep_spec, tmp_path) do
@@ -388,28 +397,8 @@ defmodule Mix.Local.Installer do
388397
Mix.Task.run("deps.get", ["--only", Atom.to_string(Mix.env())])
389398
end
390399

391-
defp with_tmp_dir(fun) do
400+
defp tmp_path do
392401
unique = :crypto.strong_rand_bytes(4) |> Base.url_encode64(padding: false)
393-
tmp_path = Path.join(System.tmp_dir!(), "mix-local-installer-fetcher-" <> unique)
394-
395-
try do
396-
fun.(tmp_path)
397-
after
398-
File.rm_rf(tmp_path)
399-
end
400-
end
401-
402-
defp with_reset_prod_env(fun) do
403-
previous_env = Mix.env()
404-
deps_path = System.get_env("MIX_DEPS_PATH")
405-
406-
try do
407-
System.delete_env("MIX_DEPS_PATH")
408-
Mix.env(:prod)
409-
fun.()
410-
after
411-
Mix.env(previous_env)
412-
deps_path && System.put_env("MIX_DEPS_PATH", deps_path)
413-
end
402+
Path.join(System.tmp_dir!(), "mix-local-installer-fetcher-" <> unique)
414403
end
415404
end

0 commit comments

Comments
 (0)