[Pkg-debile-commits] [debile-slave] 11/28: add coccinelle worker
Sylvestre Ledru
sylvestre at alioth.debian.org
Mon Aug 19 14:55:20 UTC 2013
This is an automated email from the git hooks/post-receive script.
sylvestre pushed a commit to branch master
in repository debile-slave.
commit d133b5e95ed166b4d8f8c200d95aeefb7258fc55
Author: Matthieu Caneill <matthieu.caneill42 at gmail.com>
Date: Mon Aug 12 09:59:32 2013 +0200
add coccinelle worker
Located in ethel/[wrappers|runners|commands]/coccinelle.py,
it adds the possibility to run coccinelle static tool on C files.
---
ethel/commands/__init__.py | 1 +
ethel/commands/coccinelle.py | 27 +++++++++++++++++++++
ethel/runners/coccinelle.py | 53 ++++++++++++++++++++++++++++++++++++++++++
ethel/wrappers/coccinelle.py | 11 +++++++++
4 files changed, 92 insertions(+)
diff --git a/ethel/commands/__init__.py b/ethel/commands/__init__.py
index ec11e60..28dbf03 100644
--- a/ethel/commands/__init__.py
+++ b/ethel/commands/__init__.py
@@ -6,6 +6,7 @@ PLUGINS = {
"pep8": "ethel.commands.pep8",
"perlcritic": "ethel.commands.perlcritic",
"cppcheck": "ethel.commands.cppcheck",
+ "coccinelle": "ethel.commands.coccinelle",
"lintian": "ethel.commands.lintian",
"lintian4py": "ethel.commands.lintian4py",
diff --git a/ethel/commands/coccinelle.py b/ethel/commands/coccinelle.py
new file mode 100644
index 0000000..6636703
--- /dev/null
+++ b/ethel/commands/coccinelle.py
@@ -0,0 +1,27 @@
+from ethel.runners.coccinelle import coccinelle, version
+
+### Coccinelle worker ###
+
+# 1/ install last Coccinelle development version
+
+# download it from http://coccinelle.lip6.fr/download.php
+# the version must be 1.0.0-rc18 or newer
+# $ cd coccinelle
+# $ ./configure --enable-python
+# $ make
+# $ sudo make install
+
+# 2/ get the semantic patches
+
+# $ bin/update-coccinelle-semantic-patches coccinelle_sp
+
+# 3/ put in config.ini the path of coccinelle_sp
+
+# coccinelle_patches_folder: /path/to/coccinelle_sp
+
+
+def run(dsc, package, job, firehose):
+ return coccinelle(dsc, firehose)
+
+def get_version():
+ return version()
diff --git a/ethel/runners/coccinelle.py b/ethel/runners/coccinelle.py
new file mode 100644
index 0000000..d8f94b3
--- /dev/null
+++ b/ethel/runners/coccinelle.py
@@ -0,0 +1,53 @@
+from ethel.wrappers.coccinelle import parse_coccinelle
+from ethel.utils import run_command, cd
+from ethel.config import load
+import os
+import glob
+
+def list_semantic_patches():
+ config = load(location="/home/matthieu/work/debian/ethel/config.ini")
+ print config["coccinelle_patches_folder"]
+ return glob.iglob(config["coccinelle_patches_folder"] + "*/*.cocci")
+
+def coccinelle(dsc, analysis):
+ run_command(["dpkg-source", "-x", dsc, "source"])
+ with cd('source'):
+ complete_out = ""
+ failed = False
+ for semantic_patch in list_semantic_patches():
+ print(semantic_patch)
+ out, err, ret = run_command([
+ "spatch",
+ "-D", "firehose",
+ "--cocci-file", semantic_patch,
+ "--dir", ".",
+ "--no-show-diff",
+ "--timeout", "120",
+ ])
+ failed = (ret != 0) or failed
+
+ for result in parse_coccinelle(out):
+ analysis.results.append(result)
+
+ complete_out += out
+
+ return (analysis, complete_out, failed)
+
+def version():
+ out, err, ret = run_command(["spatch", "--version"])
+ if ret != 0:
+ raise Exception("spatch seems not to be installed")
+ try:
+ out = out.split()[2] # we only extract the version number
+ except:
+ out = out.strip()
+ return out
+
+
+if __name__ == "__main__":
+ import firehose.model
+ analysis = firehose.model.Analysis(
+ metadata=firehose.model.Metadata(firehose.model.Generator("foo"),
+ None, None, None),
+ results=[])
+ print(coccinelle("fontforge_20120731.b-3.dsc", analysis))
diff --git a/ethel/wrappers/coccinelle.py b/ethel/wrappers/coccinelle.py
new file mode 100644
index 0000000..bcb19f2
--- /dev/null
+++ b/ethel/wrappers/coccinelle.py
@@ -0,0 +1,11 @@
+import StringIO
+from firehose.model import Analysis
+
+def parse_coccinelle(lines):
+ # we have to emulate a file for from_xml()
+ firehose = StringIO.StringIO(lines)
+ analysis = Analysis.from_xml(firehose)
+
+ for result in analysis.results:
+ yield result
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-debile/debile-slave.git
More information about the Pkg-debile-commits
mailing list