Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only filter non Hex overrides from requests #1030

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
50 changes: 50 additions & 0 deletions test/hex/mix_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ defmodule Hex.MixTaskTest do
end
end

defmodule EctoOverrideParent do
def project do
[
app: :ecto_override_parent,
version: "0.1.0",
consolidate_protocols: false,
deps: [
{:ecto_override, path: HexTest.Case.fixture_path("ecto_override")}
]
]
end
end

defp reset_code_paths(fun) do
path = :code.get_path()

Expand Down Expand Up @@ -1082,4 +1095,41 @@ defmodule Hex.MixTaskTest do
Umbrella.MyApp3.Fixture.MixProject
])
end

test "deps.get with path override" do
Mix.Project.push(EctoOverrideParent)

in_tmp(fn ->
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([
EctoOverride.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
Loading