[Buildroot] [git commit branch/next] package/erlang: do not hard-code the Erlang Interface Version (EI_VSN)

Thomas Petazzoni thomas.petazzoni at bootlin.com
Thu Aug 10 21:07:06 UTC 2023


commit: https://git.buildroot.net/buildroot/commit/?id=b574a9606e62e79a3b7f8aa3e14199ea73fc6826
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/next

The note above the erlang version instructs to refer to another note
further down the file. However, even if it is not too difficult to find,
it is still located a bit too far away, and the reference is not very
explicit what note we should look at.

When we introduced that variable in 6c1d128844c5 (package/erlang: export
EI_VSN so other packages can use it), the rationale for hard-coding it
was "to avoid spawning a shell every time the variable is dereferenced".

However, that can get a bit confusing and hard to follow. Also, that in
fact spawns a shell only once for each rebar-packages, so the overhead
is far from being too high.

The EI_VSN is only used by rebar-package packages, is derefrenced from
the rebar-infra and not the packages themselves, and is not needed by
erlang itself (it knows its own EI_VSN), so we can de-hard-code it, and
rely on build-time detection, by looking in the appropriate file.

We have two files where we could look:
  - lib/erl_interface/vsn.mk in the erlang source tree, but it is not
    installed,
  - .../lib/erlang/releases/$(ERLANG_RELASE)/installed_application_versions
    as installed by erlang.

We use the second one, as it is cleaner, for a package, to look into
installed files, rather than to look in the source tree of another
package.

Although both the host and target erlang are the same, we still look
into the corresponding file to extract the version. This is so that it
would be easier if in the future we ever manage to rely on a
system-installed erlang that could have a EI_VSN different from the
target one.

We can't re-use the variable ERLANG_EI_VSN, because it now needs to be
$(call)-ed with a parameter. Hopefully, external packages that use it
directly rather than through the rebar infra, are not legion...

Signed-off-by: Yann E. MORIN <yann.morin.1998 at free.fr>
Cc: Will Newton <will.newton at gmail.com>
Cc: Johan Oudinet <johan.oudinet at gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
---
 package/erlang/erlang.mk | 7 ++++---
 package/pkg-rebar.mk     | 4 ++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/package/erlang/erlang.mk b/package/erlang/erlang.mk
index 593cb72937..29e2b74cbd 100644
--- a/package/erlang/erlang.mk
+++ b/package/erlang/erlang.mk
@@ -6,6 +6,7 @@
 
 # See note below when updating Erlang
 ERLANG_VERSION = 26.0.2
+ERLANG_RELEASE = $(firstword $(subst ., ,$(ERLANG_VERSION)))
 ERLANG_SITE = \
 	https://github.com/erlang/otp/releases/download/OTP-$(ERLANG_VERSION)
 ERLANG_SOURCE = otp_src_$(ERLANG_VERSION).tar.gz
@@ -26,9 +27,9 @@ ERLANG_PRE_CONFIGURE_HOOKS += ERLANG_RUN_AUTOCONF
 HOST_ERLANG_DEPENDENCIES += host-autoconf
 HOST_ERLANG_PRE_CONFIGURE_HOOKS += ERLANG_RUN_AUTOCONF
 
-# Whenever updating Erlang, this value should be updated as well, to the
-# value of EI_VSN in the file lib/erl_interface/vsn.mk
-ERLANG_EI_VSN = 5.4
+# Return the EIV (Erlang Interface Version, EI_VSN)
+# $(1): base directory, i.e. either $(HOST_DIR) or $(STAGING_DIR)/usr
+erlang_ei_vsn = `sed -r -e '/^erl_interface-(.+)/!d; s//\1/' $(1)/lib/erlang/releases/$(ERLANG_RELEASE)/installed_application_versions`
 
 # The configure checks for these functions fail incorrectly
 ERLANG_CONF_ENV = ac_cv_func_isnan=yes ac_cv_func_isinf=yes
diff --git a/package/pkg-rebar.mk b/package/pkg-rebar.mk
index e4e3f3bb6c..4b993dd970 100644
--- a/package/pkg-rebar.mk
+++ b/package/pkg-rebar.mk
@@ -32,10 +32,10 @@ REBAR_TARGET_DEPS_DIR = $(STAGING_DIR)/usr/share/rebar/deps
 #
 REBAR_HOST_DEPS_ENV = \
 	ERL_COMPILER_OPTIONS='{i, "$(REBAR_HOST_DEPS_DIR)"}' \
-	ERL_EI_LIBDIR=$(HOST_DIR)/lib/erlang/lib/erl_interface-$(ERLANG_EI_VSN)/lib
+	ERL_EI_LIBDIR=$(HOST_DIR)/lib/erlang/lib/erl_interface-$(call erlang_ei_vsn,$(HOST_DIR))/lib
 REBAR_TARGET_DEPS_ENV = \
 	ERL_COMPILER_OPTIONS='{i, "$(REBAR_TARGET_DEPS_DIR)"}' \
-	ERL_EI_LIBDIR=$(STAGING_DIR)/usr/lib/erlang/lib/erl_interface-$(ERLANG_EI_VSN)/lib
+	ERL_EI_LIBDIR=$(STAGING_DIR)/usr/lib/erlang/lib/erl_interface-$(call erlang_ei_vsn,$(STAGING_DIR)/usr)/lib
 
 ################################################################################
 # Helper functions



More information about the buildroot mailing list