@@ -746,10 +746,10 @@ def main():
746746 help = 'directory from which files are read' )
747747 parser .add_argument ('--write-dir' , default = "build" ,
748748 help = 'directory into which files are written' )
749- parser .add_argument ('--prefix' , default = "" ,
750- help = 'prefix for build files' )
751749 parser .add_argument ('--line' , action = 'store_true' , default = False ,
752750 help = 'add line directive to input files into build files' )
751+ parser .add_argument ('--recursive' , action = 'store_true' , default = False ,
752+ help = 'scan input directory recursively when no files are specified' )
753753 parser .add_argument ('file' , nargs = '*' ,
754754 help = 'file to compile' )
755755 args = parser .parse_args ()
@@ -758,38 +758,34 @@ def main():
758758 line_directive = args .line
759759 files = args .file
760760
761+ if len (files ) > 0 and args .recursive :
762+ print ('--recursive has not effect since files were explicitly specified.' )
763+
761764 # Check if we are invoked from the right place
762765 if not os .path .exists (lib_dir ):
763766 print ('Directory "' + lib_dir + '"not found.' )
764767 sys .exit (- 1 )
765768
766769 # Create build directory if needed
767- try :
768- os .makedirs (build_dir )
769- except OSError as e :
770- # due to race condition in case of parallel build,
771- # makedirs may fail. Ignore that; if there's actual
772- # problem with directory creation, it'll be caught
773- # by the following isdir check
774- if e .errno != errno .EEXIST :
775- raise
770+ os .makedirs (build_dir , exist_ok = True )
776771
777772 if not os .path .isdir (build_dir ):
778773 raise Exception (build_dir + ' is not a directory' )
779774
780- mc = MatchCompiler (verify_mode = args .verify ,
781- show_skipped = args .show_skipped )
782-
783775 if not files :
784776 # select all *.cpp files in lib_dir
785- for f in glob .glob (lib_dir + '/*.cpp' ):
777+ for f in glob .glob (lib_dir + '/**/* .cpp' , recursive = args . recursive ):
786778 files .append (f [len (lib_dir ) + 1 :])
787779
780+ mc = MatchCompiler (verify_mode = args .verify ,
781+ show_skipped = args .show_skipped )
782+
788783 # convert files
789784 for fi in files :
790- pi = lib_dir + '/' + fi
791- fo = args .prefix + fi
792- po = build_dir + '/' + fo
785+ pi = os .path .join (lib_dir , fi )
786+ po = os .path .join (build_dir , fi )
787+ if args .recursive :
788+ os .makedirs (os .path .dirname (po ), exist_ok = True )
793789 print (pi + ' => ' + po )
794790 mc .convertFile (pi , po , line_directive )
795791
0 commit comments