Building Debian packages with scan-build

Purpose

This page describes the different solutions you have when you want to build a Debian package using scan-build, the static analysis tool from the LLVM suite.

Solutions

A few solutions I have heard of, some of them work but some of them cannot.

Easiest way

Just do :

scan-build dpkg-buildpackage

Fake dpkg-buildpackage

Working well, this is one good solution to keep. This is simply the previous solution, wrapped up in a new script. When you are using a tool which calls dpkg-buildpackage (e.g sbuild).

mv /usr/bin/dpkg-buildpackage /usr/bin/dpkg-buildpackage.faked
cat > /usr/bin/dpkg-buildpackage <<EOF
#!/bin/bash
scan-build dpkg-buildpackage.faked $@
EOF
chmod +x /usr/bin/dpkg-buildpackage
dpkg-buildpackage 

Fake make

Wrapping the make command in scan-build is not sufficient because scan-build needs also to be called for the "configure" phase. This technique may lead to unexpected results.

PATH magic

Does not work with scan-build because scan-build is not a real compiler it is a wrapper of ccc-analyzer which is itself a wrapper calling the clang -cc1 frontend.

mkdir /tmp/scan-build-path
ln -s /usr/bin/g++ /tmp/scan-build-path/
export PATH=/tmp/scan-build-path:$PATH
dpkg-buildpackage