Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make Clang's "scan-build" work with SCons?

Tags:

I've got a project built with SCons and I'm trying to use the Clang Static Analyzer to analyze the code. However, when running

scan-build scons 

SCons seems to ignore the settings introduced by scan-build. How can I make this work?

like image 242
Greg Hewgill Avatar asked Feb 16 '12 04:02

Greg Hewgill


People also ask

How does scan build work?

scan-build has little or no knowledge about how you build your code. It works by overriding the CC and CXX environment variables to (hopefully) change your build to use a "fake" compiler instead of the one that would normally build your project.

What is analyze in Xcode?

The static analyzer is a tool in Xcode that can discover bugs by analyzing the source code without running it, so it can reveal bugs, even before you do testing and quality assurance of your app.


1 Answers

The way scan-build works is it sets up various environment variables that are usually used by build systems (such as make) to control how the build happens. Some of these are:

  • CC - name of program to use as C compiler
  • CXX - name of program to use as C++ compiler
  • CCC_* - various environment variables that control the behaviour of Clang's static analyzer

SCons normally cleans out the environment before running a build (this is a feature). In order to make the above environment variables take effect, do something like this in SConstruct:

env = Environment() env["CC"] = os.getenv("CC") or env["CC"] env["CXX"] = os.getenv("CXX") or env["CXX"] env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_")) 
like image 119
Greg Hewgill Avatar answered Sep 20 '22 15:09

Greg Hewgill