| 
									
										
										
										
											2014-03-08 11:31:38 +01:00
										 |  |  | from  __future__ import  print_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import re | 
					
						
							|  |  |  | import datetime | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | import string | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:58:57 +01:00
										 |  |  | from scriptCommon import catchPath | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | from releaseCommon import Version | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:58:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | includesParser = re.compile( r'\s*#include\s*"(.*)"' ) | 
					
						
							| 
									
										
										
										
											2014-02-11 18:11:37 +00:00
										 |  |  | guardParser = re.compile( r'\s*#.*TWOBLUECUBES_CATCH_.*_INCLUDED') | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | defineParser = re.compile( r'\s*#define') | 
					
						
							| 
									
										
										
										
											2014-02-11 18:11:37 +00:00
										 |  |  | ifParser = re.compile( r'\s*#ifndef TWOBLUECUBES_CATCH_.*_INCLUDED') | 
					
						
							|  |  |  | endIfParser = re.compile( r'\s*#endif // TWOBLUECUBES_CATCH_.*_INCLUDED') | 
					
						
							| 
									
										
										
										
											2014-06-02 07:47:24 +01:00
										 |  |  | ifImplParser = re.compile( r'\s*#ifdef CATCH_CONFIG_RUNNER' ) | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | commentParser1 = re.compile( r'^\s*/\*') | 
					
						
							| 
									
										
										
										
											2014-07-11 07:45:41 +01:00
										 |  |  | commentParser2 = re.compile( r'^ \*') | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | blankParser = re.compile( r'^\s*$') | 
					
						
							|  |  |  | seenHeaders = set([]) | 
					
						
							| 
									
										
										
										
											2013-04-24 18:58:57 +01:00
										 |  |  | rootPath = os.path.join( catchPath, 'include/' ) | 
					
						
							| 
									
										
										
										
											2013-04-24 20:19:05 +01:00
										 |  |  | outputPath = os.path.join( catchPath, 'single_include/catch.hpp' ) | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | includeImpl = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for arg in sys.argv[1:]: | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |     arg = string.lower(arg) | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  |     if arg == "noimpl": | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |         includeImpl = False | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  |         print( "Not including impl code" ) | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2014-03-08 11:31:38 +01:00
										 |  |  |         print( "\n** Unrecognised argument: " + arg + " **\n" ) | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |         exit(1) | 
					
						
							| 
									
										
										
										
											2013-03-04 12:19:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 20:19:05 +01:00
										 |  |  | out = open( outputPath, 'w' ) | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | ifdefs = 0 | 
					
						
							|  |  |  | implIfDefs = -1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def write( line ): | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |     if includeImpl or implIfDefs == -1: | 
					
						
							|  |  |  |         out.write( line ) | 
					
						
							| 
									
										
										
										
											2013-04-24 20:19:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | def parseFile( path, filename ): | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |     global ifdefs | 
					
						
							|  |  |  |     global implIfDefs | 
					
						
							| 
									
										
										
										
											2013-12-03 18:52:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |     f = open( path + filename, 'r' ) | 
					
						
							|  |  |  |     blanks = 0 | 
					
						
							|  |  |  |     for line in f: | 
					
						
							|  |  |  |         if ifParser.match( line ): | 
					
						
							|  |  |  |             ifdefs = ifdefs + 1 | 
					
						
							|  |  |  |         elif endIfParser.match( line ): | 
					
						
							|  |  |  |             ifdefs = ifdefs - 1 | 
					
						
							| 
									
										
										
										
											2014-06-02 07:47:24 +01:00
										 |  |  |             if ifdefs == implIfDefs: | 
					
						
							|  |  |  |                 implIfDefs = -1 | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |         m = includesParser.match( line ) | 
					
						
							|  |  |  |         if m: | 
					
						
							|  |  |  |             header = m.group(1) | 
					
						
							|  |  |  |             headerPath, sep, headerFile = header.rpartition( "/" ) | 
					
						
							|  |  |  |             if not headerFile in seenHeaders: | 
					
						
							| 
									
										
										
										
											2014-02-11 18:11:37 +00:00
										 |  |  |                 if headerFile != "tbc_text_format.h" and headerFile != "clara.h": | 
					
						
							|  |  |  |                     seenHeaders.add( headerFile ) | 
					
						
							| 
									
										
										
										
											2013-12-04 20:25:14 +00:00
										 |  |  |                 write( "// #included from: {0}\n".format( header ) ) | 
					
						
							|  |  |  |                 if( headerPath == "internal" and path.endswith( "internal/" ) ): | 
					
						
							|  |  |  |                     headerPath = "" | 
					
						
							|  |  |  |                     sep = "" | 
					
						
							|  |  |  |                 if os.path.exists( path + headerPath + sep + headerFile ): | 
					
						
							|  |  |  |                     parseFile( path + headerPath + sep, headerFile ) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     parseFile( rootPath + headerPath + sep, headerFile ) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             if ifImplParser.match(line): | 
					
						
							|  |  |  |                 implIfDefs = ifdefs | 
					
						
							|  |  |  |             if (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ): | 
					
						
							|  |  |  |                 if blankParser.match( line ): | 
					
						
							|  |  |  |                     blanks = blanks + 1 | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     blanks = 0 | 
					
						
							|  |  |  |                 if blanks < 2: | 
					
						
							|  |  |  |                     write( line.rstrip() + "\n" ) | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-16 20:43:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | v = Version() | 
					
						
							|  |  |  | out.write( "/*\n" ) | 
					
						
							|  |  |  | out.write( " *  Catch v{0}\n".format( v.getVersionString() ) ) | 
					
						
							|  |  |  | out.write( " *  Generated: {0}\n".format( datetime.datetime.now() ) ) | 
					
						
							|  |  |  | out.write( " *  ----------------------------------------------------------\n" ) | 
					
						
							|  |  |  | out.write( " *  This file has been merged from multiple headers. Please don't edit it directly\n" ) | 
					
						
							|  |  |  | out.write( " *  Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.\n" ) | 
					
						
							|  |  |  | out.write( " *\n" ) | 
					
						
							|  |  |  | out.write( " *  Distributed under the Boost Software License, Version 1.0. (See accompanying\n" ) | 
					
						
							|  |  |  | out.write( " *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n" ) | 
					
						
							|  |  |  | out.write( " */\n" ) | 
					
						
							|  |  |  | out.write( "#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" ) | 
					
						
							|  |  |  | out.write( "#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" ) | 
					
						
							| 
									
										
										
										
											2014-03-08 11:31:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | parseFile( rootPath, 'catch.hpp' ) | 
					
						
							| 
									
										
										
										
											2014-03-08 11:31:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | out.write( "#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" ) | 
					
						
							| 
									
										
										
										
											2012-11-15 22:15:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-29 18:05:23 +01:00
										 |  |  | print ("Generated single include for Catch v{0}\n".format( v.getVersionString() ) ) |