Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorPhil Nash2017-06-20 18:03:37 +0100
committerPhil Nash2017-06-20 18:03:47 +0100
commitda5964af782fc6dc1d7c8f19507e967f3a286ca9 (patch)
tree8af8a11eb1735dbd8a4080d449cc6a75318c5e1b /scripts
parentee0defb93900f1b8fdf65dfcbd2db1b1f33137bd (diff)
downloadcatch3-da5964af782fc6dc1d7c8f19507e967f3a286ca9.tar.gz
Updated version of Clara (should fix Windows compile issues)
- embedded using new embed script
Diffstat (limited to 'scripts')
-rw-r--r--scripts/embed.py73
-rw-r--r--scripts/embedClara.py24
2 files changed, 97 insertions, 0 deletions
diff --git a/scripts/embed.py b/scripts/embed.py
new file mode 100644
index 00000000..85a7fcfb
--- /dev/null
+++ b/scripts/embed.py
@@ -0,0 +1,73 @@
+import re
+
+preprocessorRe = re.compile( r'\s*#.*' )
+
+fdefineRe = re.compile( r'\s*#\s*define\s*(\S*)\s*\(' ) # #defines that take arguments
+defineRe = re.compile( r'\s*#\s*define\s*(\S*)(\s+)(.*)' ) # all #defines
+undefRe = re.compile( r'\s*#\s*undef\s*(\S*)' ) # all #undefs
+
+ifdefCommonRe = re.compile( r'\s*#\s*if' ) # all #ifdefs
+ifdefRe = re.compile( r'\s*#\s*ifdef\s*(\S*)' )
+ifndefRe = re.compile( r'\s*#\s*ifndef\s*(\S*)' )
+endifRe = re.compile( r'\s*#\s*endif\s*//\s*(.*)' )
+elseRe = re.compile( r'\s*#\s*else' )
+ifRe = re.compile( r'\s*#\s*if\s+(.*)' )
+
+nsRe = re.compile( r'(.*?\s*\s*namespace\s+)(\w+)(\s*{?)(.*)' )
+nsCloseRe = re.compile( r'(.*\s*})(\s*\/\/\s*namespace\s+)(\w+)(\s*)(.*)' )
+
+
+class LineMapper:
+ def __init__( self, idMap, outerNamespace ):
+ self.idMap = idMap
+ self.outerNamespace = outerNamespace
+
+ def replaceId( self, lineNo, id ):
+ if not self.idMap.has_key( id ):
+ raise ValueError( "Unrecognised macro identifier: '{0}' on line: {1}".format( id, lineNo ) )
+ subst = self.idMap[id]
+ if subst == "":
+ return id
+ else:
+ return subst
+
+ # TBD:
+ # #if, #ifdef, comments after #else
+ def mapLine( self, lineNo, line ):
+ m = ifndefRe.match( line )
+ if m:
+ return "#ifndef " + self.replaceId( lineNo, m.group(1)) + "\n"
+ m = defineRe.match( line )
+ if m:
+ return "#define {0}{1}{2}\n".format( self.replaceId( lineNo, m.group(1)), m.group(2), m.group(3) )
+ m = endifRe.match( line )
+ if m:
+ return "#endif // " + self.replaceId( lineNo, m.group(1)) + "\n"
+ m = nsCloseRe.match( line )
+ if m:
+ originalNs = m.group(3)
+ # print("[{0}] originalNs: '{1}' - closing".format(lineNo, originalNs))
+ # print( " " + line )
+ # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]\n 5:[{4}]".format( m.group(1), m.group(2), m.group(3), m.group(4), m.group(5) ) )
+ if self.outerNamespace.has_key(originalNs):
+ outerNs, innerNs = self.outerNamespace[originalNs]
+ return "{0}}}{1}{2}::{3}{4}{5}\n".format( m.group(1), m.group(2), outerNs, innerNs, m.group(4), m.group(5))
+ m = nsRe.match( line )
+ if m:
+ originalNs = m.group(2)
+ # print("[{0}] originalNs: '{1}'".format(lineNo, originalNs))
+ # print( " " + line )
+ # print( " 1:[{0}]\n 2:[{1}]\n 3:[{2}]\n 4:[{3}]".format( m.group(1), m.group(2), m.group(3), m.group(4) ) )
+ if self.outerNamespace.has_key(originalNs):
+ outerNs, innerNs = self.outerNamespace[originalNs]
+ return "{0}{1} {{ namespace {2}{3}{4}\n".format( m.group(1), outerNs, innerNs, m.group(3), m.group(4) )
+ return line
+
+ def mapFile(self, filenameIn, filenameOut ):
+ print( "Embedding:\n {0}\nas:\n {1}".format( filenameIn, filenameOut ) )
+ with open( filenameIn, 'r' ) as f, open( filenameOut, 'w' ) as outf:
+ lineNo = 1
+ for line in f:
+ outf.write( self.mapLine( lineNo, line ) )
+ lineNo = lineNo + 1
+ print( "Written {0} lines".format( lineNo ) ) \ No newline at end of file
diff --git a/scripts/embedClara.py b/scripts/embedClara.py
new file mode 100644
index 00000000..a35c221e
--- /dev/null
+++ b/scripts/embedClara.py
@@ -0,0 +1,24 @@
+# Execute this script any time you import a new copy of Clara into the third_party area
+import os
+import sys
+import embed
+
+rootPath = os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0])))
+
+filename = os.path.join( rootPath, "third_party", "clara.hpp" )
+outfilename = os.path.join( rootPath, "include", "external", "clara.hpp" )
+
+
+# Mapping of pre-processor identifiers
+idMap = {
+ "CLARA_HPP_INCLUDED": "CATCH_CLARA_HPP_INCLUDED",
+ "CLARA_CONFIG_CONSOLE_WIDTH": "CATCH_CLARA_CONFIG_CONSOLE_WIDTH",
+ "CLARA_TEXTFLOW_HPP_INCLUDED": "CATCH_CLARA_TEXTFLOW_HPP_INCLUDED",
+ "CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH": "CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH"
+ }
+
+# outer namespace to add
+outerNamespace = { "clara": ("Catch", "clara") }
+
+mapper = embed.LineMapper( idMap, outerNamespace )
+mapper.mapFile( filename, outfilename ) \ No newline at end of file