2015-06-29 19:05:23 +02:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import string
|
2019-08-03 10:44:57 +02:00
|
|
|
import fnmatch
|
2015-06-29 19:05:23 +02:00
|
|
|
|
|
|
|
from scriptCommon import catchPath
|
|
|
|
|
2017-03-16 19:17:45 +01:00
|
|
|
versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
|
2020-01-19 15:37:34 +01:00
|
|
|
rootPath = os.path.join( catchPath, 'src/catch2' )
|
|
|
|
versionPath = os.path.join( rootPath, "catch_version.cpp" )
|
2020-01-19 15:30:38 +01:00
|
|
|
definePath = os.path.join(rootPath, 'catch_version_macros.hpp')
|
2015-06-29 19:05:23 +02:00
|
|
|
readmePath = os.path.join( catchPath, "README.md" )
|
2017-10-12 21:42:09 +02:00
|
|
|
cmakePath = os.path.join(catchPath, 'CMakeLists.txt')
|
2022-10-01 23:28:30 +02:00
|
|
|
mesonPath = os.path.join(catchPath, 'meson.build')
|
2015-06-29 19:05:23 +02:00
|
|
|
|
|
|
|
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.patchNumber = int(m.group(4))
|
|
|
|
self.branchName = m.group(5)
|
|
|
|
self.buildNumber = int(m.group(6))
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def nonDevelopRelease(self):
|
|
|
|
if self.branchName != "":
|
|
|
|
self.branchName = ""
|
|
|
|
self.buildNumber = 0
|
|
|
|
def developBuild(self):
|
|
|
|
if self.branchName == "":
|
|
|
|
self.branchName = "develop"
|
|
|
|
self.buildNumber = 0
|
|
|
|
|
|
|
|
def incrementBuildNumber(self):
|
|
|
|
self.developBuild()
|
|
|
|
self.buildNumber = self.buildNumber+1
|
|
|
|
|
|
|
|
def incrementPatchNumber(self):
|
|
|
|
self.nonDevelopRelease()
|
|
|
|
self.patchNumber = self.patchNumber+1
|
|
|
|
|
|
|
|
def incrementMinorVersion(self):
|
|
|
|
self.nonDevelopRelease()
|
|
|
|
self.patchNumber = 0
|
|
|
|
self.minorVersion = self.minorVersion+1
|
|
|
|
|
|
|
|
def incrementMajorVersion(self):
|
|
|
|
self.nonDevelopRelease()
|
|
|
|
self.patchNumber = 0
|
|
|
|
self.minorVersion = 0
|
|
|
|
self.majorVersion = self.majorVersion+1
|
|
|
|
|
|
|
|
def getVersionString(self):
|
|
|
|
versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
|
|
|
|
if self.branchName != "":
|
|
|
|
versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
|
|
|
|
return versionString
|
|
|
|
|
|
|
|
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}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
|
|
|
|
else:
|
|
|
|
lines.append( line.rstrip() )
|
|
|
|
f.close()
|
|
|
|
f = open( versionPath, 'w' )
|
|
|
|
for line in lines:
|
|
|
|
f.write( line + "\n" )
|
|
|
|
|
2017-06-27 16:03:27 +02:00
|
|
|
|
2017-10-12 21:42:09 +02:00
|
|
|
def updateCmakeFile(version):
|
2019-08-03 11:08:05 +02:00
|
|
|
with open(cmakePath, 'rb') as file:
|
2017-10-12 21:42:09 +02:00
|
|
|
lines = file.readlines()
|
2022-05-17 22:12:41 +02:00
|
|
|
replacementRegex = re.compile(b'''VERSION (\\d+.\\d+.\\d+) # CML version placeholder, don't delete''')
|
|
|
|
replacement = '''VERSION {0} # CML version placeholder, don't delete'''.format(version.getVersionString()).encode('ascii')
|
2019-08-03 11:08:05 +02:00
|
|
|
with open(cmakePath, 'wb') as file:
|
2017-10-12 21:42:09 +02:00
|
|
|
for line in lines:
|
2019-08-03 11:08:05 +02:00
|
|
|
file.write(replacementRegex.sub(replacement, line))
|
2017-10-12 21:42:09 +02:00
|
|
|
|
2018-01-26 20:27:19 +01:00
|
|
|
|
2022-10-01 23:28:30 +02:00
|
|
|
def updateMesonFile(version):
|
|
|
|
with open(mesonPath, 'rb') as file:
|
|
|
|
lines = file.readlines()
|
|
|
|
replacementRegex = re.compile(b'''version\s*:\s*'(\\d+.\\d+.\\d+)', # CML version placeholder, don't delete''')
|
2022-10-03 17:23:38 +02:00
|
|
|
replacement = '''version: '{0}', # CML version placeholder, don't delete'''.format(version.getVersionString()).encode('ascii')
|
2022-10-01 23:28:30 +02:00
|
|
|
with open(mesonPath, 'wb') as file:
|
|
|
|
for line in lines:
|
|
|
|
file.write(replacementRegex.sub(replacement, line))
|
|
|
|
|
|
|
|
|
2018-01-26 20:27:19 +01:00
|
|
|
def updateVersionDefine(version):
|
2019-08-03 11:08:05 +02:00
|
|
|
# First member of the tuple is the compiled regex object, the second is replacement if it matches
|
|
|
|
replacementRegexes = [(re.compile(b'#define CATCH_VERSION_MAJOR \\d+'),'#define CATCH_VERSION_MAJOR {}'.format(version.majorVersion).encode('ascii')),
|
|
|
|
(re.compile(b'#define CATCH_VERSION_MINOR \\d+'),'#define CATCH_VERSION_MINOR {}'.format(version.minorVersion).encode('ascii')),
|
|
|
|
(re.compile(b'#define CATCH_VERSION_PATCH \\d+'),'#define CATCH_VERSION_PATCH {}'.format(version.patchNumber).encode('ascii')),
|
|
|
|
]
|
|
|
|
with open(definePath, 'rb') as file:
|
2018-01-26 20:27:19 +01:00
|
|
|
lines = file.readlines()
|
2019-08-03 11:08:05 +02:00
|
|
|
with open(definePath, 'wb') as file:
|
2018-01-26 20:27:19 +01:00
|
|
|
for line in lines:
|
2019-08-03 11:08:05 +02:00
|
|
|
for replacement in replacementRegexes:
|
|
|
|
line = replacement[0].sub(replacement[1], line)
|
|
|
|
file.write(line)
|
2018-01-26 20:27:19 +01:00
|
|
|
|
|
|
|
|
2019-08-03 10:44:57 +02:00
|
|
|
def updateVersionPlaceholder(filename, version):
|
|
|
|
with open(filename, 'rb') as file:
|
|
|
|
lines = file.readlines()
|
2020-12-29 15:02:11 +01:00
|
|
|
placeholderRegex = re.compile(b'in Catch[0-9]? X.Y.Z')
|
|
|
|
replacement = 'in Catch2 {}.{}.{}'.format(version.majorVersion, version.minorVersion, version.patchNumber).encode('ascii')
|
2019-08-03 10:44:57 +02:00
|
|
|
with open(filename, 'wb') as file:
|
|
|
|
for line in lines:
|
|
|
|
file.write(placeholderRegex.sub(replacement, line))
|
|
|
|
|
|
|
|
|
|
|
|
def updateDocumentationVersionPlaceholders(version):
|
|
|
|
print('Updating version placeholder in documentation')
|
|
|
|
docsPath = os.path.join(catchPath, 'docs/')
|
|
|
|
for basePath, _, files in os.walk(docsPath):
|
|
|
|
for file in files:
|
|
|
|
if fnmatch.fnmatch(file, "*.md") and "contributing.md" != file:
|
|
|
|
updateVersionPlaceholder(os.path.join(basePath, file), version)
|
|
|
|
|
|
|
|
|
2017-08-24 21:59:06 +02:00
|
|
|
def performUpdates(version):
|
|
|
|
version.updateVersionFile()
|
2018-01-26 20:27:19 +01:00
|
|
|
updateVersionDefine(version)
|
2018-01-10 13:44:08 +01:00
|
|
|
|
2022-05-16 18:39:01 +02:00
|
|
|
import generateAmalgamatedFiles
|
|
|
|
generateAmalgamatedFiles.generate_header()
|
|
|
|
generateAmalgamatedFiles.generate_cpp()
|
2018-01-10 13:44:08 +01:00
|
|
|
|
2017-10-12 21:42:09 +02:00
|
|
|
updateCmakeFile(version)
|
2022-10-01 23:28:30 +02:00
|
|
|
updateMesonFile(version)
|
2019-08-03 10:44:57 +02:00
|
|
|
updateDocumentationVersionPlaceholders(version)
|