2012-11-15 23:15:41 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import datetime
|
|
|
|
|
2013-04-24 19:58:57 +02:00
|
|
|
from scriptCommon import catchPath
|
|
|
|
|
2012-12-02 00:42:47 +01:00
|
|
|
versionParser = re.compile( r'(\s*Version\slibraryVersion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*\).*' )
|
2012-11-15 23:15:41 +01:00
|
|
|
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([])
|
2013-04-24 19:58:57 +02:00
|
|
|
rootPath = os.path.join( catchPath, 'include/' )
|
2012-11-15 23:15:41 +01:00
|
|
|
versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
|
2013-04-24 19:58:57 +02:00
|
|
|
readmePath = os.path.join( catchPath, "README.md" )
|
2012-11-15 23:15:41 +01:00
|
|
|
#outputPath = os.path.join( catchPath, 'single_include/catch.hpp' )
|
|
|
|
|
2013-03-04 12:19:15 +01:00
|
|
|
bumpVersion = len(sys.argv) < 2 or sys.argv[1] <> "nobump"
|
|
|
|
|
2012-11-15 23:15:41 +01:00
|
|
|
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 )
|
|
|
|
print "// #included from: " + 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:
|
|
|
|
print line.rstrip()
|
|
|
|
|
|
|
|
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:
|
2012-12-02 00:42:47 +01:00
|
|
|
lines.append( '{0}( {1}, {2}, {3}, "{4}" );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.buildNumber, self.branchName ) )
|
2012-11-15 23:15:41 +01:00
|
|
|
else:
|
|
|
|
lines.append( line.rstrip() )
|
|
|
|
f.close()
|
|
|
|
f = open( versionPath, 'w' )
|
|
|
|
for line in lines:
|
|
|
|
f.write( line + "\n" )
|
|
|
|
|
2012-11-16 21:43:27 +01:00
|
|
|
def updateReadmeFile(self):
|
|
|
|
f = open( readmePath, 'r' )
|
|
|
|
lines = []
|
|
|
|
for line in f:
|
|
|
|
lines.append( line.rstrip() )
|
|
|
|
f.close()
|
|
|
|
f = open( readmePath, 'w' )
|
2013-03-21 21:48:05 +01:00
|
|
|
for line in lines:
|
|
|
|
if line.startswith( "## CATCH" ):
|
|
|
|
f.write( '## CATCH v{0}.{1} build {2} ({3} branch)\n'.format( self.majorVersion, self.minorVersion, self.buildNumber, self.branchName ) )
|
|
|
|
else:
|
|
|
|
f.write( line + "\n" )
|
2012-11-16 21:43:27 +01:00
|
|
|
|
2012-11-15 23:15:41 +01:00
|
|
|
def generateSingleInclude():
|
|
|
|
v = Version()
|
2013-03-04 12:19:15 +01:00
|
|
|
if bumpVersion:
|
|
|
|
v.incrementBuildNumber()
|
|
|
|
v.updateVersionFile()
|
|
|
|
v.updateReadmeFile()
|
2012-11-15 23:15:41 +01:00
|
|
|
print "/*"
|
|
|
|
print " * CATCH v{0}.{1} build {2} ({3} branch)".format( v.majorVersion, v.minorVersion, v.buildNumber, v.branchName )
|
|
|
|
print " * Generated: " + str( datetime.datetime.now() )
|
|
|
|
print " * ----------------------------------------------------------"
|
|
|
|
print " * This file has been merged from multiple headers. Please don't edit it directly"
|
|
|
|
print " * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved."
|
|
|
|
print " *"
|
|
|
|
print " * Distributed under the Boost Software License, Version 1.0. (See accompanying"
|
|
|
|
print " * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)"
|
|
|
|
print " */"
|
|
|
|
print '#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
|
|
|
|
print '#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
|
|
|
|
parseFile( rootPath, 'catch.hpp' )
|
|
|
|
print '#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED'
|
|
|
|
print
|
|
|
|
|
|
|
|
generateSingleInclude()
|