[jhbuild] Support running scan-build (Clang Static Analyzer) with autotools projects



commit 68dbc0c9b0019ddf3ce622fc10463fa3222310ab
Author: Jeremy Huddleston <jeremyhu apple com>
Date:   Thu Apr 28 00:55:13 2011 -0700

    Support running scan-build (Clang Static Analyzer) with autotools projects
    
    http://clang-analyzer.llvm.org
    
    Signed-off-by: Jeremy Huddleston <jeremyhu apple com>
    Signed-off-by: Dirk Wallenstein <halsmit t-online de>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=648990

 jhbuild/config.py             |    3 ++-
 jhbuild/defaults.jhbuildrc    |    9 ++++++++-
 jhbuild/modtypes/autotools.py |   28 ++++++++++++++++++++++++----
 3 files changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/jhbuild/config.py b/jhbuild/config.py
index 0b1a7d8..be952e6 100644
--- a/jhbuild/config.py
+++ b/jhbuild/config.py
@@ -59,7 +59,8 @@ _known_keys = [ 'moduleset', 'modules', 'skip', 'tags', 'prefix',
                 'jhbuildbot_mastercfg', 'use_local_modulesets',
                 'ignore_suggests', 'modulesets_dir', 'mirror_policy',
                 'module_mirror_policy', 'dvcs_mirror_dir', 'build_targets',
-                'cmakeargs', 'module_cmakeargs', 'print_command_pattern' ]
+                'cmakeargs', 'module_cmakeargs', 'print_command_pattern',
+                'static_analyzer', 'module_static_analyzer', 'static_analyzer_template', 'static_analyzer_outputdir' ]
 
 env_prepends = {}
 def prependpath(envvar, path):
diff --git a/jhbuild/defaults.jhbuildrc b/jhbuild/defaults.jhbuildrc
index d7c49df..c417853 100644
--- a/jhbuild/defaults.jhbuildrc
+++ b/jhbuild/defaults.jhbuildrc
@@ -2,7 +2,7 @@
 # This file holds the default values for the ~/.jhbuildrc file.
 # Do not copy this to ~/.jhbuildrc
 
-import os, sys
+import os, sys, tempfile
 
 if 'GTK_PATH' in os.environ.keys():
     del os.environ['GTK_PATH']
@@ -93,6 +93,13 @@ interact      = True   # whether to interact with the user.
 quiet_mode    = False  # whether to display running commands output
 progress_bar  = True   # whether to display a progress bar when running in quiet mode
 
+# Run a static analyzer by prepending the command to the configure and build command lines.
+# Defaults to the Clang Static Analyzer (scan-build)
+static_analyzer = False
+module_static_analyzer = {}
+static_analyzer_template = 'scan-build -v -o %(outputdir)s/%(module)s'
+static_analyzer_outputdir = os.path.join(tempfile.gettempdir(), 'jhbuild_static_analyzer')
+
 # checkout modes. For VCS directories, it specifies how the checkout
 # is done. We can also specify checkout modes for specific modules
 checkout_mode = 'update'
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index 6050d7c..2d0e366 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -54,7 +54,8 @@ class AutogenModule(Package, DownloadableModule):
                  autogen_sh='autogen.sh',
                  makefile='Makefile',
                  autogen_template=None,
-                 check_target=True):
+                 check_target=True,
+                 supports_static_analyzer=True):
         Package.__init__(self, name, branch=branch)
         self.autogenargs = autogenargs
         self.makeargs    = makeargs
@@ -66,6 +67,7 @@ class AutogenModule(Package, DownloadableModule):
         self.autogen_template = autogen_template
         self.check_target = check_target
         self.supports_install_destdir = True
+        self.supports_static_analyzer = supports_static_analyzer
 
     def get_srcdir(self, buildscript):
         return self.branch.srcdir
@@ -141,7 +143,7 @@ class AutogenModule(Package, DownloadableModule):
         else:
             vars['libdir'] = "'${exec_prefix}/lib'"
 
-        cmd = template % vars
+        cmd = self.static_analyzer_pre_cmd(buildscript) + template % vars
 
         if self.autogen_sh == 'autoreconf':
             # autoreconf doesn't honour ACLOCAL_FLAGS, therefore we pass
@@ -210,13 +212,28 @@ class AutogenModule(Package, DownloadableModule):
         buildscript.set_action(_('Building'), self)
         makeargs = self.makeargs + ' ' + self.config.module_makeargs.get(
                 self.name, self.config.makeargs)
-        cmd = '%s %s' % (os.environ.get('MAKE', 'make'), makeargs)
+        cmd = '%s%s %s' % (self.static_analyzer_pre_cmd(buildscript), os.environ.get('MAKE', 'make'), makeargs)
         buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
                 extra_env = self.extra_env)
     do_build.depends = [PHASE_CONFIGURE]
     do_build.error_phases = [PHASE_FORCE_CHECKOUT, PHASE_CONFIGURE,
             PHASE_CLEAN, PHASE_DISTCLEAN]
 
+    def static_analyzer_pre_cmd(self, buildscript):
+        if self.supports_static_analyzer and buildscript.config.module_static_analyzer.get(self.name, buildscript.config.static_analyzer):
+            template = buildscript.config.static_analyzer_template + ' '
+            outputdir = buildscript.config.static_analyzer_outputdir
+
+            if not os.path.exists(outputdir):
+                os.makedirs(outputdir)
+
+            vars = {'outputdir': outputdir,
+                    'module': self.name
+                   }
+
+            return template % vars
+        return ''
+
     def skip_check(self, buildscript, last_phase):
         if not self.check_target:
             return True
@@ -230,7 +247,7 @@ class AutogenModule(Package, DownloadableModule):
         buildscript.set_action(_('Checking'), self)
         makeargs = self.makeargs + ' ' + self.config.module_makeargs.get(
                 self.name, self.config.makeargs)
-        cmd = '%s %s check' % (os.environ.get('MAKE', 'make'), makeargs)
+        cmd = '%s%s %s check' % (self.static_analyzer_pre_cmd(buildscript), os.environ.get('MAKE', 'make'), makeargs)
         try:
             buildscript.execute(cmd, cwd = self.get_builddir(buildscript),
                     extra_env = self.extra_env)
@@ -296,6 +313,7 @@ class AutogenModule(Package, DownloadableModule):
                  ('skip-autogen', 'skip_autogen', False),
                  ('autogen-sh', 'autogen_sh', 'autogen.sh'),
                  ('makefile', 'makefile', 'Makefile'),
+                 ('supports-static-analyzer', 'supports_static_analyzer', True),
                  ('autogen-template', 'autogen_template', None)])
 
 
@@ -337,6 +355,8 @@ def parse_autotools(node, config, uri, repositories, default_repo):
 
     if node.hasAttribute('check-target'):
         instance.check_target = (node.getAttribute('check-target') == 'true')
+    if node.hasAttribute('static-analyzer'):
+        instance.supports_static_analyzer = (node.getAttribute('static-analyzer') == 'true')
 
     from jhbuild.versioncontrol.tarball import TarballBranch
     if node.hasAttribute('autogen-sh'):



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