I am playing with ideas such as #2959 or #2892 and here is a proposal how to 
achieve that (and much more). This could be the .spec file:

~~~rpm-spec
%define subpackage() %{lua:
subpackage = arg[1]

subpackage_name = subpackage:match("\\n%%package%s*([^\\n]*)")

if subpackages == nil then
  subpackages = {}
end

subpackages[subpackage_name] = subpackage

if licenses == nil then
  licenses = {}
end

licenses[subpackage_name] = subpackage:match("\\nLicense:%s*([^\\n]*)")
}

%define subpackages() %{lua:
for k in pairs(subpackages) do
  print(rpm.expand(subpackages[k]))
end
}

%define licenses() %{lua:
local license = arg[1]

for k in pairs(licenses) do
  l = licenses[k]

  if l then
    license = license .. " AND " .. l
  end
end

print(license)
}

%{subpackage:
%package foo
Summary: foo subpackage
License: BSD

%description foo
This random subpackage

%files foo
}


Summary: Demonstration package for mining licenses from subpackages
Name: license-subpackages
Version: 1
Release: 1%{?dist}
License: %{licenses:MIT}

%description
Using Lua and "metaprograming", it is possible to do magic with .spec files
such as collecting licenses from subpackages.

%{subpackages}

%changelog
* Wed Mar 13 2024 Vít Ondruch <vondr...@redhat.com>
- Initial version
~~~

The SRPM would look like this:

~~~
$ rpm -qp --qf "%{SPEC}" license-subpackages-1-1.fc41.src.rpm









Summary: Demonstration package for mining licenses from subpackages
Name: license-subpackages
Version: 1
Release: 1.fc41
License: MIT AND BSD

%description
Using Lua and "metaprograming", it is possible to do magic with .spec files
such as collecting licenses from subpackages.


%package foo
Summary: foo subpackage
License: BSD

%description foo
This random subpackage

%files foo


%changelog
* Wed Mar 13 2024 Vít Ondruch <vondr...@redhat.com>
- Initial version
~~~

I can imagine quite a lot more done with something similar. This trick could be 
used to enable/disable subpackages at will. If there were requires/provides, 
they could be adjusted for systems such as SCL. Is there some functionality or 
tag which RPM does not support (yet?), no problem to implement it in such macro.

Is this going too far?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/2969
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/repo-discussions/2...@github.com>
_______________________________________________
Rpm-maint mailing list
Rpm-maint@lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint

Reply via email to