[jhbuild/wip/packaging: 5/5] Add binpkg option



commit 78a7a4532c3a278d7704343dde702662b9970fc0
Author: Colin Walters <walters verbum org>
Date:   Wed May 4 17:26:25 2011 -0400

    Add binpkg option
    
    This moves us architecturally even closer to dpkg/rpm; we now have the
    option to use the "fakeroot" command to generate a binary tarball of
    the results.
    
    This step is useful for multiple reasons; I want it for implementing
    GNOME OS, and it also is useful for developers who currently do 'sudo
    make install'.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=647231

 jhbuild/commands/base.py      |    6 +++
 jhbuild/config.py             |    4 ++-
 jhbuild/defaults.jhbuildrc    |    1 +
 jhbuild/modtypes/__init__.py  |   72 ++++++++++++++++++++++++++++++++++------
 jhbuild/modtypes/autotools.py |   18 ++++------
 5 files changed, 79 insertions(+), 22 deletions(-)
---
diff --git a/jhbuild/commands/base.py b/jhbuild/commands/base.py
index 2338d98..31bd6c3 100644
--- a/jhbuild/commands/base.py
+++ b/jhbuild/commands/base.py
@@ -262,6 +262,9 @@ class cmd_build(Command):
             make_option('--min-age', metavar='TIME-SPEC',
                         action='store', dest='min_age', default=None,
                         help=_('skip modules installed less than the given time ago')),
+            make_option('', '--binpkg',
+                        action='store_true', dest='binpkg', default=None,
+                        help=_('create tarballs for the resulting builds')),
             ])
 
     def run(self, config, options, args, help=None):
@@ -335,6 +338,9 @@ class cmd_buildone(Command):
             make_option('--min-age', metavar='TIME-SPEC',
                         action='store', dest='min_age', default=None,
                         help=_('skip modules installed less than the given time ago')),
+            make_option('', '--binpkg',
+                        action='store_true', dest='binpkg', default=None,
+                        help=_('create a tarball of the resulting build')),
             ])
 
     def run(self, config, options, args, help=None):
diff --git a/jhbuild/config.py b/jhbuild/config.py
index f127515..cc58e41 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -44,7 +44,7 @@ _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'autogenargs', 'makeargs',
                 'installprog', 'repos', 'branches', 'noxvfb', 'xvfbargs',
                 'builddir_pattern', 'module_autogenargs', 'module_makeargs',
-                'interact', 'buildscript', 'nonetwork',
+                'interact', 'buildscript', 'nonetwork', 'binpkg',
                 'alwaysautogen', 'nobuild', 'makeclean', 'makecheck', 'module_makecheck',
                 'use_lib64', 'tinderbox_outputdir', 'sticky_date',
                 'tarballdir', 'pretty_print', 'svn_program', 'makedist',
@@ -528,6 +528,8 @@ class Config:
         if hasattr(options, 'dist') and (
                 options.dist and not 'dist' in self.build_targets):
             self.build_targets.append('dist')
+        if hasattr(options, 'binpkg') and options.binpkg:
+            self.binpkg = options.binpkg
         if hasattr(options, 'distcheck') and (
                 options.distcheck and not 'distcheck' in self.build_targets):
             self.build_targets.append('distcheck')
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index cebd624..2f19cf4 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -81,6 +81,7 @@ makedistcheck = False  # run make distcheck after building
 trycheckout   = False  # try to force checkout and autogen on failure
 nopoison      = False  # don't poison modules on failure
 forcecheck    = False  # run make check even when not building
+binpkg        = None   # Generate a binary tarball
 
 build_targets = ['install','test']
 
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index 3d10e47..8c4cac5 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -28,6 +28,7 @@ __all__ = [
     ]
 
 import os
+import tempfile
 import shutil
 
 from jhbuild.errors import FatalError, CommandError, BuildStateError, \
@@ -120,6 +121,15 @@ def get_branch(node, repositories, default_repo, config):
 
     return repo.branch_from_xml(name, childnode, repositories, default_repo)
 
+_host_sys = None
+def _get_host_sys():
+    """The host system is something we could eventually pass as --host for
+    builds if we were cross compiling."""
+    global _host_sys
+    if _host_sys  is None:
+        uname = os.uname()
+        _host_sys = '%s-%s-%s' % (uname[4], 'gnome', uname[0].lower())
+    return _host_sys
 
 class Package:
     type = 'base'
@@ -133,6 +143,8 @@ class Package:
         self.tags = []
         self.moduleset_name = None
         self.supports_install_destdir = False
+        
+        self._fakeroot_db = None
 
     def __repr__(self):
         return "<%s '%s'>" % (self.__class__.__name__, self.name)
