blob: 9a62690d4842ed371f148a950e40dc492b8091d5 [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/' )
12versionPath = os.path.join( rootPath, "internal/catch_version.hpp" )
13readmePath = 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')
Phil Nash21f7ef62015-06-29 18:05:23 +010016
17class Version:
18 def __init__(self):
19 f = open( versionPath, 'r' )
20 for line in f:
21 m = versionParser.match( line )
22 if m:
23 self.variableDecl = m.group(1)
24 self.majorVersion = int(m.group(2))
25 self.minorVersion = int(m.group(3))
26 self.patchNumber = int(m.group(4))
27 self.branchName = m.group(5)
28 self.buildNumber = int(m.group(6))
29 f.close()
30
31 def nonDevelopRelease(self):
32 if self.branchName != "":
33 self.branchName = ""
34 self.buildNumber = 0
35 def developBuild(self):
36 if self.branchName == "":
37 self.branchName = "develop"
38 self.buildNumber = 0
39
40 def incrementBuildNumber(self):
41 self.developBuild()
42 self.buildNumber = self.buildNumber+1
43
44 def incrementPatchNumber(self):
45 self.nonDevelopRelease()
46 self.patchNumber = self.patchNumber+1
47
48 def incrementMinorVersion(self):
49 self.nonDevelopRelease()
50 self.patchNumber = 0
51 self.minorVersion = self.minorVersion+1
52
53 def incrementMajorVersion(self):
54 self.nonDevelopRelease()
55 self.patchNumber = 0
56 self.minorVersion = 0
57 self.majorVersion = self.majorVersion+1
58
59 def getVersionString(self):
60 versionString = '{0}.{1}.{2}'.format( self.majorVersion, self.minorVersion, self.patchNumber )
61 if self.branchName != "":
62 versionString = versionString + '-{0}.{1}'.format( self.branchName, self.buildNumber )
63 return versionString
64
65 def updateVersionFile(self):
66 f = open( versionPath, 'r' )
67 lines = []
68 for line in f:
69 m = versionParser.match( line )
70 if m:
71 lines.append( '{0}( {1}, {2}, {3}, "{4}", {5} );'.format( self.variableDecl, self.majorVersion, self.minorVersion, self.patchNumber, self.branchName, self.buildNumber ) )
72 else:
73 lines.append( line.rstrip() )
74 f.close()
75 f = open( versionPath, 'w' )
76 for line in lines:
77 f.write( line + "\n" )
78
79 def updateReadmeFile(self):
Martin Hořeňovský73872202017-01-26 13:12:14 +010080 downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' )
Phil Nash21f7ef62015-06-29 18:05:23 +010081 f = open( readmePath, 'r' )
82 lines = []
83 for line in f:
84 lines.append( line.rstrip() )
85 f.close()
86 f = open( readmePath, 'w' )
87 for line in lines:
Martin Hořeňovský73872202017-01-26 13:12:14 +010088 line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(self.getVersionString()) , line)
89 f.write( line + "\n" )
Phil Nash21f7ef62015-06-29 18:05:23 +010090
Uilian Ries34918042017-06-23 11:06:49 -030091 def updateConanFile(self):
92 conanParser = re.compile( r' version = "\d+\.\d+\.\d+.*"')
93 f = open( conanPath, 'r' )
94 lines = []
95 for line in f:
96 m = conanParser.match( line )
97 if m:
98 lines.append( ' version = "{0}"'.format(format(self.getVersionString())) )
99 else:
100 lines.append( line.rstrip() )
101 f.close()
102 f = open( conanPath, 'w' )
103 for line in lines:
104 f.write( line + "\n" )
Uilian Ries7013e382017-06-27 11:03:27 -0300105
106 def updateConanTestFile(self):
107 conanParser = re.compile( r' requires = \"Catch\/\d+\.\d+\.\d+.*@%s\/%s\" % \(username, channel\)')
108 f = open( conanTestPath, 'r' )
109 lines = []
110 for line in f:
111 m = conanParser.match( line )
112 if m:
113 lines.append( ' requires = "Catch/{0}@%s/%s" % (username, channel)'.format(format(self.getVersionString())) )
114 else:
115 lines.append( line.rstrip() )
116 f.close()
117 f = open( conanTestPath, 'w' )
118 for line in lines:
119 f.write( line + "\n" )