SRPM/test: add code for handling rpmbuildopts

This commit does the following things:
1: add a field to SRPM to include rpmbuildopts
2: add code to handle rpmbuildopts in expand_components
3: add small example to overlay.yaml to demonstrate usage
4: remove extra empty spaces in several files
This commit is contained in:
Ruixin Bao
2018-05-13 23:31:36 +00:00
committed by Colin Walters
parent a2fd7aa628
commit 4dea8bf94e
6 changed files with 52 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
aliases:
aliases:
- name: github
url: https://github.com/
# We support "pinned TLS"; save the CA certificate
@@ -13,7 +13,7 @@ aliases:
distgit:
prefix: fedorapkgs
branch: f23
root:
mock: fedora-23-$arch
@@ -30,6 +30,14 @@ components:
- src: github:rpm-software-management/libhif
spec: internal
- src: github:openshift/origin
spec: internal
# We also support --define option, which is going to be fed
# into rpmbuild. E.g the example below is equivalent to
# --define make_redistributable 0
defines:
make_redistributable: "0"
- src: github:shurcooL/sanitized_anchor_name
# Freeze to an arbitrary commit
tag: 11a20b799bf22a02808c862eb6ca09f7fb38f84a

View File

@@ -19,7 +19,7 @@ import os
import yaml
import copy
from .utils import fatal
from .utils import fatal, convert_key_pair_into_commands
from .task import Task
from .git import GitRemote, GitMirror
@@ -81,7 +81,7 @@ class BaseTaskResolve(Task):
def _expand_component(self, component):
for key in component:
if key not in ['src', 'spec', 'distgit', 'tag', 'branch', 'freeze', 'self-buildrequires',
'rpmwith', 'rpmwithout', 'srpmroot', 'override-version']:
'rpmwith', 'rpmwithout', 'srpmroot', 'override-version', 'defines']:
fatal("Unknown key {0} in component: {1}".format(key, component))
# 'src' and 'distgit' mappings
src = component.get('src')
@@ -95,7 +95,7 @@ class BaseTaskResolve(Task):
pass
else:
raise ValueError('Unknown spec type {0}'.format(spec))
# Canonicalize
if src is None:
component['src'] = src = 'distgit'
@@ -122,14 +122,22 @@ class BaseTaskResolve(Task):
pkgname_default = name
# TODO support pulling VCS from distgit
# tag/branch defaults
if component.get('tag') is None:
component['branch'] = component.get('branch', 'master')
# Handles rpmbuildopts section, currently only support defines,
# but it is possible for more coming in the future
if component.get('defines') is not None:
component['rpmbuildopts'] = []
key_value_pairs = component.get('defines')
defineopts = convert_key_pair_into_commands(key_value_pairs)
component['rpmbuildopts'].append(defineopts)
if spec != 'internal':
pkgname_default = self._ensure_key_or(distgit, 'name', pkgname_default)
distgit['src'] = self._ensure_key_or(distgit, 'src',
distgit['src'] = self._ensure_key_or(distgit, 'src',
self._distgit_prefix + ':' + distgit['name'])
distgit['src'] = self._expand_srckey(distgit, 'src')
@@ -143,10 +151,10 @@ class BaseTaskResolve(Task):
# rpmbuild --with and --without
self._ensure_key_or(component, 'rpmwith', [])
self._ensure_key_or(component, 'rpmwithout', [])
self._ensure_key_or(component, 'rpmbuildopts', [])
self._ensure_key_or(component, 'pkgname', pkgname_default)
def _load_overlay(self):
def _load_overlay(self):
self.srcdir = self.workdir + '/src'
self.mirror = GitMirror(self.srcdir)
self.lookaside_mirror = self.srcdir + '/lookaside'
@@ -164,14 +172,14 @@ class BaseTaskResolve(Task):
def _expand_overlay(self, fetchall=False, fetch=[],
parent_mirror=None,
override_giturl=None,
override_giturl=None,
override_gitbranch=None,
override_gitrepo_from=None,
override_gitrepo_from_rev=None):
override_gitrepo_from=None,
override_gitrepo_from_rev=None):
assert override_gitbranch is None or override_gitrepo_from is None
assert (override_gitrepo_from is None) == (override_gitrepo_from_rev is None)
expanded = copy.deepcopy(self._overlay)
found_overrides = []
for component in expanded['components']:

View File

@@ -36,7 +36,7 @@ import re
import mockbuild.util
from . import specfile
from . import specfile
from .utils import fatal, ensuredir, run_sync, rmrf
# all of the variables below are substituted by the build system
@@ -49,7 +49,7 @@ MOCKCONFDIR = os.path.join(SYSCONFDIR, "mock")
# This variable is global as it's set by `eval`ing the mock config file =(
config_opts = {}
SRPMBuild = collections.namedtuple('SRPMBuild', ['filename', 'rpmwith', 'rpmwithout'])
SRPMBuild = collections.namedtuple('SRPMBuild', ['filename', 'rpmwith', 'rpmwithout', 'rpmbuildopts'])
def log(msg):
print(msg)
@@ -251,6 +251,15 @@ class MockChain(object):
'--old-chroot', # Since we'll be running in a container
'--resultdir', resdir,
'--no-cleanup-after'])
if pkg.rpmbuildopts:
# Note: this implementation will have trouble when there
# are extra " characters defined in the build opts because
# mock currently won't be able to handle cases like e.g:
# rpmbuild-opts='--define ""key value"'
buildopts = " ".join(pkg.rpmbuildopts)
mockcmd.append('--rpmbuild-opts')
mockcmd.append(buildopts)
for rpmwith in pkg.rpmwith:
mockcmd.append('--with=' + rpmwith)
for rpmwithout in pkg.rpmwithout:

View File

@@ -187,7 +187,7 @@ class TaskBuild(Task):
newcache[distgit_name] = {'hashv0': component_hash,
'dirname': srcsnap.replace('.srcsnap','')}
needed_builds.append((component, SRPMBuild(self.snapshotdir + '/' + srcsnap + '/',
component['rpmwith'], component['rpmwithout'])))
component['rpmwith'], component['rpmwithout'], component['rpmbuildopts'])))
need_createrepo = True
# At this point we've consumed any previous partial results, so clean up the dir.

View File

@@ -32,5 +32,16 @@ class TestRpmBuildOptions(unittest.TestCase):
num_value_pairs ={ 0 : "1"}
self.assertRaises(TypeError, utils.convert_key_pair_into_commands, num_value_pairs)
def test_combine_with_other_opts(self):
# In the future, there might be case where we want to add more rpmopts
# other than define, this unit test is more of proof of expected behavior
opts = ["-ts", "--clean", "-bc",'--define "foo bar" --define "baz blar"']
output = " ".join(opts)
self.assertEqual(output, '-ts --clean -bc --define "foo bar" --define "baz blar"')
empty_opts = []
output = " ".join(empty_opts)
self.assertEqual(output, "")
if __name__ == '__main__':
unittest.main()

Binary file not shown.