| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | from  __future__ import  print_function | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | import string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from scriptCommon import catchPath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-16 11:17:45 -07:00
										 |  |  | versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' ) | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | rootPath = os.path.join( catchPath, 'include/' ) | 
					
						
							| 
									
										
										
										
											2017-07-09 20:58:51 +02:00
										 |  |  | versionPath = os.path.join( rootPath, "internal/catch_version.cpp" ) | 
					
						
							| 
									
										
										
										
											2018-01-26 20:27:19 +01:00
										 |  |  | definePath = os.path.join(rootPath, 'catch.hpp') | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | readmePath = os.path.join( catchPath, "README.md" ) | 
					
						
							| 
									
										
										
										
											2017-10-12 21:42:09 +02:00
										 |  |  | cmakePath = os.path.join(catchPath, 'CMakeLists.txt') | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01: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-08-24 21:59:06 +02:00
										 |  |  | def updateReadmeFile(version): | 
					
						
							| 
									
										
										
										
											2017-11-19 15:01:12 +01:00
										 |  |  |     import updateWandbox | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-10 14:01:20 +01:00
										 |  |  |     downloadParser = re.compile( r'<a href=\"https://github.com/catchorg/Catch2/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' ) | 
					
						
							| 
									
										
										
										
											2017-08-24 21:59:06 +02:00
										 |  |  |     success, wandboxLink = updateWandbox.uploadFiles() | 
					
						
							|  |  |  |     if not success: | 
					
						
							|  |  |  |         print('Error when uploading to wandbox: {}'.format(wandboxLink)) | 
					
						
							|  |  |  |         exit(1) | 
					
						
							|  |  |  |     f = open( readmePath, 'r' ) | 
					
						
							|  |  |  |     lines = [] | 
					
						
							|  |  |  |     for line in f: | 
					
						
							|  |  |  |         lines.append( line.rstrip() ) | 
					
						
							|  |  |  |     f.close() | 
					
						
							|  |  |  |     f = open( readmePath, 'w' ) | 
					
						
							|  |  |  |     for line in lines: | 
					
						
							| 
									
										
										
										
											2018-01-10 14:01:20 +01:00
										 |  |  |         line = downloadParser.sub( r'<a href="https://github.com/catchorg/Catch2/releases/download/v{0}/catch.hpp">'.format(version.getVersionString()) , line) | 
					
						
							| 
									
										
										
										
											2017-08-24 21:59:06 +02:00
										 |  |  |         if '[]' in line: | 
					
						
							|  |  |  |             line = '[]({0})'.format(wandboxLink) | 
					
						
							|  |  |  |         f.write( line + "\n" ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 11:03:27 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-12 21:42:09 +02:00
										 |  |  | def updateCmakeFile(version): | 
					
						
							|  |  |  |     with open(cmakePath, 'r') as file: | 
					
						
							|  |  |  |         lines = file.readlines() | 
					
						
							|  |  |  |     with open(cmakePath, 'w') as file: | 
					
						
							|  |  |  |         for line in lines: | 
					
						
							| 
									
										
										
										
											2018-01-18 19:20:08 +01:00
										 |  |  |             if 'project(Catch2 LANGUAGES CXX VERSION ' in line: | 
					
						
							|  |  |  |                 file.write('project(Catch2 LANGUAGES CXX VERSION {0})\n'.format(version.getVersionString())) | 
					
						
							| 
									
										
										
										
											2017-10-12 21:42:09 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 file.write(line) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-26 20:27:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def updateVersionDefine(version): | 
					
						
							|  |  |  |     with open(definePath, 'r') as file: | 
					
						
							|  |  |  |         lines = file.readlines() | 
					
						
							|  |  |  |     with open(definePath, 'w') as file: | 
					
						
							|  |  |  |         for line in lines: | 
					
						
							|  |  |  |             if '#define CATCH_VERSION_MAJOR' in line: | 
					
						
							|  |  |  |                 file.write('#define CATCH_VERSION_MAJOR {}\n'.format(version.majorVersion)) | 
					
						
							|  |  |  |             elif '#define CATCH_VERSION_MINOR' in line: | 
					
						
							|  |  |  |                 file.write('#define CATCH_VERSION_MINOR {}\n'.format(version.minorVersion)) | 
					
						
							|  |  |  |             elif '#define CATCH_VERSION_PATCH' in line: | 
					
						
							|  |  |  |                 file.write('#define CATCH_VERSION_PATCH {}\n'.format(version.patchNumber)) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 file.write(line) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 21:59:06 +02:00
										 |  |  | def performUpdates(version): | 
					
						
							|  |  |  |     # First update version file, so we can regenerate single header and | 
					
						
							|  |  |  |     # have it ready for upload to wandbox, when updating readme | 
					
						
							|  |  |  |     version.updateVersionFile() | 
					
						
							| 
									
										
										
										
											2018-01-26 20:27:19 +01:00
										 |  |  |     updateVersionDefine(version) | 
					
						
							| 
									
										
										
										
											2018-01-10 13:44:08 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-19 15:01:12 +01:00
										 |  |  |     import generateSingleHeader | 
					
						
							| 
									
										
										
										
											2017-08-24 21:59:06 +02:00
										 |  |  |     generateSingleHeader.generate(version) | 
					
						
							| 
									
										
										
										
											2018-01-10 13:44:08 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Then copy the reporters to single include folder to keep them in sync | 
					
						
							|  |  |  |     # We probably should have some kind of convention to select which reporters need to be copied automagically, | 
					
						
							|  |  |  |     # but this works for now | 
					
						
							|  |  |  |     import shutil | 
					
						
							|  |  |  |     for rep in ('automake', 'tap', 'teamcity'): | 
					
						
							|  |  |  |         sourceFile = os.path.join(catchPath, 'include/reporters/catch_reporter_{}.hpp'.format(rep)) | 
					
						
							| 
									
										
										
										
											2018-06-11 10:48:10 +02:00
										 |  |  |         destFile = os.path.join(catchPath, 'single_include', 'catch2', 'catch_reporter_{}.hpp'.format(rep)) | 
					
						
							| 
									
										
										
										
											2018-01-10 13:44:08 +01:00
										 |  |  |         shutil.copyfile(sourceFile, destFile) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-24 21:59:06 +02:00
										 |  |  |     updateReadmeFile(version) | 
					
						
							| 
									
										
										
										
											2017-10-12 21:42:09 +02:00
										 |  |  |     updateCmakeFile(version) |