c++ - Setting up SCons to Autolint -


i'm using google's cpplint.py verify source code in project meets standards set forth in google c++ style guide. use scons build i'd automate process having scons first read in of our .h , .cc files , run cpplint.py on them, building file if passes. issues follows:

  1. in scons how pre-hook build process? no file should compiled until passes linting.
  2. cpplint doesn't return exit code. how run command in scons , check whether result matches regular expression? i.e., how text being output?
  3. the project large, whatever solution #1 , #2 should run concurrently when -j option passed scons.
  4. i need whitelist allows files skip lint check.

one way monkey patch object emitter function, turns c++ code linkable object files. there 2 such emitter functions; 1 static objects , 1 shared objects. here example can copy paste sconstruct:

import sys import scons.defaults import scons.builder originalshared = scons.defaults.sharedobjectemitter originalstatic = scons.defaults.staticobjectemitter  def dolint(env, source):     s in source:         env.lint(s.srcnode().path + ".lint", s)  def sharedobjectemitter(target, source, env):     dolint(env, source)     return originalshared(target, source, env)  def staticobjectemitter(target, source, env):     dolint(env, source)     return originalstatic(target, source, env)  scons.defaults.sharedobjectemitter = sharedobjectemitter scons.defaults.staticobjectemitter = staticobjectemitter linter = scons.builder.builder(     action=['$python $lint $lint_options $source','date > $target'],     suffix='.lint',     src_suffix='.cpp')  # actual build env = environment() env.append(builders={'lint': linter}) env["python"] = sys.executable env["lint"] = "cpplint.py" env["lint_options"] = ["--filter=-whitespace,+whitespace/tab", "--verbose=3"] env.program("test", glob("*.cpp")) 

there's nothing tricky really. you'd set lint path cpplint.py copy, , set appropriate lint_options project. warty bit creating target file if check passes using command line date program. if want cross platform that'd have change.

adding whitelist regular python code, like:

whitelist = """" src/legacy_code.cpp src/by_the_phb.cpp """".split()  def dolint(env, source):     s in source:         src = s.srcnode().path         if src not in whitelist:             env.lint( + ".lint", s) 

it seems cpplint.py output correct error status. when there errors returns 1, otherwise returns 0. there's no work there. if lint check fails, fail build.

this solution works -j, c++ files may compile there no implicit dependencies between lint fake output , object file target. can add explicit env.depends in there force ".lint" output depend on object target. it's enough, since build fail (scons gives non-zero return code) if there remaining lint issues after c++ compiles. completeness depends code in dolint function:

def dolint(env, source, target):     in range(len(source)):         s = source[i]         out = env.lint(s.srcnode().path + ".lint", s)         env.depends(target[i], out) 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -