def create_source_scanner(options, args): if hasattr(options, 'filelist') and options.filelist: filenames = extract_filelist(options) else: filenames = extract_filenames(args) filenames = [os.path.realpath(f) for f in filenames] if platform.system() == 'Darwin': options.cpp_undefines.append('__BLOCKS__') # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() if hasattr(options, 'compiler') and options.compiler: ss.set_compiler(options.compiler) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines, cflags=options.cflags) try: ss.parse_files(filenames) ss.parse_macros(filenames) finally: for error in ss.get_errors(): print(error, file=sys.stderr) return ss, filenames
def check(args): filename = args[0] output = ChunkedIO() namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace, output=output) logger.enable_warnings(True) transformer = Transformer(namespace) transformer.set_include_paths([ os.path.join(top_srcdir, 'gir'), top_builddir, os.path.join(top_builddir, 'gir'), ]) transformer.register_include(Include.from_string('GObject-2.0')) ss = SourceScanner() options = Options() exit_code = process_packages(options, ['gobject-2.0']) if exit_code: sys.exit(exit_code) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files([filename]) ss.parse_macros([filename]) transformer.parse(ss.get_symbols()) cbp = GtkDocCommentBlockParser() blocks = cbp.parse_comment_blocks(ss.get_comments()) main = MainTransformer(transformer, blocks) main.transform() final = IntrospectablePass(transformer, blocks) final.validate() emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()] expected_warnings = _extract_expected(filename) sortkey = lambda x: int(x.split(':')[0]) expected_warnings.sort(key=sortkey) emitted_warnings.sort(key=sortkey) if len(expected_warnings) != len(emitted_warnings): raise SystemExit("ERROR in '%s': %d warnings were emitted, " "expected %d:\n%s" % (os.path.basename(filename), len(emitted_warnings), len(expected_warnings), _diff(expected_warnings, emitted_warnings))) for emitted_warning, expected_warning in zip(emitted_warnings, expected_warnings): if expected_warning != emitted_warning: raise SystemExit( "ERROR in '%s': expected warning does not match emitted " "warning:\n%s" % (filename, _diff([expected_warning], [emitted_warning])))
def setUp(self): self.ss = SourceScanner() tmp_fd, tmp_name = tempfile.mkstemp() file = os.fdopen(tmp_fd, 'wt') file.write(two_typedefs_source) file.close() self.ss.parse_files([tmp_name])
def create_scanner_from_source_string(source): ss = SourceScanner() tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True) file = os.fdopen(tmp_fd, 'wt') file.write(source) file.close() ss.parse_files([tmp_name]) return ss
def _parse_files(self, code, header=True): scanner = SourceScanner() tmp_fd, tmp_name = tempfile.mkstemp(suffix=".h" if header else ".c") fileobj = os.fdopen(tmp_fd, 'wb') with fileobj: fileobj.write(code.encode("utf-8")) scanner.parse_files([tmp_name]) os.unlink(tmp_name) return scanner
def create_source_scanner(options, args): filenames = extract_filenames(args) # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files(filenames) ss.parse_macros(filenames) return ss
def create_scanner_from_source_string(source): ss = SourceScanner() tmp_fd, tmp_name = tempfile.mkstemp(suffix='.h', text=True) try: with os.fdopen(tmp_fd, 'wt') as file: file.write(source) ss.parse_files([tmp_name]) finally: os.unlink(tmp_name) return ss
def check(args): filename = args[0] output = StringIO() namespace = Namespace("Test", "1.0") logger = MessageLogger.get(namespace=namespace, output=output) logger.enable_warnings(True) transformer = Transformer(namespace) transformer.set_include_paths( [os.path.join(top_srcdir, 'gir'), top_builddir]) transformer.register_include(Include.from_string("GObject-2.0")) ss = SourceScanner() options = Options() exit_code = process_packages(options, ['gobject-2.0']) if exit_code: sys.exit(exit_code) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files([filename]) ss.parse_macros([filename]) transformer.parse(ss.get_symbols()) ap = AnnotationParser() blocks = ap.parse(ss.get_comments()) main = MainTransformer(transformer, blocks) main.transform() final = IntrospectablePass(transformer, blocks) final.validate() raw = output.getvalue() if raw.endswith('\n'): raw = raw[:-1] warnings = raw.split('\n') failed_tests = 0 expected_warnings = _extract_expected(filename) if '' in warnings: warnings.remove('') if len(expected_warnings) != len(warnings): raise SystemExit( "ERROR in %r: expected %d warnings, but got %d:\n" "----\nexpected:\n%s\n----\ngot:\n%s\n----" % (os.path.basename(filename), len(expected_warnings), len(warnings), '\n'.join([w[1] for w in expected_warnings]), '\n'.join( [w.split(':', 2)[2][1:] for w in warnings]))) for warning, (sort_key, expected) in zip(warnings, expected_warnings): actual = warning.split(":", 1)[1] if _diff(expected, actual, filename): raise SystemExit("ERROR: tests %r failed" % (filename, ))
def create_source_scanner(options, args): if hasattr(options, 'filelist') and options.filelist: filenames = extract_filelist(options) else: filenames = extract_filenames(args) if platform.system() == 'Darwin': options.cpp_undefines.append('__BLOCKS__') # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines, cflags=options.cflags) ss.parse_files(filenames) ss.parse_macros(filenames) return ss