blob: 688b13ce7445436aa6ad37796a4475e81d64d9b6 [file] [log] [blame]
Phil Nash21f7ef62015-06-29 18:05:23 +01001from __future__ import print_function
2
3import os
4import sys
5import re
6import string
7
8from scriptCommon import catchPath
9
Kevin Usheye04dc512017-03-16 11:17:45 -070010versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
Phil Nash21f7ef62015-06-29 18:05:23 +010011rootPath = os.path.join( catchPath, 'include/' )
Martin Hořeňovský93f84b52017-07-09 20:58:51 +020012versionPath = os.path.join( rootPath, "internal/catch_version.cpp" )
Phil Nash21f7ef62015-06-29 18:05:23 +010013readmePath = os.path.join( catchPath, "README.md" )
Uilian Ries34918042017-06-23 11:06:49 -030014conanPath = os.path.join(catchPath, 'conanfile.py')
Uilian Ries7013e382017-06-27 11:03:27 -030015conanTestPath = os.path.join(catchPath, 'test_package', 'conanfile.py')
Martin Hořeňovskýc7d9f022017-10-12 21:42:09 +020016cmakePath = os.path.join(catchPath, 'CMakeLists.txt')
Phil Nash21f7ef62015-06-29 18:05:23 +010017
18class Version:
19 def __init__(self):
20 f = open( versionPath, 'r' )
21 for line in f:
22 m = versionParser.match( line )
23 if m:
24 self.variableDecl = m.group(1)
25 self.majorVersion = int(m.group(2))
26 self.minorVersion = int(m.group(3))
27 self.patchNumber = int(m.group(4))
28 self.branchName = m.group(5)
29 self.buildNumber = int(m.group(6))
30 f.close()
31
32 def nonDevelopRelease(self):
33 if self.branchName != "":
34 self.branchName = ""
35 self.buildNumber = 0
36 def developBuild(self):
37 if self.branchName == "":
38 self.branchName = "develop"
39 self.buildNumber = 0
40
41 def incrementBuildNumber(self):
42 self.developBuild()
43 self.buildNumber = self.buildNumber+1
44
45 def incrementPatchNumber(self):
46 self.nonDevelopRelease()
47 self.patchNumber = self.patchNumber+1
48
49 def incrementMinorVersion(self):
50 self.nonDevelopRelease()
51 self.patchNumber = 0
52 self.minorVersion = self.minorVersion+1
53
54 def incrementMajorVersion(self):
55 self.nonDevelopRelease()
56 self.patchNumber = 0
57 self.minorVersion = 0
58 self.majorVersion = self.majorVersion+1
59
60 def getVersionString(self):
61 versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
62 if self.branchName != "":
63 versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
64 return versionString
65
66 def updateVersionFile(self):
67 f = open( versionPath, 'r' )
68 lines = []
69 for line in f:
70 m = versionParser.match( line )
71 if m:
72 lines.append( '{0}( {1}, {2}, {3}, "{4}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
73 else:
74 lines.append( line.rstrip() )
75 f.close()
76 f = open( versionPath, 'w' )
77 for line in lines:
78 f.write( line + "\n" )
79
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +020080def updateReadmeFile(version):
Martin Hořeňovský812bf212017-11-19 15:01:12 +010081 import updateWandbox
82
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +020083 downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' )
84 success, wandboxLink = updateWandbox.uploadFiles()
85 if not success:
86 print('Error when uploading to wandbox: {}'.format(wandboxLink))
87 exit(1)
88 f = open( readmePath, 'r' )
89 lines = []
90 for line in f:
91 lines.append( line.rstrip() )
92 f.close()
93 f = open( readmePath, 'w' )
94 for line in lines:
95 line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(version.getVersionString()) , line)
96 if '[![Try online](https://img.shields.io/badge/try-online-blue.svg)]' in line:
97 line = '[![Try online](https://img.shields.io/badge/try-online-blue.svg)]({0})'.format(wandboxLink)
98 f.write( line + "\n" )
99
100def updateConanFile(version):
101 conanParser = re.compile( r' version = "\d+\.\d+\.\d+.*"')
102 f = open( conanPath, 'r' )
103 lines = []
104 for line in f:
105 m = conanParser.match( line )
106 if m:
107 lines.append( ' version = "{0}"'.format(format(version.getVersionString())) )
108 else:
Phil Nash21f7ef62015-06-29 18:05:23 +0100109 lines.append( line.rstrip() )
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +0200110 f.close()
111 f = open( conanPath, 'w' )
112 for line in lines:
113 f.write( line + "\n" )
Phil Nash21f7ef62015-06-29 18:05:23 +0100114
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +0200115def updateConanTestFile(version):
116 conanParser = re.compile( r' requires = \"Catch\/\d+\.\d+\.\d+.*@%s\/%s\" % \(username, channel\)')
117 f = open( conanTestPath, 'r' )
118 lines = []
119 for line in f:
120 m = conanParser.match( line )
121 if m:
122 lines.append( ' requires = "Catch/{0}@%s/%s" % (username, channel)'.format(format(version.getVersionString())) )
123 else:
124 lines.append( line.rstrip() )
125 f.close()
126 f = open( conanTestPath, 'w' )
127 for line in lines:
128 f.write( line + "\n" )
Uilian Ries7013e382017-06-27 11:03:27 -0300129
Martin Hořeňovskýc7d9f022017-10-12 21:42:09 +0200130def updateCmakeFile(version):
131 cmakeParser = re.compile(r'set(CATCH_VERSION_NUMBER \d+\.\d+\.\d+)')
132 with open(cmakePath, 'r') as file:
133 lines = file.readlines()
134 with open(cmakePath, 'w') as file:
135 for line in lines:
136 if 'set(CATCH_VERSION_NUMBER ' in line:
137 file.write('set(CATCH_VERSION_NUMBER {0})\n'.format(version.getVersionString()))
138 else:
139 file.write(line)
140
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +0200141def performUpdates(version):
142 # First update version file, so we can regenerate single header and
143 # have it ready for upload to wandbox, when updating readme
144 version.updateVersionFile()
Martin Hořeňovský812bf212017-11-19 15:01:12 +0100145
146 import generateSingleHeader
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +0200147 generateSingleHeader.generate(version)
Martin Hořeňovský812bf212017-11-19 15:01:12 +0100148
Martin Hořeňovskýdee61df2017-08-24 21:59:06 +0200149 updateReadmeFile(version)
150 updateConanFile(version)
151 updateConanTestFile(version)
Martin Hořeňovskýc7d9f022017-10-12 21:42:09 +0200152 updateCmakeFile(version)