[projects/pld-builder.new/new-builddir: 2/2] setup new build dir, each build job gets own rpmdir

glen glen at pld-linux.org
Sun Oct 21 09:56:14 CEST 2012


commit 59fa18bd02be60d6533082a62d35ab2761ffa0ca
Author: Your Name <you at example.com>
Date:   Sun Oct 21 09:51:29 2012 +0200

    setup new build dir, each build job gets own rpmdir
    
    currently still dependant on $HOME outside chroot

 PLD_Builder/install.py     | 16 +++++++---------
 PLD_Builder/request.py     | 28 +++++++++++++++++++++++++---
 PLD_Builder/rpm_builder.py | 41 ++++++++++++++++++++---------------------
 3 files changed, 52 insertions(+), 33 deletions(-)
---
diff --git a/PLD_Builder/install.py b/PLD_Builder/install.py
index 91cc889..d33f9a2 100644
--- a/PLD_Builder/install.py
+++ b/PLD_Builder/install.py
@@ -100,12 +100,11 @@ def uninstall(conflicting, b):
 
 def uninstall_self_conflict(b):
     b.log_line("checking BuildConflict-ing packages")
-    packagename = b.spec[:-5]
-    tmpdir = os.environ.get('HOME') + "/rpm/BUILD/%s/tmp" % packagename
-    f = chroot.popen("set -e; TMPDIR=%(tmpdir)s rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s rpm/packages/%(package)s/%(spec)s 2>&1" % {
-        'tmpdir': tmpdir,
+    f = chroot.popen("set -e; TMPDIR=%(tmpdir)s " \
+        "rpmbuild -bp --nobuild --short-circuit --define 'prep exit 0' %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
+        'tmpdir': b.tmpdir(),
         'rpmdefs' : b.rpmbuild_opts(),
-        'package' : packagename,
+        'topdir' : b._topdir,
         'spec': b.spec,
     })
     # java-sun >= 1.5 conflicts with soprano-2.1.67-1.src
@@ -128,13 +127,12 @@ def install_br(r, b):
         # ignore internal rpm dependencies, see lib/rpmns.c for list
         ignore_br = re.compile(r'^\s*(rpmlib|cpuinfo|getconf|uname|soname|user|group|mounted|diskspace|digest|gnupg|macro|envvar|running|sanitycheck|vcheck|signature|verify|exists|executable|readable|writable)\(.*')
 
-        packagename = b.spec[:-5]
-        tmpdir = os.environ.get('HOME') + "/rpm/BUILD/%s/tmp" % packagename
+        tmpdir = b.tmpdir()
         chroot.run("install -m 700 -d %s" % tmpdir)
-        cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s rpm/packages/%(package)s/%(spec)s 2>&1" % {
+        cmd = "set -e; TMPDIR=%(tmpdir)s rpmbuild --nobuild %(rpmdefs)s %(topdir)s/%(spec)s 2>&1" % {
             'tmpdir': tmpdir,
+            'topdir' : b._topdir,
             'rpmdefs' : b.rpmbuild_opts(),
-            'package' : packagename,
             'spec': b.spec,
         }
         f = chroot.popen(cmd)
diff --git a/PLD_Builder/request.py b/PLD_Builder/request.py
index 79bd0e5..21bc600 100644
--- a/PLD_Builder/request.py
+++ b/PLD_Builder/request.py
@@ -170,6 +170,12 @@ class Batch:
         self.b_id = attr(e, "id")
         self.depends_on = string.split(attr(e, "depends-on"))
         self.upgraded = True
+
+        self.parse_xml(e)
+
+        self._topdir = os.path.abspath(os.path.join(os.environ.get('HOME'), 'rpmbuild', self.b_id))
+
+    def parse_xml(self, e):
         for c in e.childNodes:
             if is_blank(c): continue
 
@@ -211,6 +217,21 @@ class Batch:
             else:
                 log.panic("xml: evil batch child (%s)" % c.nodeName)
 
+    def get_package_name(self):
+        if len(self.spec) <= 5:
+            return None
+        return self.spec[:-5]
+
+    def tmpdir(self):
+        """
+        return tmpdir for this batch job building
+        """
+        # it's better to have TMPDIR and BUILD dir on same partition:
+        # + /usr/bin/bzip2 -dc /home/services/builder/rpm/packages/kernel/patch-2.6.27.61.bz2
+        # patch: **** Can't rename file /tmp/B.a1b1d3/poKWwRlp to drivers/scsi/hosts.c : No such file or directory
+        path = os.path.join(self._topdir, 'BUILD', 'tmp')
+        return path
+
     def is_done(self):
         ok = 1
         for b in self.builders:
@@ -312,10 +333,11 @@ class Batch:
         """
         rpmopts = self.bconds_string() + self.kernel_string() + self.target_string() + self.defines_string()
         rpmdefs = \
-            "--define '_topdir %(echo $HOME/rpm)' " \
-            "--define '_specdir %{_topdir}/packages/%{name}' "  \
+            "--define '_topdir %s' " % self._topdir + \
+            "--define '_specdir %{_topdir}' "  \
             "--define '_sourcedir %{_specdir}' " \
-            "--define '_builddir %{_topdir}/BUILD/%{name}' "
+            "--define '_rpmdir %{_topdir}/RPMS' " \
+            "--define '_builddir %{_specdir}/BUILD' "
         return rpmdefs + rpmopts
 
     def kernel_string(self):
diff --git a/PLD_Builder/rpm_builder.py b/PLD_Builder/rpm_builder.py
index c41fbc3..e1a6cd8 100644
--- a/PLD_Builder/rpm_builder.py
+++ b/PLD_Builder/rpm_builder.py
@@ -135,7 +135,7 @@ def fetch_src(r, b):
     else:
         b.log_line("fetched %d bytes, %.1f K/s" % (bytes, bytes / 1024.0 / t))
 
-def prepare_env():
+def prepare_env(logfile = None):
     chroot.run("""
         test ! -f /proc/uptime && mount /proc 2>/dev/null
         test ! -c /dev/full && rm -f /dev/full && mknod -m 666 /dev/full c 1 7
@@ -156,16 +156,16 @@ def prepare_env():
 
         # try to limit network access for builder account
         /bin/setfacl -m u:builder:--- /etc/resolv.conf
-    """, 'root')
+    """, 'root', logfile = logfile)
 
 def build_rpm(r, b):
-    if len(b.spec) <= 5:
+    packagename = b.get_package_name()
+    if not packagename:
         # should not really get here
         b.log_line("error: No .spec not given of malformed: '%s'" % b.spec)
         res = "FAIL_INTERNAL"
         return res
 
-    packagename = b.spec[:-5]
     status.push("building %s (%s)" % (b.spec, packagename))
     b.log_line("request from: %s" % r.requester)
 
@@ -178,23 +178,18 @@ def build_rpm(r, b):
     fetch_src(r, b)
     b.log_line("installing srpm: %s" % b.src_rpm)
     res = chroot.run("""
-        # b.id %(bid)s
         set -ex;
-        install -d rpm/packages/%(package)s rpm/BUILD/%(package)s;
+        install -d %(topdir)s/{BUILD,RPMS};
         rpm -Uhv %(rpmdefs)s %(src_rpm)s;
         rm -f %(src_rpm)s;
     """ % {
-        'bid' : b.b_id,
-        'package' : packagename,
+        'topdir' : b._topdir,
         'rpmdefs' : b.rpmbuild_opts(),
         'src_rpm' : b.src_rpm
     }, logfile = b.logfile)
     b.files = []
 
-    # it's better to have TMPDIR and BUILD dir on same partition:
-    # + /usr/bin/bzip2 -dc /home/services/builder/rpm/packages/kernel/patch-2.6.27.61.bz2
-    # patch: **** Can't rename file /tmp/B.a1b1d3/poKWwRlp to drivers/scsi/hosts.c : No such file or directory
-    tmpdir = os.environ.get('HOME') + "/rpm/BUILD/%s/tmp" % packagename
+    tmpdir = b.tmpdir()
     if res:
         b.log_line("error: installing src rpm failed")
         res = "FAIL_SRPM_INSTALL"
@@ -205,11 +200,11 @@ def build_rpm(r, b):
         b.default_target(config.arch)
         # check for build arch before filling BR
         cmd = "set -ex; TMPDIR=%(tmpdir)s exec nice -n %(nice)s " \
-            "rpmbuild -bp --short-circuit --nodeps %(rpmdefs)s --define 'prep exit 0' rpm/packages/%(package)s/%(spec)s" % {
+            "rpmbuild -bp --short-circuit --nodeps %(rpmdefs)s --define 'prep exit 0' %(topdir)s/%(spec)s" % {
             'tmpdir': tmpdir,
             'nice' : config.nice,
+            'topdir' : b._topdir,
             'rpmdefs' : b.rpmbuild_opts(),
-            'package' : packagename,
             'spec': b.spec,
         }
         res = chroot.run(cmd, logfile = b.logfile)
@@ -227,12 +222,12 @@ def build_rpm(r, b):
                 if r.max_jobs > 0:
                     max_jobs = max(min(config.max_jobs, r.max_jobs), 1)
                 cmd = "set -ex; : build-id: %(r_id)s; TMPDIR=%(tmpdir)s exec nice -n %(nice)s " \
-                    "rpmbuild -bb --define '_smp_mflags -j%(max_jobs)d' %(rpmdefs)s rpm/packages/%(package)s/%(spec)s" % {
+                    "rpmbuild -bb --define '_smp_mflags -j%(max_jobs)d' %(rpmdefs)s %(topdir)s/%(spec)s" % {
                     'r_id' : r.id,
                     'tmpdir': tmpdir,
                     'nice' : config.nice,
                     'rpmdefs' : b.rpmbuild_opts(),
-                    'package' : packagename,
+                    'topdir' : b._topdir,
                     'max_jobs' : max_jobs,
                     'spec': b.spec,
                 }
@@ -257,12 +252,16 @@ def build_rpm(r, b):
 
     chroot.run("""
         set -ex;
-        rpmbuild %(rpmdefs)s --nodeps --nobuild --clean --rmspec --rmsource rpm/packages/%(package)s/%(spec)s
+        rpmbuild --nodeps --nobuild --clean --rmspec --rmsource %(rpmdefs)s %(topdir)s/%(spec)s;
         rm -rf %(tmpdir)s;
-        chmod -R u+rwX rpm/BUILD/%(package)s;
-        rm -rf rpm/BUILD/%(package)s;
-    """ %
-        {'tmpdir' : tmpdir, 'spec': b.spec, 'package' : packagename, 'rpmdefs' : b.rpmbuild_opts()}, logfile = b.logfile)
+        chmod -R u+rwX %(topdir)s/BUILD;
+        rm -rf %(topdir)s/BUILD;
+    """ % {
+        'tmpdir' : tmpdir,
+        'spec': b.spec,
+        'topdir' : b._topdir,
+        'rpmdefs' : b.rpmbuild_opts()
+    }, logfile = b.logfile)
 
     def ll(l):
         util.append_to(b.logfile, l)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-builder.new.git/commitdiff/59fa18bd02be60d6533082a62d35ab2761ffa0ca



More information about the pld-cvs-commit mailing list