[rpm] Fix build with mock 1.1.33 (closes #223279)

Build rpm in tempdir and manually copy .log and .rpms to destdir.

This prevents mock from writing to nfs mounts as root.

authorRémi Cardona <remi.cardona@logilab.fr>
changeset178c7d24d874
branchdefault
phasepublic
hiddenno
parent revision#76f132305efc Use dict.get/ dict.pop instead of old style API.
child revision#f90937f86e89 [rpm] Allow building RPMs without a debian/ directory (closes #223076)
files modified by this revision
lgp/build.py
# HG changeset patch
# User Rémi Cardona <remi.cardona@logilab.fr>
# Date 1393589728 -3600
# Fri Feb 28 13:15:28 2014 +0100
# Node ID 178c7d24d8744d1ad153f6f8fe355e1aa7f2487a
# Parent 76f132305efc954e61dd4ecb238329696fedd3e7
[rpm] Fix build with mock 1.1.33 (closes #223279)

Build rpm in tempdir and manually copy .log and .rpms to destdir.

This prevents mock from writing to nfs mounts as root.

diff --git a/lgp/build.py b/lgp/build.py
@@ -182,10 +182,15 @@
1                  for distrib in  self.distributions:
2                      with tempdir(self.config.keep_tmpdir) as src_tmpdir:
3                          if self.config.rpm or distrib.startswith(('fedora', 'epel')):
4                              srpm = self.make_rpm_source_package(distrib, src_tmpdir)
5                              self.make_rpm_binary_package(distrib, srpm)
6 +                            # move logs and rpms to distdir
7 +                            rpms = glob(osp.join(src_tmpdir, '*.rpm'))
8 +                            buildlog = glob(osp.join(src_tmpdir, '*.log'))
9 +                            self.move_package_files(rpms + buildlog, self.get_distrib_dir(distrib))
10 +                            #
11                              if self.config.post_treatments:
12                                  self.run_rpm_post_treatments(distrib)
13                          else:
14                              # create a debian source package
15                              dscfile = self.make_debian_source_package(distrib, src_tmpdir)
@@ -308,10 +313,11 @@
16                  self.logger.error("please use the '--specfile' option")
17                  raise LGPException("cannot build source distribution")
18          specfile = osp.abspath(specfile)
19 
20          # change directory to build source package
21 +        # note: call os.chdir() HERE is needed in make_rpm_binary_package() below
22          os.chdir(tmpdir)
23          try:
24              cmd = ["sudo", "mock", "--buildsrpm",
25                     "--spec", specfile,
26                     "--resultdir", os.getcwd(),
@@ -329,11 +335,11 @@
27              raise LGPException("couldn't find the SRPM")
28          return srpm
29 
30      def make_rpm_binary_package(self, distrib, srpm):
31          cmd = ["sudo", "mock", "-r", distrib,
32 -               "--result", self.get_distrib_dir(distrib),
33 +               "--resultdir", os.getcwd(), # os.chdir() is called above
34                 "--rebuild", srpm]
35          try:
36              self.logger.debug("running mock command: %s ..." % " ".join(cmd))
37              check_call(cmd, stdout=sys.stdout)
38          except CalledProcessError, err: