File: generateSingleHeader.py

package info (click to toggle)
catch 1.0%2Bm10git1e2f1d16-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,984 kB
  • ctags: 2,218
  • sloc: cpp: 14,476; ansic: 738; python: 173; objc: 39; makefile: 17
file content (117 lines) | stat: -rw-r--r-- 4,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import os
import sys
import re
import datetime

from scriptCommon import catchPath

versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*\).*' )
includesParser = re.compile( r'\s*#include\s*"(.*)"' )
guardParser = re.compile( r'\s*#.*_INCLUDED')
defineParser = re.compile( r'\s*#define')
commentParser1 = re.compile( r'^\s*/\*')
commentParser2 = re.compile( r'^\s*\*')
blankParser = re.compile( r'^\s*$')
seenHeaders = set([])
rootPath = os.path.join( catchPath, 'include/' )
versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
readmePath = os.path.join( catchPath, "README.md" )
outputPath = os.path.join( catchPath, 'single_include/catch.hpp' )

bumpVersion = len(sys.argv) < 2 or sys.argv[1] <> "nobump"

out = open( outputPath, 'w' )

def parseFile( path, filename ):
	f = open( path + filename, 'r' )
	blanks = 0
	for line in f:
		m = includesParser.match( line )
		if m:
			header = m.group(1)
			headerPath, sep, headerFile = header.rpartition( "/" )
			if not headerFile in seenHeaders:
				seenHeaders.add( headerFile )
				out.write( "// #included from: {0}\n".format( header ) )
				if( headerPath == "internal" and path.endswith( "internal/" ) ):
					headerPath = ""
					sep = ""
				if os.path.exists( path + headerPath + sep + headerFile ):
					parseFile( path + headerPath + sep, headerFile )
				else:
					parseFile( rootPath + headerPath + sep, headerFile )
		elif (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ):
			if blankParser.match( line ):
				blanks = blanks + 1
			else:
				blanks = 0
			if blanks < 2:
				out.write( line.rstrip() + "\n" )

class Version:
	def __init__(self):
		f = open( versionPath, 'r' )
		for line in f:
			m = versionParser.match( line )
			if m:
				self.variableDecl = m.group(1)
				self.majorVersion = int(m.group(2))
				self.minorVersion = int(m.group(3))
				self.buildNumber = int(m.group(4))
				self.branchName = m.group(5)
		f.close()

	def incrementBuildNumber(self):
		self.buildNumber = self.buildNumber+1

	def updateVersionFile(self):
		f = open( versionPath, 'r' )
		lines = []
		for line in f:
			m = versionParser.match( line )
			if m:
				lines.append( '{0}( {1}, {2}, {3}, "{4}" );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.buildNumber, self.branchName ) )
			else:
				lines.append( line.rstrip() )
		f.close()
		f = open( versionPath, 'w' )
		for line in lines:
			f.write( line + "\n" )

	def updateReadmeFile(self):
		f = open( readmePath, 'r' )
		lines = []
		for line in f:
			lines.append( line.rstrip() )
		f.close()
		f = open( readmePath, 'w' )
		for line in lines:
			if line.startswith( "*v" ):
				f.write( '*v{0}.{1} build {2} ({3} branch)*\n'.format( self.majorVersion, self.minorVersion, self.buildNumber, self.branchName ) )
			else:
				f.write( line + "\n" )

def generateSingleInclude():
	v = Version()
	if bumpVersion:
		v.incrementBuildNumber()
		v.updateVersionFile()
		v.updateReadmeFile()
	out.write( "/*\n" )
	out.write( " *  CATCH v{0}.{1} build {2} ({3} branch)\n".format( v.majorVersion, v.minorVersion, v.buildNumber, v.branchName ) )
	out.write( " *  Generated: {0}\n".format( datetime.datetime.now() ) )
	out.write( " *  ----------------------------------------------------------\n" )
	out.write( " *  This file has been merged from multiple headers. Please don't edit it directly\n" )
	out.write( " *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.\n" )
	out.write( " *\n" )
	out.write( " *  Distributed under the Boost Software License, Version 1.0. (See accompanying\n" )
	out.write( " *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n" )
	out.write( " */\n" )
	out.write( "#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
	out.write( "#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
	
	parseFile( rootPath, 'catch.hpp' )
	
	out.write( "#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" )

generateSingleInclude()