PageRenderTime 43ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/glueHeaders.py

http://github.com/philsquared/Catch
Python | 54 lines | 52 code | 2 blank | 0 comment | 5 complexity | 78a3f96395a8ea251cfe5527742f4a51 MD5 | raw file
  1. import os
  2. import sys
  3. import re
  4. import datetime
  5. includesParser = re.compile( r'\s*#include\s*"(.*)"' )
  6. guardParser = re.compile( r'\s*#.*_INCLUDED')
  7. defineParser = re.compile( r'\s*#define')
  8. commentParser1 = re.compile( r'^\s*/\*')
  9. commentParser2 = re.compile( r'^\s*\*')
  10. blankParser = re.compile( r'^\s*$')
  11. seenHeaders = set([])
  12. rootPath = os.path.join( os.path.realpath(os.path.dirname(sys.argv[0])), 'include/' )
  13. def parseFile( path, filename ):
  14. f = open( path + filename, 'r' )
  15. blanks = 0
  16. for line in f:
  17. m = includesParser.match( line )
  18. if m:
  19. header = m.group(1)
  20. headerPath, sep, headerFile = header.rpartition( "/" )
  21. if not headerFile in seenHeaders:
  22. seenHeaders.add( headerFile )
  23. print "// #included from: " + header
  24. if( headerPath == "internal" and path.endswith( "internal/" ) ):
  25. headerPath = ""
  26. sep = ""
  27. if os.path.exists( path + headerPath + sep + headerFile ):
  28. parseFile( path + headerPath + sep, headerFile )
  29. else:
  30. parseFile( rootPath + headerPath + sep, headerFile )
  31. elif (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ):
  32. if blankParser.match( line ):
  33. blanks = blanks + 1
  34. else:
  35. blanks = 0
  36. if blanks < 2:
  37. print line.rstrip()
  38. print "/*"
  39. print " * Generated: " + str( datetime.datetime.now() )
  40. print " * ----------------------------------------------------------"
  41. print " * This file has been merged from multiple headers. Please don't edit it directly"
  42. print " * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved."
  43. print " *"
  44. print " * Distributed under the Boost Software License, Version 1.0. (See accompanying"
  45. print " * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)"
  46. print " */"
  47. print '#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
  48. print '#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
  49. parseFile( rootPath, 'catch.hpp' )
  50. print '#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
  51. print