[jhbuild] Re-run autogen.sh if autogen arguments change (GNOME bug 683374)



commit cc2bcbe0c0cb85538866fa1c87af7ddb94fd9c48
Author: Craig Keogh <cskeogh adam com au>
Date:   Wed Sep 5 15:35:17 2012 +0930

    Re-run autogen.sh if autogen arguments change (GNOME bug 683374)

 jhbuild/modtypes/__init__.py  |    5 +-
 jhbuild/modtypes/autotools.py |  128 ++++++++++++++++++++++++-----------------
 jhbuild/utils/packagedb.py    |   25 +++++++-
 3 files changed, 101 insertions(+), 57 deletions(-)
---
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index 6e26bed..ff96999 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -181,6 +181,7 @@ class Package:
         self.moduleset_name = None
         self.supports_install_destdir = False
         self.supports_parallel_build = True
+        self.configure_cmd = None
 
     def __repr__(self):
         return "<%s '%s'>" % (self.__class__.__name__, self.name)
@@ -358,7 +359,9 @@ them into the prefix."""
                         logging.warn(_("Failed to delete no longer installed file %(file)r: %(msg)s") % { 'file': path,
                                                                                                           'msg': error_string})
 
-            buildscript.moduleset.packagedb.add(self.name, revision or '', absolute_new_contents)
+            buildscript.moduleset.packagedb.add(self.name, revision or '',
+                                                absolute_new_contents,
+                                                self.configure_cmd)
 
     def get_revision(self):
         return self.branch.tree_id()
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index e7f794d..00e178e 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -23,6 +23,10 @@ __metaclass__ = type
 import os
 import re
 import stat
+try:
+    import hashlib
+except ImportError:
+    import md5 as hashlib
 
 from jhbuild.errors import FatalError, BuildStateError, CommandError
 from jhbuild.modtypes import \
@@ -89,6 +93,65 @@ class AutogenModule(MakeModule, DownloadableModule):
             return False
         return potential_stbuf.st_mtime > other_stbuf.st_mtime
 
+    def _get_configure_cmd(self, buildscript):
+        if self.configure_cmd is not None:
+            return self.configure_cmd
+        if self.autogen_template:
+            template = self.autogen_template
+        else:
+            template = ("%(srcdir)s/%(autogen-sh)s --prefix %(prefix)s"
+                        " --libdir %(libdir)s %(autogenargs)s ")
+
+        autogenargs = self.autogenargs + ' ' + self.config.module_autogenargs.get(
+                self.name, self.config.autogenargs)
+
+        vars = {'prefix': buildscript.config.prefix,
+                'autogen-sh': self.autogen_sh,
+                'autogenargs': autogenargs}
+
+        if buildscript.config.buildroot and self.supports_non_srcdir_builds:
+            vars['srcdir'] = self.get_srcdir(buildscript)
+        else:
+            vars['srcdir'] = '.'
+
+        if buildscript.config.use_lib64:
+            vars['libdir'] = "'${exec_prefix}/lib64'"
+        else:
+            vars['libdir'] = "'${exec_prefix}/lib'"
+
+        cmd = self.static_analyzer_pre_cmd(buildscript) + template % vars
+
+        if self.autogen_sh == 'autoreconf':
+            cmd = cmd.replace('autoreconf', 'configure')
+            cmd = cmd.replace('--enable-maintainer-mode', '')
+
+        # Fix up the arguments for special cases:
+        #   tarballs: remove --enable-maintainer-mode to avoid breaking build
+        #   tarballs: remove '-- ' to avoid breaking build (GStreamer weirdness)
+        #   non-tarballs: place --prefix and --libdir after '-- ', if present
+        if self.autogen_sh == 'configure':
+            cmd = cmd.replace('--enable-maintainer-mode', '')
+
+            # Also, don't pass '--', which gstreamer attempts to do, since
+            # it is royally broken.
+            cmd = cmd.replace('-- ', '')
+        else:
+            # place --prefix and --libdir arguments after '-- '
+            # (GStreamer weirdness)
+            if autogenargs.find('-- ') != -1:
+                p = re.compile('(.*)(--prefix %s )((?:--libdir %s )?)(.*)-- ' %
+                       (buildscript.config.prefix, "'\${exec_prefix}/lib64'"))
+                cmd = p.sub(r'\1\4-- \2\3', cmd)
+
+        # If there is no --exec-prefix in the constructed autogen command, we
+        # can safely assume it will be the same as {prefix} and substitute it
+        # right now, so the printed command can be copy/pasted afterwards.
+        # (GNOME #580272)
+        if not '--exec-prefix' in template:
+            cmd = cmd.replace('${exec_prefix}', buildscript.config.prefix)
+        self.configure_cmd = cmd
+        return cmd
+
     def skip_configure(self, buildscript, last_phase):
         # skip if manually instructed to do so
         if self.skip_autogen is True:
@@ -105,6 +168,18 @@ class AutogenModule(MakeModule, DownloadableModule):
         if self.skip_autogen == 'never':
             return False
 
+        # if autogen.sh args has changed, re-run configure
+        db_entry = buildscript.moduleset.packagedb.get(self.name)
+        if db_entry:
+            configure_hash = db_entry.metadata.get('configure-hash')
+            if configure_hash:
+                configure_cmd = self._get_configure_cmd(buildscript)
+                if hashlib.md5(configure_cmd).hexdigest() != configure_hash:
+                    return False
+            else:
+                # force one-time reconfigure if no configure-hash
+                return False
+
         # We can't rely on the autotools maintainer-mode stuff because many
         # modules' autogen.sh script includes e.g. gtk-doc and/or intltool,
         # which also need to be rerun.
@@ -143,31 +218,6 @@ class AutogenModule(MakeModule, DownloadableModule):
         except:
             pass
 
-        if self.autogen_template:
-            template = self.autogen_template
-        else:
-            template = ("%(srcdir)s/%(autogen-sh)s --prefix %(prefix)s"
-                        " --libdir %(libdir)s %(autogenargs)s ")
-
-        autogenargs = self.autogenargs + ' ' + self.config.module_autogenargs.get(
-                self.name, self.config.autogenargs)
-
-        vars = {'prefix': buildscript.config.prefix,
-                'autogen-sh': self.autogen_sh,
-                'autogenargs': autogenargs}
-                
-        if buildscript.config.buildroot and self.supports_non_srcdir_builds:
-            vars['srcdir'] = self.get_srcdir(buildscript)
-        else:
-            vars['srcdir'] = '.'
-
-        if buildscript.config.use_lib64:
-            vars['libdir'] = "'${exec_prefix}/lib64'"
-        else:
-            vars['libdir'] = "'${exec_prefix}/lib'"
-
-        cmd = self.static_analyzer_pre_cmd(buildscript) + template % vars
-
         if self.autogen_sh == 'autoreconf':
             # autoreconf doesn't honour ACLOCAL_FLAGS, therefore we pass
             # a crafted ACLOCAL variable.  (GNOME bug 590064)
@@ -180,34 +230,8 @@ class AutogenModule(MakeModule, DownloadableModule):
             buildscript.execute(['autoreconf', '-i'], cwd=srcdir,
                     extra_env=extra_env)
             os.chmod(os.path.join(srcdir, 'configure'), 0755)
-            cmd = cmd.replace('autoreconf', 'configure')
-            cmd = cmd.replace('--enable-maintainer-mode', '')
-
-        # Fix up the arguments for special cases:
-        #   tarballs: remove --enable-maintainer-mode to avoid breaking build
-        #   tarballs: remove '-- ' to avoid breaking build (GStreamer weirdness)
-        #   non-tarballs: place --prefix and --libdir after '-- ', if present
-        if self.autogen_sh == 'configure':
-            cmd = cmd.replace('--enable-maintainer-mode', '')
-            
-            # Also, don't pass '--', which gstreamer attempts to do, since
-            # it is royally broken.
-            cmd = cmd.replace('-- ', '')
-        else:
-            # place --prefix and --libdir arguments after '-- '
-            # (GStreamer weirdness)
-            if autogenargs.find('-- ') != -1:
-                p = re.compile('(.*)(--prefix %s )((?:--libdir %s )?)(.*)-- ' %
-                       (buildscript.config.prefix, "'\${exec_prefix}/lib64'"))
-                cmd = p.sub(r'\1\4-- \2\3', cmd)
-
-        # If there is no --exec-prefix in the constructed autogen command, we
-        # can safely assume it will be the same as {prefix} and substitute it
-        # right now, so the printed command can be copy/pasted afterwards.
-        # (GNOME #580272)
-        if not '--exec-prefix' in template:
-            cmd = cmd.replace('${exec_prefix}', buildscript.config.prefix)
 
+        cmd = self._get_configure_cmd(buildscript)
         buildscript.execute(cmd, cwd = builddir, extra_env = self.extra_env)
     do_configure.depends = [PHASE_CHECKOUT]
     do_configure.error_phases = [PHASE_FORCE_CHECKOUT,
diff --git a/jhbuild/utils/packagedb.py b/jhbuild/utils/packagedb.py
index 4fa044d..d80e3b4 100644
--- a/jhbuild/utils/packagedb.py
+++ b/jhbuild/utils/packagedb.py
@@ -23,6 +23,10 @@ import stat
 import time
 import logging
 import xml.dom.minidom as DOM
+try:
+    import hashlib
+except ImportError:
+    import md5 as hashlib
 
 from jhbuild.utils import lockfile
 
@@ -81,6 +85,9 @@ class PackageEntry:
         installed_string = node.attrib['installed']
         if installed_string:
             metadata['installed-date'] = _parse_isotime(installed_string)
+        configure_hash = node.attrib.get('configure-hash')
+        if configure_hash:
+            metadata['configure-hash'] = configure_hash
 
         dbentry = cls(package, version, metadata, manifests_dir)
 
@@ -107,6 +114,9 @@ class PackageEntry:
                                           'version': self.version})
         if 'installed-date' in self.metadata:
             entry_node.attrib['installed'] = _format_isotime(self.metadata['installed-date'])
+        if 'configure-hash' in self.metadata:
+            entry_node.attrib['configure-hash'] = \
+                self.metadata['configure-hash']
         if self.manifest is not None:
             fd = file(os.path.join(self.manifests_dir, self.package + '.tmp'), 'w')
             fd.write('\n'.join(self.manifest))
@@ -216,11 +226,18 @@ class PackageDB:
 
     @_ensure_cache
     @_locked
-    def add(self, package, version, contents):
+    def add(self, package, version, contents, configure_cmd = None):
         '''Add a module to the install cache.'''
-        now = time.time()
-        metadata = {'installed-date': now}
-        self._entries[package] = PackageEntry(package, version, metadata, self.manifests_dir)
+        entry = self.get(package)
+        if entry:
+            metadata = entry.metadata
+        else:
+            metadata = {}
+        metadata['installed-date'] = time.time() # now
+        if configure_cmd:
+            metadata['configure-hash'] = hashlib.md5(configure_cmd).hexdigest()
+        self._entries[package] = PackageEntry(package, version, metadata,
+                                              self.manifests_dir)
         self._entries[package].manifest = contents
         self._write_cache()
 



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