Skip to content

Commit

Permalink
Only filter non Hex overrides from requests
Browse files Browse the repository at this point in the history
Closes #1029.
  • Loading branch information
ericmj committed May 22, 2024
1 parent 0a5c49f commit d3d2399
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lib/hex/mix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ defmodule Hex.Mix do
|> Enum.uniq()
end

defp non_hex_overridden_deps(deps) do
for(
dep <- deps,
dep.opts[:override],
dep.scm != Hex.SCM,
do: dep.app
)
|> Enum.uniq()
end

@doc """
Converts a list of dependencies to a requests to the resolver. Skips
dependencies overriding with another SCM (but include dependencies
Expand All @@ -26,7 +36,8 @@ defmodule Hex.Mix do
in the original list of dependencies as they were likely filtered out
due to options like `:only`.
"""
def deps_to_requests(all_deps, overridden) do
def deps_to_requests(all_deps) do
overridden = non_hex_overridden_deps(all_deps)
all_apps = Enum.map(all_deps, & &1.app)

hex_deps_to_requests(all_deps, all_apps, overridden) ++
Expand Down Expand Up @@ -60,18 +71,14 @@ defmodule Hex.Mix do

defp non_hex_deps_to_requests(deps, all_deps, all_apps, overridden) do
Enum.flat_map(deps, fn dep ->
if has_non_hex_deps?(dep, all_apps) do
if dep.scm != Hex.SCM and dep.deps != [] and dep.app in all_apps do
collect_non_hex_deps(dep, all_deps, all_apps, overridden)
else
[]
end
end)
end

defp has_non_hex_deps?(dep, all_apps) do
dep.scm != Hex.SCM and dep.deps != [] and dep.app in all_apps
end

defp collect_non_hex_deps(dep, all_deps, all_apps, overridden) do
sub_apps = Enum.map(dep.deps, & &1.app)
sub_deps = Enum.filter(dep.deps, &(&1.app in sub_apps))
Expand Down
2 changes: 1 addition & 1 deletion lib/hex/remote_converger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Hex.RemoteConverger do
old_lock = Mix.Dep.Lock.read()

overridden = Hex.Mix.overridden_deps(deps)
requests = Hex.Mix.deps_to_requests(deps, overridden)
requests = Hex.Mix.deps_to_requests(deps)

[
Hex.Mix.packages_from_lock(lock),
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/ecto_override/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule EctoOverride.Fixture.MixProject do
use Mix.Project

def project do
[app: :ecto, version: "0.2.1", deps: deps()]
end

defp deps do
[{:postgrex, "0.2.0", override: true}]
end
end
19 changes: 19 additions & 0 deletions test/fixtures/umbrella_override/apps/my_app1/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule UmbrellaOverride.MyApp1.Fixture.MixProject do
use Mix.Project

def project do
[
app: :my_app1,
version: "0.1.0",
build_path: "../../_build",
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
deps: deps()
]
end

defp deps do
[{:ecto_override, path: HexTest.Case.fixture_path("ecto_override")}]
end
end
20 changes: 20 additions & 0 deletions test/fixtures/umbrella_override/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule UmbrellaOverride.Fixture.MixProject do
use Mix.Project

def project do
[
apps_path: "apps",
version: "0.1.0",
deps: deps()
]
end

# Dependencies listed here are available only for this
# project and cannot be accessed from applications inside
# the apps folder.
#
# Run "mix help deps" for examples and options.
defp deps do
[]
end
end
20 changes: 20 additions & 0 deletions test/hex/mix_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ defmodule Hex.MixTaskTest do
in_tmp(fn ->
Hex.State.put(:cache_home, File.cwd!())

# Mix.shell(Mix.Shell.IO)
Mix.Task.run("deps.get")
deps_compile()
Mix.Task.run("deps")
Expand Down Expand Up @@ -1082,4 +1083,23 @@ defmodule Hex.MixTaskTest do
Umbrella.MyApp3.Fixture.MixProject
])
end

test "deps.get umbrella with path override" do
in_fixture("umbrella_override", fn ->
Code.eval_file("mix.exs")
Mix.Task.run("deps.get")

assert_received {:mix_shell, :info, ["* Getting postgrex (Hex package)"]}

assert %{
postgrex: {:hex, :postgrex, "0.2.0", _, _, _, _, _}
} = Mix.Dep.Lock.read()
end)
after
purge([
UmbrellaOverride.Fixture.MixProject,
UmbrellaOverride.MyApp1.Fixture.MixProject,
EctoOverride.Fixture.MixProject
])
end
end

0 comments on commit d3d2399

Please sign in to comment.