diff --git a/lib/hex/mix.ex b/lib/hex/mix.ex index 9f88b66d..45e9f5fc 100644 --- a/lib/hex/mix.ex +++ b/lib/hex/mix.ex @@ -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 @@ -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) ++ @@ -60,7 +71,7 @@ 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 [] @@ -68,10 +79,6 @@ defmodule Hex.Mix do 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)) diff --git a/lib/hex/remote_converger.ex b/lib/hex/remote_converger.ex index 3a300990..e8b2c2e5 100644 --- a/lib/hex/remote_converger.ex +++ b/lib/hex/remote_converger.ex @@ -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), diff --git a/test/fixtures/ecto_override/mix.exs b/test/fixtures/ecto_override/mix.exs new file mode 100644 index 00000000..fc920593 --- /dev/null +++ b/test/fixtures/ecto_override/mix.exs @@ -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 diff --git a/test/fixtures/umbrella_override/apps/my_app1/mix.exs b/test/fixtures/umbrella_override/apps/my_app1/mix.exs new file mode 100644 index 00000000..e9d189bc --- /dev/null +++ b/test/fixtures/umbrella_override/apps/my_app1/mix.exs @@ -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 diff --git a/test/fixtures/umbrella_override/mix.exs b/test/fixtures/umbrella_override/mix.exs new file mode 100644 index 00000000..ddf7540a --- /dev/null +++ b/test/fixtures/umbrella_override/mix.exs @@ -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 diff --git a/test/hex/mix_task_test.exs b/test/hex/mix_task_test.exs index 96a20328..097b52d0 100644 --- a/test/hex/mix_task_test.exs +++ b/test/hex/mix_task_test.exs @@ -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") @@ -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