rpm-software-management / rpm

The RPM package manager
http://rpm.org
Other
504 stars 364 forks source link

[RFE] Autogenerate source archive decompression dependencies #1396

Open voxik opened 4 years ago

voxik commented 4 years ago

I am experimenting with something like this:

$ git diff
diff --git a/rubygem-abrt.spec b/rubygem-abrt.spec
index 22ac9aa..79e9a53 100644
--- a/rubygem-abrt.spec
+++ b/rubygem-abrt.spec
@@ -30,6 +30,25 @@ BuildArch: noarch
 %description doc
 Documentation for %{name}.

+%global __spec_buildrequires_pre %{expand: \
+%{?__spec_buildrequires_pre} \
+echo "%{lua:
+do
+  local compressors = {
+    gz = "__gzip",
+    xz = "__xz",
+    gem = "__gem",
+  }
+  for i, p in ipairs(sources) do
+    local suffix = compressors[rpm.expand("%{suffix:"..p.."}")]
+    print(rpm.expand("%{"..suffix.."}\\n"))
+  end
+end
+}"
+}
+
+%generate_buildrequires
+
 %prep
 %setup -q -n %{gem_name}-%{version} -b 1

The idea is, that since we have dynamic build dependencies, we could do better and generate dependencies on the archive tools, used to expand the sources by setup macro. This in turn would allow to have:

  1. Better defined SRPM dependencies, because the tools used to expand the SRPM certainly have to be specified somewhere.
  2. Smaller buildroot, because not every tool had to be installed, when it is not used.

Of course this is very naive proof of concept. To make this more useful, it would be helpful if RPM provided list of supported archivers together with access to rpmFileIsCompressed which knows how to detect the compression tool already. Or possibly if the %sources macro provided more then just list of files.

voxik commented 4 years ago

This request is inspired by this ML thread:

https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/CDU375QSFDEKX3HRNQPBAGEFJORVE2TK

pmatilai commented 4 years ago

Yup, it's not a new idea, we've even had a ticket for it but that's probably gotten lost in the jump to GH.

I had a PoC that threw sources at %{uncompress:...} and grabbed the result up to the first space, which kinda works but of course has the limitation of not supporting executables with whitespace in the name (dunno if we care...), but also has the issue of whining unnecessarily on spec parse (non-build) where sources are not present. It probably needs a bit of API work to make the required stuff meaningfully available. Incidentally I was just looking around this neighborhood last week or so when adding Lua bindings for rpmio files: rpm doesn't currently know how to convert a result from rpmFileIsCompressed() into a Fopen() mode for that compression type...