Refactor release scripts, automatically update Wandbox on release

This commit is contained in:
Martin Hořeňovský 2017-08-24 21:59:06 +02:00
parent 6c09b45a20
commit dee61df274
6 changed files with 217 additions and 160 deletions

View File

@ -10,9 +10,8 @@ import string
from glob import glob from glob import glob
from scriptCommon import catchPath from scriptCommon import catchPath
from releaseCommon import Version
def generate(v):
includesParser = re.compile( r'\s*#\s*include\s*"(.*)"' ) includesParser = re.compile( r'\s*#\s*include\s*"(.*)"' )
guardParser = re.compile( r'\s*#.*(TWOBLUECUBES_)?CATCH_.*_INCLUDED') guardParser = re.compile( r'\s*#.*(TWOBLUECUBES_)?CATCH_.*_INCLUDED')
defineParser = re.compile( r'\s*#define\s+(TWOBLUECUBES_)?CATCH_.*_INCLUDED') defineParser = re.compile( r'\s*#define\s+(TWOBLUECUBES_)?CATCH_.*_INCLUDED')
@ -27,12 +26,16 @@ seenHeaders = set([])
rootPath = os.path.join( catchPath, 'include/' ) rootPath = os.path.join( catchPath, 'include/' )
outputPath = os.path.join( catchPath, 'single_include/catch.hpp' ) outputPath = os.path.join( catchPath, 'single_include/catch.hpp' )
includeImpl = True globals = {
'includeImpl' : True,
'ifdefs' : 0,
'implIfDefs' : -1
}
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
arg = string.lower(arg) arg = string.lower(arg)
if arg == "noimpl": if arg == "noimpl":
includeImpl = False globals['includeImpl'] = False
print( "Not including impl code" ) print( "Not including impl code" )
else: else:
print( "\n** Unrecognised argument: " + arg + " **\n" ) print( "\n** Unrecognised argument: " + arg + " **\n" )
@ -44,11 +47,9 @@ outDir = os.path.dirname(outputPath)
if not os.path.exists(outDir): if not os.path.exists(outDir):
os.makedirs(outDir) os.makedirs(outDir)
out = open( outputPath, 'w' ) out = open( outputPath, 'w' )
ifdefs = 0
implIfDefs = -1
def write( line ): def write( line ):
if includeImpl or implIfDefs == -1: if globals['includeImpl'] or globals['implIfDefs'] == -1:
out.write( line ) out.write( line )
def insertCpps(): def insertCpps():
@ -62,9 +63,6 @@ def insertCpps():
parseFile(dir, name) parseFile(dir, name)
def parseFile( path, filename ): def parseFile( path, filename ):
global ifdefs
global implIfDefs
f = open( os.path.join(path, filename), 'r' ) f = open( os.path.join(path, filename), 'r' )
blanks = 0 blanks = 0
write( "// start {0}\n".format( filename ) ) write( "// start {0}\n".format( filename ) )
@ -73,11 +71,11 @@ def parseFile( path, filename ):
insertCpps() insertCpps()
continue continue
elif ifParser.match( line ): elif ifParser.match( line ):
ifdefs = ifdefs + 1 globals['ifdefs'] += 1
elif endIfParser.match( line ): elif endIfParser.match( line ):
ifdefs = ifdefs - 1 globals['ifdefs'] -= 1
if ifdefs == implIfDefs: if globals['ifdefs'] == globals['implIfDefs']:
implIfDefs = -1 globals['implIfDefs'] = -1
m = includesParser.match( line ) m = includesParser.match( line )
if m: if m:
header = m.group(1) header = m.group(1)
@ -94,7 +92,7 @@ def parseFile( path, filename ):
parseFile( rootPath + headerPath + sep, headerFile ) parseFile( rootPath + headerPath + sep, headerFile )
else: else:
if ifImplParser.match(line): if ifImplParser.match(line):
implIfDefs = ifdefs globals['implIfDefs'] = globals['ifdefs']
if (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ): if (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ):
if blankParser.match( line ): if blankParser.match( line ):
blanks = blanks + 1 blanks = blanks + 1
@ -105,7 +103,6 @@ def parseFile( path, filename ):
write( '// end {}\n'.format(filename) ) write( '// end {}\n'.format(filename) )
v = Version()
out.write( "/*\n" ) out.write( "/*\n" )
out.write( " * Catch v{0}\n".format( v.getVersionString() ) ) out.write( " * Catch v{0}\n".format( v.getVersionString() ) )
out.write( " * Generated: {0}\n".format( datetime.datetime.now() ) ) out.write( " * Generated: {0}\n".format( datetime.datetime.now() ) )
@ -122,5 +119,10 @@ out.write( "#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
parseFile( rootPath, 'catch.hpp' ) parseFile( rootPath, 'catch.hpp' )
out.write( "#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" ) out.write( "#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" )
out.close()
print ("Generated single include for Catch v{0}\n".format( v.getVersionString() ) ) print ("Generated single include for Catch v{0}\n".format( v.getVersionString() ) )
if __name__ == '__main__':
from releaseCommon import Version
generate(Version())

View File

@ -1,13 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
from releaseCommon import Version import releaseCommon
v = Version() v = releaseCommon.Version()
v.incrementMajorVersion() v.incrementMajorVersion()
v.updateVersionFile() releaseCommon.performUpdates(v)
v.updateReadmeFile()
v.updateConanFile()
v.updateConanTestFile()
print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) ) print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) )

View File

@ -1,13 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
from releaseCommon import Version import releaseCommon
v = Version() v = releaseCommon.Version()
v.incrementMinorVersion() v.incrementMinorVersion()
v.updateVersionFile() releaseCommon.performUpdates(v)
v.updateReadmeFile()
v.updateConanFile()
v.updateConanTestFile()
print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) ) print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) )

View File

@ -1,13 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function from __future__ import print_function
from releaseCommon import Version import releaseCommon
v = Version() v = releaseCommon.Version()
v.incrementPatchNumber() v.incrementPatchNumber()
v.updateVersionFile() releaseCommon.performUpdates(v)
v.updateReadmeFile()
v.updateConanFile()
v.updateConanTestFile()
print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) ) print( "Updated Version.hpp, README and Conan to v{0}".format( v.getVersionString() ) )

View File

@ -6,6 +6,8 @@ import re
import string import string
from scriptCommon import catchPath from scriptCommon import catchPath
import generateSingleHeader
import updateWandbox
versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' ) versionParser = re.compile( r'(\s*static\sVersion\sversion)\s*\(\s*(.*)\s*,\s*(.*)\s*,\s*(.*)\s*,\s*\"(.*)\"\s*,\s*(.*)\s*\).*' )
rootPath = os.path.join( catchPath, 'include/' ) rootPath = os.path.join( catchPath, 'include/' )
@ -76,8 +78,12 @@ class Version:
for line in lines: for line in lines:
f.write( line + "\n" ) f.write( line + "\n" )
def updateReadmeFile(self): def updateReadmeFile(version):
downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' ) downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' )
success, wandboxLink = updateWandbox.uploadFiles()
if not success:
print('Error when uploading to wandbox: {}'.format(wandboxLink))
exit(1)
f = open( readmePath, 'r' ) f = open( readmePath, 'r' )
lines = [] lines = []
for line in f: for line in f:
@ -85,17 +91,19 @@ class Version:
f.close() f.close()
f = open( readmePath, 'w' ) f = open( readmePath, 'w' )
for line in lines: for line in lines:
line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(self.getVersionString()) , line) line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(version.getVersionString()) , line)
if '[![Try online](https://img.shields.io/badge/try-online-blue.svg)]' in line:
line = '[![Try online](https://img.shields.io/badge/try-online-blue.svg)]({0})'.format(wandboxLink)
f.write( line + "\n" ) f.write( line + "\n" )
def updateConanFile(self): def updateConanFile(version):
conanParser = re.compile( r' version = "\d+\.\d+\.\d+.*"') conanParser = re.compile( r' version = "\d+\.\d+\.\d+.*"')
f = open( conanPath, 'r' ) f = open( conanPath, 'r' )
lines = [] lines = []
for line in f: for line in f:
m = conanParser.match( line ) m = conanParser.match( line )
if m: if m:
lines.append( ' version = "{0}"'.format(format(self.getVersionString())) ) lines.append( ' version = "{0}"'.format(format(version.getVersionString())) )
else: else:
lines.append( line.rstrip() ) lines.append( line.rstrip() )
f.close() f.close()
@ -103,17 +111,26 @@ class Version:
for line in lines: for line in lines:
f.write( line + "\n" ) f.write( line + "\n" )
def updateConanTestFile(self): def updateConanTestFile(version):
conanParser = re.compile( r' requires = \"Catch\/\d+\.\d+\.\d+.*@%s\/%s\" % \(username, channel\)') conanParser = re.compile( r' requires = \"Catch\/\d+\.\d+\.\d+.*@%s\/%s\" % \(username, channel\)')
f = open( conanTestPath, 'r' ) f = open( conanTestPath, 'r' )
lines = [] lines = []
for line in f: for line in f:
m = conanParser.match( line ) m = conanParser.match( line )
if m: if m:
lines.append( ' requires = "Catch/{0}@%s/%s" % (username, channel)'.format(format(self.getVersionString())) ) lines.append( ' requires = "Catch/{0}@%s/%s" % (username, channel)'.format(format(version.getVersionString())) )
else: else:
lines.append( line.rstrip() ) lines.append( line.rstrip() )
f.close() f.close()
f = open( conanTestPath, 'w' ) f = open( conanTestPath, 'w' )
for line in lines: for line in lines:
f.write( line + "\n" ) f.write( line + "\n" )
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()
generateSingleHeader.generate(version)
updateReadmeFile(version)
updateConanFile(version)
updateConanTestFile(version)

47
scripts/updateWandbox.py Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python
import json
import os
import urllib2
from scriptCommon import catchPath
def upload(options):
request = urllib2.Request('http://melpon.org/wandbox/api/compile.json')
request.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(request, json.dumps(options))
return json.loads(response.read())
main_file = '''
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}
'''
def uploadFiles():
response = upload({
'compiler': 'gcc-head',
'code': main_file,
'codes': [{
'file': 'catch.hpp',
'code': open(os.path.join(catchPath, 'single_include', 'catch.hpp')).read()
}],
'options': 'c++11,cpp-no-pedantic,boost-nothing',
'compiler-option-raw': '-DCATCH_CONFIG_FAST_COMPILE',
'save': True
})
if 'status' in response and not 'compiler_error' in response:
return True, response['url']
else:
return False, response