mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Update single header generation script to warn about unused headers
This commit is contained in:
parent
cfba9dce97
commit
9a8963133f
@ -23,6 +23,7 @@ def generate(v):
|
|||||||
blankParser = re.compile( r'^\s*$')
|
blankParser = re.compile( r'^\s*$')
|
||||||
|
|
||||||
seenHeaders = set([])
|
seenHeaders = set([])
|
||||||
|
possibleHeaders = set([])
|
||||||
rootPath = os.path.join( catchPath, 'include/' )
|
rootPath = os.path.join( catchPath, 'include/' )
|
||||||
outputPath = os.path.join( catchPath, 'single_include/catch2/catch.hpp' )
|
outputPath = os.path.join( catchPath, 'single_include/catch2/catch.hpp' )
|
||||||
|
|
||||||
@ -52,8 +53,20 @@ def generate(v):
|
|||||||
if globals['includeImpl'] or globals['implIfDefs'] == -1:
|
if globals['includeImpl'] or globals['implIfDefs'] == -1:
|
||||||
out.write( line )
|
out.write( line )
|
||||||
|
|
||||||
|
def getDirsToSearch( ):
|
||||||
|
return [os.path.join( rootPath, s) for s in ['', 'internal', 'reporters', 'internal/benchmark', 'internal/benchmark/detail']]
|
||||||
|
|
||||||
|
def collectPossibleHeaders():
|
||||||
|
dirs = getDirsToSearch()
|
||||||
|
for dir in dirs:
|
||||||
|
hpps = glob(os.path.join(dir, '*.hpp'))
|
||||||
|
hs = glob(os.path.join(dir, '*.h'))
|
||||||
|
possibleHeaders.update( hpp.rpartition( os.sep )[2] for hpp in hpps )
|
||||||
|
possibleHeaders.update( h.rpartition( os.sep )[2] for h in hs )
|
||||||
|
|
||||||
|
|
||||||
def insertCpps():
|
def insertCpps():
|
||||||
dirs = [os.path.join( rootPath, s) for s in ['', 'internal', 'reporters', 'internal/benchmark', 'internal/benchmark/detail']]
|
dirs = getDirsToSearch()
|
||||||
cppFiles = []
|
cppFiles = []
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
cppFiles += glob(os.path.join(dir, '*.cpp'))
|
cppFiles += glob(os.path.join(dir, '*.cpp'))
|
||||||
@ -103,6 +116,13 @@ def generate(v):
|
|||||||
write( line.rstrip() + "\n" )
|
write( line.rstrip() + "\n" )
|
||||||
write( u'// end {}\n'.format(filename) )
|
write( u'// end {}\n'.format(filename) )
|
||||||
|
|
||||||
|
def warnUnparsedHeaders():
|
||||||
|
unparsedHeaders = possibleHeaders.difference( seenHeaders )
|
||||||
|
# These headers aren't packaged into the unified header, exclude them from any warning
|
||||||
|
whitelist = ['catch.hpp', 'catch_reporter_teamcity.hpp', 'catch_with_main.hpp', 'catch_reporter_automake.hpp', 'catch_reporter_tap.hpp', 'catch_reporter_sonarqube.hpp']
|
||||||
|
unparsedHeaders = unparsedHeaders.difference( whitelist )
|
||||||
|
if unparsedHeaders:
|
||||||
|
print( "WARNING: unparsed headers detected\n{0}\n".format( unparsedHeaders ) )
|
||||||
|
|
||||||
write( u"/*\n" )
|
write( u"/*\n" )
|
||||||
write( u" * Catch v{0}\n".format( v.getVersionString() ) )
|
write( u" * Catch v{0}\n".format( v.getVersionString() ) )
|
||||||
@ -117,11 +137,13 @@ def generate(v):
|
|||||||
write( u"#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
|
write( u"#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
|
||||||
write( u"#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
|
write( u"#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n" )
|
||||||
|
|
||||||
|
collectPossibleHeaders()
|
||||||
parseFile( rootPath, 'catch.hpp' )
|
parseFile( rootPath, 'catch.hpp' )
|
||||||
|
warnUnparsedHeaders()
|
||||||
|
|
||||||
write( u"#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" )
|
write( u"#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED\n\n" )
|
||||||
out.close()
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user