Skip to content

Commit 5fbf793

Browse files
authored
Install Hex and Rebar per OTP release (#14477)
1 parent 670cc09 commit 5fbf793

File tree

6 files changed

+36
-21
lines changed

6 files changed

+36
-21
lines changed

lib/mix/lib/mix/local.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,32 @@ defmodule Mix.Local do
198198

199199
defp find_latest_eligible_version(entries, artifact_version) do
200200
elixir_version = Version.parse!(System.version())
201+
otp_release = System.otp_release()
201202

202203
entries
203204
|> Enum.reverse()
204-
|> find_version(artifact_version, elixir_version)
205+
|> find_version(artifact_version, elixir_version, otp_release)
205206
end
206207

207-
defp find_version(entries, artifact_version, elixir_version) do
208+
defp find_version(entries, artifact_version, elixir_version, otp_release) do
208209
entries =
209210
if artifact_version do
210211
Enum.filter(entries, &(hd(&1) == artifact_version))
211212
else
212213
entries
213214
end
214215

215-
Enum.find_value(entries, &find_by_elixir_version(&1, elixir_version))
216+
Enum.find_value(entries, &find_by_elixir_version(&1, elixir_version, otp_release))
216217
end
217218

218-
defp find_by_elixir_version([artifact_version, digest, hex_elixir_version | _], elixir_version) do
219-
if Version.compare(hex_elixir_version, elixir_version) != :gt do
220-
{hex_elixir_version, artifact_version, digest}
219+
defp find_by_elixir_version(
220+
[artifact_version, digest, hex_elixir_version, hex_otp_release | _],
221+
elixir_version,
222+
otp_release
223+
) do
224+
if Version.compare(hex_elixir_version, elixir_version) != :gt and
225+
hex_otp_release <= otp_release do
226+
{hex_elixir_version, artifact_version, digest, hex_otp_release}
221227
end
222228
end
223229
end

lib/mix/lib/mix/rebar.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ defmodule Mix.Rebar do
5353
@doc """
5454
Returns the path supposed to host the local copy of `rebar`.
5555
56-
The rebar3 installation is specific to the Elixir version,
56+
The rebar3 installation is specific to the Elixir version and OTP release,
5757
in order to force updates when new Elixir versions come out.
5858
"""
5959
def local_rebar_path(:rebar3) do
6060
[major, minor | _] = String.split(System.version(), ".")
61-
Path.join([Mix.Utils.mix_home(), "elixir", "#{major}-#{minor}", "rebar3"])
61+
62+
Path.join([
63+
Mix.Utils.mix_home(),
64+
"elixir",
65+
"#{major}-#{minor}-otp-#{System.otp_release()}",
66+
"rebar3"
67+
])
6268
end
6369

6470
@doc """

lib/mix/lib/mix/tasks/local.hex.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
defmodule Mix.Tasks.Local.Hex do
66
use Mix.Task
77

8-
@hex_list_path "/installs/hex-1.x.csv"
9-
@hex_archive_path "/installs/[ELIXIR_VERSION]/hex-[HEX_VERSION].ez"
8+
@hex_list_path "/installs/hex.csv"
9+
@hex_archive_path "/installs/[ELIXIR_VERSION]/hex-[HEX_VERSION]-otp-[OTP_RELEASE].ez"
1010

1111
@shortdoc "Installs Hex locally"
1212

@@ -72,12 +72,13 @@ defmodule Mix.Tasks.Local.Hex do
7272
defp run_install(version, argv) do
7373
hex_url = Mix.Hex.url()
7474

75-
{elixir_version, hex_version, sha512} =
75+
{elixir_version, hex_version, sha512, otp_release} =
7676
Mix.Local.find_matching_versions!("Hex", version, hex_url <> @hex_list_path)
7777

7878
url =
7979
(hex_url <> @hex_archive_path)
8080
|> String.replace("[ELIXIR_VERSION]", elixir_version)
81+
|> String.replace("[OTP_RELEASE]", otp_release)
8182
|> String.replace("[HEX_VERSION]", hex_version)
8283

8384
# Unload the Hex module we loaded earlier to avoid conflicts when Hex is updated

lib/mix/lib/mix/tasks/local.rebar.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
defmodule Mix.Tasks.Local.Rebar do
66
use Mix.Task
77

8-
@rebar3_list_url "/installs/rebar3-1.x.csv"
9-
@rebar3_escript_url "/installs/[ELIXIR_VERSION]/rebar3-[REBAR_VERSION]"
8+
@rebar3_list_url "/installs/rebar.csv"
9+
@rebar3_escript_url "/installs/[ELIXIR_VERSION]/rebar3-[REBAR_VERSION]-otp-[OTP_RELEASE]"
1010

1111
@shortdoc "Installs Rebar locally"
1212

@@ -114,13 +114,14 @@ defmodule Mix.Tasks.Local.Rebar do
114114
hex_url = Mix.Hex.url()
115115
list_url = hex_url <> list_url
116116

117-
{elixir_version, rebar_version, sha512} =
117+
{elixir_version, rebar_version, sha512, otp_release} =
118118
Mix.Local.find_matching_versions!("Rebar", _version = nil, list_url)
119119

120120
url =
121121
(hex_url <> escript_url)
122122
|> String.replace("[ELIXIR_VERSION]", elixir_version)
123123
|> String.replace("[REBAR_VERSION]", rebar_version)
124+
|> String.replace("[OTP_RELEASE]", otp_release)
124125

125126
install_from_path(manager, url, Keyword.put(opts, :sha512, sha512))
126127
end

lib/mix/test/mix/local_test.exs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ defmodule Mix.LocalTest do
88
use MixTest.Case
99

1010
@csv """
11-
1.2.5,ABC,0.9.0
12-
1.2.3,DEF,1.0.0
13-
1.2.4,GHI,1.0.0
11+
1.2.5,ABC,0.9.0,26
12+
1.2.3,DEF,1.0.0,26
13+
1.2.4,GHI,1.0.0,26
1414
"""
1515

1616
@tag :tmp_dir
1717
test "select correct versions from csv", %{tmp_dir: tmp_dir} do
1818
File.cd!(tmp_dir, fn ->
1919
File.write!("csv", @csv)
2020

21-
assert {"1.0.0", "1.2.4", "GHI"} =
21+
assert {"1.0.0", "1.2.4", "GHI", "26"} =
2222
Mix.Local.find_matching_versions!("name", nil, "csv")
2323
end)
2424
end
@@ -28,10 +28,10 @@ defmodule Mix.LocalTest do
2828
File.cd!(tmp_dir, fn ->
2929
File.write!("csv", @csv)
3030

31-
assert {"0.9.0", "1.2.5", "ABC"} =
31+
assert {"0.9.0", "1.2.5", "ABC", "26"} =
3232
Mix.Local.find_matching_versions!("name", "1.2.5", "csv")
3333

34-
assert {"1.0.0", "1.2.3", "DEF"} =
34+
assert {"1.0.0", "1.2.3", "DEF", "26"} =
3535
Mix.Local.find_matching_versions!("name", "1.2.3", "csv")
3636

3737
assert_raise Mix.Error, "Could not find a version of name matching: 1.3.0", fn ->

lib/mix/test/test_helper.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ Enum.each(
266266

267267
rebar3_source = System.get_env("REBAR3") || Path.expand("fixtures/rebar3", __DIR__)
268268
[major, minor | _] = String.split(System.version(), ".")
269-
rebar3_target = Path.join([mix, "elixir", "#{major}-#{minor}", "rebar3"])
269+
version_dir = "#{major}-#{minor}-otp-#{System.otp_release()}"
270+
rebar3_target = Path.join([mix, "elixir", version_dir, "rebar3"])
270271
File.mkdir_p!(Path.dirname(rebar3_target))
271272
File.cp!(rebar3_source, rebar3_target)
272273

0 commit comments

Comments
 (0)