MCPcopy
hub / github.com/iaddis/metalnes / generate

Function generate

external/Catch2/scripts/generateSingleHeader.py:14–146  ·  view source on GitHub ↗
(v)

Source from the content-addressed store, hash-verified

12from scriptCommon import catchPath
13
14def generate(v):
15 includesParser = re.compile( r'\s*#\s*include\s*"(.*)"' )
16 guardParser = re.compile( r'\s*#.*(TWOBLUECUBES_)?CATCH_.*_INCLUDED')
17 defineParser = re.compile( r'\s*#define\s+(TWOBLUECUBES_)?CATCH_.*_INCLUDED')
18 ifParser = re.compile( r'\s*#ifndef (TWOBLUECUBES_)?CATCH_.*_INCLUDED')
19 endIfParser = re.compile( r'\s*#endif // (TWOBLUECUBES_)?CATCH_.*_INCLUDED')
20 ifImplParser = re.compile( r'\s*#ifdef CATCH_CONFIG_RUNNER' )
21 commentParser1 = re.compile( r'^\s*/\*')
22 commentParser2 = re.compile( r'^ \*')
23 blankParser = re.compile( r'^\s*$')
24
25 seenHeaders = set([])
26 possibleHeaders = set([])
27 rootPath = os.path.join( catchPath, 'include/' )
28 outputPath = os.path.join( catchPath, 'single_include/catch2/catch.hpp' )
29
30 globals = {
31 'includeImpl' : True,
32 'ifdefs' : 0,
33 'implIfDefs' : -1
34 }
35
36 for arg in sys.argv[1:]:
37 arg = arg.lower()
38 if arg == "noimpl":
39 globals['includeImpl'] = False
40 print( "Not including impl code" )
41 else:
42 print( "\n** Unrecognised argument: " + arg + " **\n" )
43 exit(1)
44
45
46 # ensure that the output directory exists (hopefully no races)
47 outDir = os.path.dirname(outputPath)
48 if not os.path.exists(outDir):
49 os.makedirs(outDir)
50 out = io.open( outputPath, 'w', newline='\n', encoding='utf-8')
51
52 def write( line ):
53 if globals['includeImpl'] or globals['implIfDefs'] == -1:
54 out.write( line )
55
56 def getDirsToSearch( ):
57 return [os.path.join( rootPath, s) for s in ['', 'internal', 'reporters', 'internal/benchmark', 'internal/benchmark/detail']]
58
59 def collectPossibleHeaders():
60 dirs = getDirsToSearch()
61 for dir in dirs:
62 hpps = glob(os.path.join(dir, '*.hpp'))
63 hs = glob(os.path.join(dir, '*.h'))
64 possibleHeaders.update( hpp.rpartition( os.sep )[2] for hpp in hpps )
65 possibleHeaders.update( h.rpartition( os.sep )[2] for h in hs )
66
67
68 def insertCpps():
69 dirs = getDirsToSearch()
70 cppFiles = []
71 for dir in dirs:

Callers 1

Calls 6

writeFunction · 0.85
collectPossibleHeadersFunction · 0.85
parseFileFunction · 0.85
warnUnparsedHeadersFunction · 0.85
getVersionStringMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected