public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/erlang] rawhide: Rewrite the subpackage Requires generator as an escript
@ 2026-11-05 22:12 Peter Lemenkov
0 siblings, 0 replies; only message in thread
From: Peter Lemenkov @ 2026-11-05 22:12 UTC (permalink / raw)
To: git-commits
A new commit has been pushed.
Repo : rpms/erlang
Branch : rawhide
Commit : 6d77723dbb8f20d1d0cab223af52e641bfc615a3
Author : Peter Lemenkov <lemenkov@gmail.com>
Date : 2026-11-05T22:52:26+01:00
Stats : +116/-139 in 3 file(s)
URL : https://src.fedoraproject.org/rpms/erlang/c/6d77723dbb8f20d1d0cab223af52e641bfc615a3?branch=rawhide
Log:
Rewrite the subpackage Requires generator as an escript
otp-find-requires.escript replaces otp-find-requires.py. It reads the
import and export tables with beam_lib instead of parsing BEAM chunks by
hand, and runs on the escript of the build tree, as the Erlang being
built is not installed yet. The build no longer needs Python.
The generated Requires are the same as those of 27.3.4.19-3 on every
subpackage (scratch build 151993601).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
diff --git a/erlang.spec b/erlang.spec
index a0a6de5..e293db3 100644
--- a/erlang.spec
+++ b/erlang.spec
@@ -68,7 +68,7 @@
Name: erlang
Version: 27.3.4.19
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: General-purpose programming language and runtime environment
License: Apache-2.0
@@ -80,11 +80,11 @@ Source6: epmd.socket
Source7: epmd@.service
Source8: epmd@.socket
# The Requires of the subpackages on each other, generated from the calls
-# of their BEAM files
-Source998: otp-find-requires.py
-BuildRequires: python3
+# of their BEAM files. Runs on the escript of the build tree, as the
+# Erlang being built is not installed yet.
+Source998: otp-find-requires.escript
%global _local_file_attrs otp
-%global __otp_requires %{__python3} %{SOURCE998} %{_libdir}/erlang/lib %{name} %{version}-%{release} %{?_isa}
+%global __otp_requires %{builddir}/otp-OTP-%{version}/bin/escript %{SOURCE998} %{_libdir}/erlang/lib %{name} %{version}-%{release} %{?_isa}
%global __otp_path ^%{_libdir}/erlang/lib/[^/]+/ebin/[^/]+\\.beam$
%global __otp_protocol multifile
# This file is intended for Fedora package maintainers only.
@@ -1771,6 +1771,10 @@ ERL_TOP=${ERL_TOP} make TARGET=${TARGET} release_tests
%changelog
+* Thu Nov 05 2026 Peter Lemenkov <lemenkov@gmail.com> - 27.3.4.19-4
+- Rewrite the subpackage Requires generator as an escript, so the build
+ no longer needs Python
+
* Tue Nov 03 2026 Peter Lemenkov <lemenkov@gmail.com> - 27.3.4.19-3
- Generate the Requires of the subpackages on each other at build time
from the calls of their BEAM files (rhbz#1297132)
diff --git a/otp-find-requires.escript b/otp-find-requires.escript
new file mode 100755
index 0000000..0359ca4
--- /dev/null
+++ b/otp-find-requires.escript
@@ -0,0 +1,107 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+
+%% SPDX-FileCopyrightText: © 2026 Peter Lemenkov
+%% SPDX-License-Identifier: MIT
+
+%% RPM dependency generator for the subpackages of Erlang/OTP itself, using
+%% the multifile protocol. Every BEAM file of a subpackage requires the
+%% subpackages of the other OTP applications whose exported functions it
+%% calls, resolved against the buildroot:
+%%
+%% erlang-APP(ISA) = VERSION-RELEASE
+%%
+%% Calls the compiler can't see (apply/3, rpc, module names computed at
+%% runtime) are deliberately not followed: OTP uses them for optional
+%% dependencies.
+%%
+%% Usage: otp-find-requires.escript LIBDIR NAME VERSION-RELEASE [ISA]
+%% otp-find-requires.escript --spec ROOT
+%% The second form prints the Requires lines for the spec file, from an
+%% unpacked tree (a buildroot, or the RPMs extracted into ROOT).
+%% LIBDIR is %{_libdir}/erlang/lib, NAME is %{name}, ISA is %{?_isa}
+
+-mode(compile).
+
+main(["--spec", Root]) ->
+ [LibDir | _] = filelib:wildcard(Root ++ "/usr/lib*/erlang/lib"),
+ Modules = index(LibDir),
+ Apps = maps:fold(
+ fun(_, Beam, Acc) ->
+ Deps = requires(Modules, Beam),
+ maps:update_with(application(Beam),
+ fun(S) -> sets:union(S, Deps) end, Deps, Acc)
+ end, #{}, Modules),
+ lists:foreach(
+ fun(App) ->
+ io:format("%package ~s~n", [App]),
+ [io:format("Requires: %{name}-~s%{?_isa} = %{version}-%{release}~n", [Dep])
+ || Dep <- lists:sort(sets:to_list(maps:get(App, Apps)))]
+ end, lists:sort(maps:keys(Apps)));
+main([LibDir, Name, EVR | Rest]) ->
+ ISA = case Rest of [I | _] -> I; [] -> "" end,
+ Root = string:trim(os:getenv("RPM_BUILD_ROOT", ""), trailing, "/"),
+ generate(index(Root ++ LibDir), Name, EVR, ISA);
+main(_) ->
+ Self = escript:script_name(),
+ io:format(standard_error,
+ "Usage: ~s LIBDIR NAME VERSION-RELEASE [ISA]~n"
+ " ~s --spec ROOT~n", [Self, Self]),
+ halt(1).
+
+generate(Modules, Name, EVR, ISA) ->
+ case io:get_line(standard_io, "") of
+ eof ->
+ ok;
+ Line ->
+ File = string:trim(Line, trailing, "\n"),
+ case filename:extension(File) of
+ ".beam" ->
+ case lists:sort(sets:to_list(requires(Modules, File))) of
+ [] ->
+ ok;
+ Deps ->
+ io:format(";~s~n", [File]),
+ [io:format("~s-~s~s = ~s~n", [Name, App, ISA, EVR]) || App <- Deps]
+ end;
+ _ ->
+ ok
+ end,
+ generate(Modules, Name, EVR, ISA)
+ end.
+
+%% Module name -> BEAM file, for every application under LIBDIR.
+index(LibDir) ->
+ maps:from_list([{list_to_atom(filename:basename(B, ".beam")), B}
+ || B <- filelib:wildcard(LibDir ++ "/*/ebin/*.beam")]).
+
+%% The application a BEAM file belongs to: lib/APP-VSN/ebin/MOD.beam.
+application(Beam) ->
+ AppVsn = filename:basename(filename:dirname(filename:dirname(Beam))),
+ string:join(lists:droplast(string:split(AppVsn, "-", all)), "-").
+
+%% The other applications whose exported functions a BEAM file calls.
+requires(Modules, File) ->
+ Own = application(File),
+ sets:from_list(
+ [App || {M, F, A} <- chunk(File, imports),
+ Beam <- [maps:get(M, Modules, undefined)],
+ Beam =/= undefined,
+ App <- [application(Beam)],
+ App =/= Own,
+ lists:member({F, A}, exports(Beam))]).
+
+exports(Beam) ->
+ case get({exports, Beam}) of
+ undefined ->
+ E = chunk(Beam, exports),
+ put({exports, Beam}, E),
+ E;
+ E ->
+ E
+ end.
+
+%% An unreadable BEAM file fails the build rather than losing its Requires.
+chunk(File, Name) ->
+ {ok, {_, [{Name, List}]}} = beam_lib:chunks(File, [Name]),
+ List.
diff --git a/otp-find-requires.py b/otp-find-requires.py
deleted file mode 100755
index a32641d..0000000
--- a/otp-find-requires.py
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/python3
-
-# SPDX-FileCopyrightText: © 2026 Peter Lemenkov
-# SPDX-License-Identifier: MIT
-
-# RPM dependency generator for the subpackages of Erlang/OTP itself, using
-# the multifile protocol. Every BEAM file of a subpackage requires the
-# subpackages of the other OTP applications whose exported functions it
-# calls, resolved against the buildroot:
-#
-# erlang-APP(ISA) = VERSION-RELEASE
-#
-# Calls the compiler can't see (apply/3, rpc, module names computed at
-# runtime) are deliberately not followed: OTP uses them for optional
-# dependencies.
-#
-# Usage: otp-find-requires.py LIBDIR NAME VERSION-RELEASE [ISA]
-# otp-find-requires.py --spec ROOT
-# The second form prints the Requires lines for the spec file, from an
-# unpacked tree (a buildroot, or the RPMs extracted into ROOT).
-# LIBDIR is %{_libdir}/erlang/lib, NAME is %{name}, ISA is %{?_isa}
-
-import functools
-import glob
-import os
-import struct
-import sys
-import zlib
-
-def chunks(filename):
- """The chunks of a BEAM file, as {name: contents}."""
- with open(filename, "rb") as f:
- data = f.read()
- if data[:2] == b'\x1f\x8b':
- data = zlib.decompress(data, 31)
- result = {}
- pos = 12
- while pos + 8 <= len(data):
- name = data[pos:pos + 4]
- size = struct.unpack(">I", data[pos + 4:pos + 8])[0]
- result[name] = data[pos + 8:pos + 8 + size]
- pos += 8 + ((size + 3) & ~3)
- return result
-
-def compact_length(data, pos):
- """An atom length in the compact term encoding of OTP 28+."""
- b = data[pos]
- if b & 0x08 == 0:
- return b >> 4, pos + 1
- if b & 0x10 == 0:
- return ((b & 0xe0) << 3) | data[pos + 1], pos + 2
- n = (b >> 5) + 2
- return int.from_bytes(data[pos + 1:pos + 1 + n], "big"), pos + 1 + n
-
-def atoms(c):
- data = c[b"AtU8"]
- count = struct.unpack(">i", data[:4])[0]
- pos = 4
- result = []
- for _ in range(abs(count)):
- if count < 0:
- size, pos = compact_length(data, pos)
- else:
- size, pos = data[pos], pos + 1
- result.append(data[pos:pos + size].decode())
- pos += size
- return result
-
-def table(c, name):
- """The entries of an import or export table, as tuples of 3 integers."""
- data = c[name]
- count = struct.unpack(">I", data[:4])[0]
- return [struct.unpack(">III", data[4 + 12 * i:16 + 12 * i]) for i in range(count)]
-
-@functools.cache
-def exports(filename):
- c = chunks(filename)
- a = atoms(c)
- return frozenset((a[f - 1], arity) for (f, arity, _) in table(c, b"ExpT"))
-
-def imports(filename):
- c = chunks(filename)
- a = atoms(c)
- return {(a[m - 1], a[f - 1], arity) for (m, f, arity) in table(c, b"ImpT")}
-
-def application(beam):
- """The application a BEAM file belongs to: lib/APP-VSN/ebin/MOD.beam."""
- return os.path.basename(os.path.dirname(os.path.dirname(beam))).rsplit("-", 1)[0]
-
-def requires(modules, filename):
- """The other applications whose exported functions a BEAM file calls."""
- own = application(filename)
- result = set()
- for (m, f, a) in imports(filename):
- beam = modules.get(m)
- if beam and application(beam) != own and (f, a) in exports(beam):
- result.add(application(beam))
- return result
-
-def index(libdir):
- return {os.path.basename(b)[:-5]: b for b in glob.glob(f"{libdir}/*/ebin/*.beam")}
-
-def spec(root):
- """Requires lines for the spec file, per application, from an installed tree."""
- libdir = glob.glob(f"{root}/usr/lib*/erlang/lib")[0]
- modules = index(libdir)
- apps = {}
- for beam in modules.values():
- apps.setdefault(application(beam), set()).update(requires(modules, beam))
- for app in sorted(apps):
- print(f"%package {app}")
- for dep in sorted(apps[app]):
- print(f"Requires: %{{name}}-{dep}%{{?_isa}} = %{{version}}-%{{release}}")
-
-def main(argv):
- if argv[:1] == ["--spec"]:
- spec(argv[1])
- return
- (libdir, name, evr), isa = argv[:3], (argv[3] if len(argv) > 3 else "")
- root = os.environ.get("RPM_BUILD_ROOT", "").rstrip("/")
- modules = index(f"{root}{libdir}")
-
- for line in sys.stdin:
- filename = line.rstrip("\n")
- if not filename.endswith(".beam"):
- continue
- deps = requires(modules, filename)
- if deps:
- print(";" + filename)
- for app in sorted(deps):
- print(f"{name}-{app}{isa} = {evr}")
-
-if __name__ == "__main__":
- main(sys.argv[1:])
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-05 22:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 22:12 [rpms/erlang] rawhide: Rewrite the subpackage Requires generator as an escript Peter Lemenkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox