diff options
Diffstat (limited to 'BuildTools/CheckHeaders.py')
| -rwxr-xr-x | BuildTools/CheckHeaders.py | 43 | 
1 files changed, 32 insertions, 11 deletions
| diff --git a/BuildTools/CheckHeaders.py b/BuildTools/CheckHeaders.py index 73f49db..ce907c5 100755 --- a/BuildTools/CheckHeaders.py +++ b/BuildTools/CheckHeaders.py @@ -2,20 +2,41 @@  import os, sys +FORBIDDEN_INCLUDES = [ +  ("iostream", ["Swiften/Base/format.h"]),  +  ("Base/Log.h", []),  +  ("Base/format.h", []), +  ("algorithm", ["Swiften/Base/Algorithm.h", "Swiften/Base/SafeAllocator.h"]),  +  ("boost/bind.hpp", []),  +  ("boost/filesystem.hpp", []),  +  ("Base/foreach.h", []),  +  ("boost/date_time/date_time.hpp", []),  +  ("boost/filesystem/filesystem.hpp", []), + +  # To avoid +  ("Base/Algorithm.h", ["Swiften/StringCodecs/HMAC.h"]), +] +  foundBadHeaders = False -for (path, dirs, files) in os.walk(".") : -  if "3rdParty" in path or ".sconf" in path or ".framework" in path : +filename = sys.argv[1] + +if "3rdParty" in filename or ".sconf" in filename or ".framework" in filename or not filename.endswith(".h") : +  sys.exit(0) +if not "Swiften" in filename : +  sys.exit(0) +if filename.endswith("Swiften.h") : +  sys.exit(0) + +file = open(filename, "r") +for line in file.readlines() : +  if not "#include" in line :      continue -  if not "Swiften" in path : +  if "Base/Log.h" in filename :      continue - -  for filename in [os.path.join(path, file) for file in files if file.endswith(".h")] : -    file = open(filename, "r") -    for line in file.readlines() : -      for include in ["iostream", "algorithm", "cassert", "boost/bind.hpp", "boost/filesystem.hpp", "Base/foreach.h", "Base/Log.h", "boost/date_time/date_time.hpp", "boost/filesystem/filesystem.hpp"] : -        if "#include" in line and include in line and not "Base/Log" in filename : -          print "Found " + include + " include in " + filename -          foundBadHeaders = True +  for forbiddenInclude, ignores in FORBIDDEN_INCLUDES : +    if forbiddenInclude in line and len([x for x in ignores if x in filename]) == 0 : +      print "Found " + forbiddenInclude + " include in " + filename +      foundBadHeaders = True  sys.exit(foundBadHeaders) | 
 Swift
 Swift