From 6e7c248568a13efcdaf5a2426d4d8ec4651e665e Mon Sep 17 00:00:00 2001 From: Edward Brash <brash@jlab.org> Date: Mon, 25 Nov 2013 18:23:27 -0500 Subject: [PATCH] Implement 'scons cppcheck=1' Generate cppcheck_report.txt in the top level directory. --- README.md | 2 ++ SConstruct.py | 31 +++++++++++++++++++++++++++++++ darwin64.py | 5 +++++ linux32.py | 5 +++++ linux64.py | 5 +++++ 5 files changed, 48 insertions(+) diff --git a/README.md b/README.md index 3fc9656..b39b884 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ To compile with debug capabilities, do `scons debug=1` To compile the standalone codes the are part of podd, do `scons standalone=1` +To run cppcheck (if installed) on the Hall C src diretory, do +`scons cppcheck=1` Running ------- diff --git a/SConstruct.py b/SConstruct.py index 069202f..69474cf 100644 --- a/SConstruct.py +++ b/SConstruct.py @@ -105,6 +105,37 @@ except OSError: bld = Builder(action=rootcint) baseenv.Append(BUILDERS = {'RootCint': bld}) +######## cppcheck ########################### + +def which(program): + import os + def is_exe(fpath): + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + + fpath, fname = os.path.split(program) + if fpath: + if is_exe(program): + return program + else: + for path in os.environ["PATH"].split(os.pathsep): + path = path.strip('"') + exe_file = os.path.join(path, program) + if is_exe(exe_file): + return exe_file + return None + +proceed = "1" or "y" or "yes" or "Yes" or "Y" +if baseenv.subst('$CPPCHECK')==proceed: + is_cppcheck = which('cppcheck') + print "Path to cppcheck is %s\n" % is_cppcheck + + if(is_cppcheck == None): + print('!!! cppcheck not found on this system. Check if cppcheck is installed and in your PATH.') + Exit(1) + else: + cppcheck_command = baseenv.Command('cppcheck_report.txt',[],"cppcheck --quiet --enable=all src/ 2> $TARGET") + baseenv.AlwaysBuild(cppcheck_command) + ####### Start of main SConstruct ############ hallclib = 'HallC' diff --git a/darwin64.py b/darwin64.py index 864f8b4..08c690b 100644 --- a/darwin64.py +++ b/darwin64.py @@ -5,6 +5,8 @@ def config(env,args): debug = args.get('debug',0) standalone = args.get('standalone',0) + cppcheck = args.get('cppcheck',0) + if int(debug): env.Append(CXXFLAGS = '-g -O0') else: @@ -14,6 +16,9 @@ def config(env,args): if int(standalone): env.Append(STANDALONE= '1') + if int(cppcheck): + env.Append(CPPCHECK= '1') + #env.Append(CXXFLAGS = '-Wall -Woverloaded-virtual -pthread -rdynamic') env.Append(CXXFLAGS = '-Wall -Woverloaded-virtual -pthread') env.Append(CPPDEFINES = '-DMACVERS') diff --git a/linux32.py b/linux32.py index 4db891c..6ba4b17 100644 --- a/linux32.py +++ b/linux32.py @@ -5,6 +5,8 @@ def config(env,args): debug = args.get('debug',0) standalone = args.get('standalone',0) + cppcheck = args.get('cppcheck',0) + if int(debug): env.Append(CXXFLAGS = '-g -O0') else: @@ -14,6 +16,9 @@ def config(env,args): if int(standalone): env.Append(STANDALONE= '1') + if int(cppcheck): + env.Append(CPPCHECK= '1') + env.Append(CXXFLAGS = '-m32 -Wall -Woverloaded-virtual') env.Append(CPPDEFINES = '-DLINUXVERS') diff --git a/linux64.py b/linux64.py index d45f862..ae012d6 100644 --- a/linux64.py +++ b/linux64.py @@ -5,6 +5,8 @@ def config(env,args): debug = args.get('debug',0) standalone = args.get('standalone',0) + cppcheck = args.get('cppcheck',0) + if int(debug): env.Append(CXXFLAGS = '-g -O0') else: @@ -14,6 +16,9 @@ def config(env,args): if int(standalone): env.Append(STANDALONE= '1') + if int(cppcheck): + env.Append(CPPCHECK= '1') + env.Append(CXXFLAGS = '-Wall -Woverloaded-virtual') env.Append(CPPDEFINES = '-DLINUXVERS') -- GitLab