This way we will be able to pass additional macros to mock if needed. This is needed to pass copr_username and copr_projectname macros but can be useful for other use cases in the future --- backend/mockremote.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/backend/mockremote.py b/backend/mockremote.py index 75d7d2c..b266c7a 100755 --- a/backend/mockremote.py +++ b/backend/mockremote.py @@ -47,6 +47,7 @@ DEF_REPOS = [] DEF_CHROOT = None DEF_USER = 'mockbuilder' DEF_DESTDIR = os.getcwd() +DEF_MACROS = {}
class SortedOptParser(optparse.OptionParser): '''Optparser which sorts the options by opt before outputting --help''' @@ -399,7 +400,8 @@ class MockRemote(object): def __init__(self, builder=None, user=DEF_USER, timeout=DEF_TIMEOUT, destdir=DEF_DESTDIR, chroot=DEF_CHROOT, cont=False, recurse=False, repos=DEF_REPOS, callback=None, - remote_basedir=DEF_REMOTE_BASEDIR, remote_tempdir=None): + remote_basedir=DEF_REMOTE_BASEDIR, remote_tempdir=None, + macros=DEF_MACROS):
self.destdir = destdir self.chroot = chroot @@ -409,6 +411,7 @@ class MockRemote(object): self.callback = callback self.remote_basedir = remote_basedir self.remote_tempdir = remote_tempdir + self.macros = macros
if not self.callback: self.callback = DefaultCallBack()
We can possibly add different more macros as needed. Maybe users could define their own macros for specific chroots or something similar --- backend/dispatcher.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py index e2362fe..9a3c512 100644 --- a/backend/dispatcher.py +++ b/backend/dispatcher.py @@ -343,9 +343,11 @@ class Worker(multiprocessing.Process): chroot_repos = list(job.repos) chroot_repos.append(job.results + '/' + job.chroot) chrootlogfile = chroot_destdir + '/build-%s.log' % job.build_id + macros = {'copr_username': job.user_name, + 'copr_projectname': job.copr_name} mr = mockremote.MockRemote(builder=ip, timeout=job.timeout, destdir=job.destdir, chroot=job.chroot, cont=True, recurse=True, - repos=chroot_repos, + repos=chroot_repos, macros=macros, callback=mockremote.CliLogCallBack(quiet=True,logfn=chrootlogfile)) mr.build_pkgs(job.pkgs) except mockremote.MockRemoteError, e: @@ -372,4 +374,3 @@ class Worker(multiprocessing.Process): # clean up the instance if self.create: self.terminate_instance(ip) -
--- backend/mockremote.py | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/backend/mockremote.py b/backend/mockremote.py index b266c7a..587c827 100755 --- a/backend/mockremote.py +++ b/backend/mockremote.py @@ -297,6 +297,12 @@ class Builder(object): for r in self.repos: buildcmd += '-a %s ' % r
+ if self.mockremote.macros: + mock_opts = ['--define {k}={v}'.format(k=k,v=v) for k, v in + self.mockremote.macros.items()] + if mock_opts: + buildcmd += "-m '{mopts}' ".format(mopts=" ".join(mock_opts)) + buildcmd += dest
#print ' Running %s on %s' % (buildcmd, hostname)
Thanks.
I had to slightly modify 3rd commit because it does not apply cleanly anymore. I will test it today. BTW: I used this modified Mock right now on builders (just -dev instance): http://copr-fe.cloud.fedoraproject.org/coprs/msuchy/Mock/
copr-devel@lists.fedorahosted.org