MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / main

Function main

tools/matchcompiler.py:749–808  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

747
748
749def main():
750 # Main program
751
752 # Argument handling
753 parser = argparse.ArgumentParser(
754 description='Compile Token::Match() calls into native C++ code')
755 parser.add_argument('--verify', action='store_true', default=False,
756 help='verify compiled matches against on-the-fly parser. Slow!')
757 parser.add_argument('--show-skipped', action='store_true', default=False,
758 help='show skipped (non-static) patterns')
759 parser.add_argument('--read-dir', default="lib",
760 help='directory from which files are read')
761 parser.add_argument('--write-dir', default="build",
762 help='directory into which files are written')
763 parser.add_argument('--prefix', default="",
764 help='prefix for build files')
765 parser.add_argument('--line', action='store_true', default=False,
766 help='add line directive to input files into build files')
767 parser.add_argument('file', nargs='*',
768 help='file to compile')
769 args = parser.parse_args()
770 lib_dir = args.read_dir
771 build_dir = args.write_dir
772 line_directive = args.line
773 files = args.file
774
775 # Check if we are invoked from the right place
776 if not os.path.exists(lib_dir):
777 print('Directory "' + lib_dir + '" not found.')
778 sys.exit(-1)
779
780 # Create build directory if needed
781 try:
782 os.makedirs(build_dir)
783 except OSError as e:
784 # due to race condition in case of parallel build,
785 # makedirs may fail. Ignore that; if there's actual
786 # problem with directory creation, it'll be caught
787 # by the following isdir check
788 if e.errno != errno.EEXIST:
789 raise
790
791 if not os.path.isdir(build_dir):
792 raise Exception(build_dir + ' is not a directory')
793
794 mc = MatchCompiler(verify_mode=args.verify,
795 show_skipped=args.show_skipped)
796
797 if not files:
798 # select all *.cpp files in lib_dir
799 for f in glob.glob(lib_dir + '/*.cpp'):
800 files.append(f[len(lib_dir) + 1:])
801
802 # convert files
803 for fi in files:
804 pi = lib_dir + '/' + fi
805 fo = args.prefix + fi
806 po = build_dir + '/' + fo

Callers 1

matchcompiler.pyFile · 0.70

Calls 3

convertFileMethod · 0.95
MatchCompilerClass · 0.85
existsMethod · 0.45

Tested by

no test coverage detected