Skip to content

Commit

Permalink
rebar3: enable compatibility with multiple Erlang versions
Browse files Browse the repository at this point in the history
`rebar3` is designed to work with multiple versions of Erlang. However,
it can only be used with versions of Erlang that are at least as new as
the one it was built with.

To maximise compatibility with supported versions of Erlang, let's build
with `erlang@25`. We also adjust the `install` method to ensure that
we're always building with the oldest supported version of Erlang.
  • Loading branch information
carlocab committed Sep 22, 2024
1 parent 38e4ea5 commit 33d6978
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Formula/r/rebar3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@ class Rebar3 < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "3049b6e29c6f38ac6ba4bbdfbdfd65e5a08e978b739957601c02aa6791cea5a5"
end

depends_on "erlang@25" => [:build, :test]
depends_on "erlang"

def install
erlang_build_dep = deps.find { |dep| dep.build? && dep.name.match?(/^erlang@\d+$/) }&.to_formula
odie "Could not find build-time erlang!" if erlang_build_dep.blank?

# To guarantee compatibility with various erlang versions, build with an older erlang.
# We want to use `erlang@#{x-2}` where x is the major version of the `erlang` formula.
build_erlang_version = erlang_build_dep.version.major.to_i
wanted_erlang_version = Formula["erlang"].version.major.to_i - 2
if wanted_erlang_version != build_erlang_version
odie "This formula should be built with `erlang@#{wanted_erlang_version}`"
end

# Ensure we're building with versioned `erlang`
ENV.remove "PATH", "#{Formula["erlang"].opt_bin}:"
system "./bootstrap"
bin.install "rebar3"

Expand All @@ -33,6 +47,15 @@ def install
end

test do
system bin/"rebar3", "--version"
deps.each do |dep|
next unless dep.name.match?(/^erlang(@\d+)?$/)

erlang = dep.to_formula
erlang_bin = erlang.opt_bin
erlang_version = erlang.version.major
with_env(PATH: "#{erlang_bin}:#{ENV["PATH"]}") do
assert_match "OTP #{erlang_version}", shell_output("#{bin}/rebar3 --version")
end
end
end
end

0 comments on commit 33d6978

Please sign in to comment.