#2272 RFE: Koji XML-RPC call to get build target to RPM macro mappings
Opened 3 years ago by dcantrell. Modified 2 years ago

It would be nice to have a way to get RPM macro values associated with a specific build target. For example, dist and scl_prefix. Since we modify package Names, Versions, and Releases based on build targets, it would be useful to have the set of modifications separated from the fully expanded names. That way downstream tools have the ability to see the "base" values vs. the expanded values in the built artifacts.


There are multiple ways that rpm macros are set in build environments.

First, it can be done by using a macros rpm that is part of the base buildroot install and places a macros file in the buildroot. Originally this was the only way. When macros are set this way, Koji cannot reasonably query them. There are simply too many possible ways for rpms in the build root to accomplish this.

Second, Koji now allows setting macro values via tag extra parameters for the build tag. Those can be queried already (they must be, because the builder needs to be able to query them). The call used is getBuildConfig.

Currently it does not look like Fedora is setting macros in this way:

>>> s = koji.ClientSession('https://koji.fedoraproject.org/kojihub')
>>> s.getBuildConfig('f32-build')['extra']
{'mock.package_manager': 'dnf', 'mock.new_chroot': 0}

So to the extent that Koji can do what you ask, it already does.

Metadata Update from @mikem:
- Custom field Size adjusted to None

3 years ago

I stand corrected. There are at least a few places where this is used in Fedora.

>>> pprint(s.getBuildConfig('epel8-infra-build')['extra'])
{'mock.new_chroot': 0,
 'mock.package_manager': 'dnf',
 'mock.yum.module_hotfixes': 1,
 'module_hotfixes': 1,
 'rpm.macro.dist': '.%{?fedora:fc%{fedora}}%{?rhel:el%{rhel}}.infra',
 'tag2distrepo.enabled': 'true',
 'tag2distrepo.keys': '47dd8ef9'}
>>> pprint(s.getBuildConfig('eln-build')['extra'])
{'mock.new_chroot': 0,
 'mock.package_manager': 'dnf',
 'rpm.macro.dist': '%{!?distprefix0:%{?distprefix}}%{expand:%{lua:for i=0,9999 '
                   'do print("%{?distprefix" .. i .."}") '
                   'end}}.eln%{eln}%{?with_bootstrap:~bootstrap}',
 'rpm.macro.eln': 100.0,
 'rpm.macro.fedora': '%nil',
 'rpm.macro.rhel': 9}
>>> pprint(s.getBuildConfig('f33-infra-build')['extra'])
{'mock.new_chroot': 0,
 'mock.package_manager': 'dnf',
 'rpm.macro.dist': '.fc33.infra',
 'tag2distrepo.enabled': 'true',
 'tag2distrepo.keys': '47dd8ef9'}
>>> pprint(s.getBuildConfig('dist-6E-epel-build')['extra'])
{'mock.new_chroot': 0, 'rpm.macro.dist': '.el6'}

If I understand the usecase you ask to have one buildroot and different targets. As Mike suggested, you can do it by simple inheritance from that buildtag with rpm macros rewritten in new tag. It can still build to the original one.

Very dumb setup:

# basic_buildtag - rpm definitions A
$ koji add-tag inherited_buildtag --parent basic_buildtag -x rpm.macro.dist=newdist
$ koji target_with_A basic_buildtag basic_buildtag 
$ koji target_with_B inherited_buildtag basic_buildtag 

I'm not trying to perform a build, I'm trying to get information about how a build was performed. This is in rpminspect, which communicates with the Koji hub to get build artifacts to run through rpminspect.

getBuildConfig looks promising, but can I get the build target name if I have the build NVR or task ID?

Correct way is to query per rpm, so basically (it needs to cover some potentially missing data, e.g. buildroot_id is not present for import rpms, etc):

import koji
s = koji.ClientSession('https://koji.fedoraproject.org/kojihub')
for rpm in s.listRPMs(buildID=1757554):
    rpminfo = s.getRPM(rpm['id'])
    brs = s.listBuildroots(buildrootID=rpminfo['buildroot_id'])
    for br in brs:
        bconfig = s.getBuildConfig(br['tag_id'], br['create_event_id'])
        print(rpminfo, bconfig)

Login to comment on this ticket.

Metadata