@@ -146,17 +158,12 @@ class Package:
     def get_builddir(self, buildscript):
         raise NotImplementedError
 
-    def _get_destdir(self, buildscript):
+    def get_destdir(self, buildscript):
         return os.path.join(buildscript.config.top_builddir, 'root-%s' % (self.name, ))
 
-    def prepare_installroot(self, buildscript):
-        assert self.supports_install_destdir
-        """Return a directory suitable for use as e.g. DESTDIR with "make install"."""
-        destdir = self._get_destdir(buildscript)
-        if os.path.exists(destdir):
-            shutil.rmtree(destdir)
-        os.makedirs(destdir)
-        return destdir
+    def _get_fakeroot_command_prefix(self):
+        assert self._fakeroot_db is not None
+        return ['fakeroot', '-i', self._fakeroot_db, '-s', self._fakeroot_db]
 
     def _clean_la_files(self, installroot):
         assert os.path.isabs(installroot)
@@ -196,14 +203,57 @@ them into the prefix."""
             else:
                 os.rename(src_path, dest_path)
 
-    def process_install(self, buildscript, revision):
+    def _create_binpkg(self, buildscript, destdir):
+        binpkg_extension = 'tar.bz2'
+        binpkg_name = '%s.%s.tar.bz2' % (self.name, _get_host_sys())
+        binpkg_destdir = os.path.join(self.config.workdir, 'deploy')
+        if not os.path.isdir(binpkg_destdir):
+            os.mkdir(binpkg_destdir)
+        binpkg_path = os.path.join(binpkg_destdir, binpkg_name)
+        cmd = self._get_fakeroot_command_prefix()
+        destdir = self.get_destdir(buildscript)
+        cmd = cmd + ['tar', 'cjf', binpkg_path, '.']
+        buildscript.execute(cmd, cwd = destdir)
+
+    def _prepare_install(self, buildscript):
+        """Return a directory suitable for use as e.g. DESTDIR with
+"make install", as well as a command prefix."""
+        assert self.supports_install_destdir
+
+        assert self._fakeroot_db is None
+        (fd, path) = tempfile.mkstemp(prefix='jhbuild-fakeroot-')
+        os.close(fd)
+        self._fakeroot_db = path
+
+        destdir = self.get_destdir(buildscript)
+        if os.path.exists(destdir):
+            shutil.rmtree(destdir)
+        os.makedirs(destdir)
+        if buildscript.config.binpkg:
+            return (destdir, self._get_fakeroot_command_prefix())
+        return (destdir, None)
+
+    def process_install(self, buildscript, revision, cmd):
+        """Called by subclasses to implement DESTDIR= style install."""
         assert self.supports_install_destdir
-        destdir = self._get_destdir(buildscript)
+
+        buildscript.set_action(_('Installing'), self)
+        (destdir, cmd_prefix) = self._prepare_install(buildscript)
+        if cmd_prefix is not None:
+            cmd = cmd_prefix + cmd
+        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
+                    extra_env = self.extra_env)
+
         self._clean_la_files(destdir)
         buildscript.packagedb.add(self.name, revision or '', destdir)
+
+        if buildscript.config.binpkg:
+            self._create_binpkg(buildscript, destdir)
         self._process_install_files(destdir, destdir, buildscript.config.prefix)
+            
         try:
             os.rmdir(destdir)
+            os.unlink(self._fakeroot_db)
         except:
             pass
 
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index f9c576f..5e420e6 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -262,18 +262,16 @@ class AutogenModule(Package, DownloadableModule):
     do_dist.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE]
 
     def do_install(self, buildscript):
-        buildscript.set_action(_('Installing'), self)
-        destdir = self.prepare_installroot(buildscript)
+        destdir = self.get_destdir(buildscript)
         if self.makeinstallargs:
-            cmd = '%s %s DESTDIR=%s' % (os.environ.get('MAKE', 'make'),
-                                        self.makeinstallargs,
-                                        destdir)
+            cmd = [os.environ.get('MAKE', 'make'),
+                   self.makeinstallargs,
+                   'DESTDIR=' + destdir]
         else:
-            cmd = '%s install DESTDIR=%s' % (os.environ.get('MAKE', 'make'),
-                                             destdir)
-        buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
-                    extra_env = self.extra_env)
-        self.process_install(buildscript, self.get_revision())
+            cmd = [os.environ.get('MAKE', 'make'),
+                   'install',
+                   'DESTDIR=' + destdir]
+        self.process_install(buildscript, self.get_revision(), cmd)
 
     do_install.depends = [PHASE_BUILD]
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]