summaryrefslogtreecommitdiffstats
path: root/py/mock
diff options
context:
space:
mode:
authorClark Williams <williams@redhat.com>2009-02-01 09:49:24 -0600
committerClark Williams <williams@redhat.com>2009-02-01 09:49:24 -0600
commit53ceb9d2a1b58291c74a4181da78731ad7c3a811 (patch)
treec5fa8975779ce9162fb7006384aecd0e71758d58 /py/mock
parentbc4dc3f77deed7b59dc872f634a13380b06a33d5 (diff)
parent534b3148fd64ca6b1a8eee6dbe40bdfb61706c00 (diff)
downloadmock-53ceb9d2a1b58291c74a4181da78731ad7c3a811.tar.gz
mock-53ceb9d2a1b58291c74a4181da78731ad7c3a811.tar.xz
mock-53ceb9d2a1b58291c74a4181da78731ad7c3a811.zip
Merge branch 'master' into clark
Diffstat (limited to 'py/mock')
-rw-r--r--py/mock/backend.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/py/mock/backend.py b/py/mock/backend.py
index d812743..8c0032f 100644
--- a/py/mock/backend.py
+++ b/py/mock/backend.py
@@ -444,6 +444,65 @@ class Root(object):
# tell caching we are done building
self._callHooks('postbuild')
+
+ #
+ # UNPRIVLEGED:
+ # Everything in this function runs as the build user
+ # -> except hooks. :)
+ #
+ decorate(traceLog())
+ def buildsrpm(self, spec, sources, timeout):
+ """build an srpm into binary rpms, capture log"""
+
+ # tell caching we are building
+ self._callHooks('earlyprebuild')
+
+ try:
+ self._mountall()
+ self.uidManager.becomeUser(self.chrootuid, self.chrootgid)
+ self.state("setup")
+
+ # copy spec/sources
+ shutil.copy(spec, self.makeChrootPath(self.builddir, "SPECS"))
+ os.rmdir(self.makeChrootPath(self.builddir, "SOURCES"))
+ shutil.copytree(sources, self.makeChrootPath(self.builddir, "SOURCES"))
+
+ spec = self.makeChrootPath(self.builddir, "SPECS", os.path.basename(spec))
+ chrootspec = spec.replace(self.makeChrootPath(), '') # get rid of rootdir prefix
+
+ # Completely/Permanently drop privs while running the following:
+ self.state("buildsrpm")
+ os.environ["HOME"] = self.homedir
+ self.doChroot(
+ ["bash", "--login", "-c", 'rpmbuild -bs --target %s --nodeps %s' % (self.rpmbuild_arch, chrootspec)],
+ shell=False,
+ logger=self.build_log, timeout=timeout,
+ uid=self.chrootuid,
+ gid=self.chrootgid,
+ )
+
+ rebuiltSrpmFile = glob.glob("%s/%s/SRPMS/*.src.rpm" % (self.makeChrootPath(), self.builddir))
+ if len(rebuiltSrpmFile) != 1:
+ raise mock.exception.PkgError, "Didnt find single rebuilt srpm."
+
+ rebuiltSrpmFile = rebuiltSrpmFile[0]
+
+ srpms = glob.glob(self.makeChrootPath(self.builddir) + '/SRPMS/*.rpm')
+ self.root_log.debug("Copying packages to result dir")
+ for item in srpms:
+ shutil.copy2(item, self.resultdir)
+
+ finally:
+ self.uidManager.restorePrivs()
+ self._umountall()
+
+ # tell caching we are done building
+ self._callHooks('postbuild')
+
+
+
+
+
# =============
# 'Private' API
# =============