From 5c70ef2eb32949f8889e9ae654d50bfbf838951f Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 10 Aug 2012 12:40:10 +0800 Subject: sourcescannermain.py: Add --filelist option Add a function to put the files to pass to g-ir-scanner in a filelist file, with one source/header file on a single line. This is done to work around the limitation of Windows cmd.exe (and MSYS) where the command line cannot exceed 8192 characters. When this option is used, g-ir-scanner will only look for the header/source files that are specified in the filelist file, which is not too hard to generate. https://bugzilla.gnome.org/show_bug.cgi?id=681820 --- giscanner/scannermain.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 794cede3..6efd291a 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -158,6 +158,9 @@ match the namespace prefix.""") parser.add_option("", "--c-include", action="append", dest="c_includes", default=[], help="headers which should be included in C programs") + parser.add_option("", "--filelist", + action="store", dest="filelist", default=[], + help="file containing headers and sources to be scanned") group = get_preprocessor_option_group(parser) parser.add_option_group(group) @@ -250,6 +253,27 @@ def extract_filenames(args): filenames.append(os.path.abspath(arg)) return filenames +def extract_filelist(options): + filenames = [] + if not os.path.exists(options.filelist): + _error('%s: no such filelist file' % (options.filelist, )) + filelist_file = open(options.filelist, "r") + lines = filelist_file.readlines() + for line in lines: + # We don't support real C++ parsing yet, but we should be able + # to understand C API implemented in C++ files. + filename = line.strip() + if (filename.endswith('.c') or filename.endswith('.cpp') or + filename.endswith('.cc') or filename.endswith('.cxx') or + filename.endswith('.h') or filename.endswith('.hpp') or + filename.endswith('.hxx')): + if not os.path.exists(filename): + _error('%s: Invalid filelist entry-no such file or directory' % (line, )) + # Make absolute, because we do comparisons inside scannerparser.c + # against the absolute path that cpp will give us + filenames.append(os.path.abspath(filename)) + return filenames + def create_namespace(options): if options.strip_prefix: print """g-ir-scanner: warning: Option --strip-prefix has been deprecated; @@ -324,7 +348,10 @@ def create_binary(transformer, options, args): return shlibs def create_source_scanner(options, args): - filenames = extract_filenames(args) + if options.filelist: + filenames = extract_filelist(options) + else: + filenames = extract_filenames(args) # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols @@ -381,8 +408,9 @@ def scanner_main(args): if options.test_codegen: return test_codegen(options.test_codegen) - if len(args) <= 1: - _error('Need at least one filename') + if not options.filelist: + if len(args) <= 1: + _error('Need at least one filename') if not options.namespace_name: _error('Namespace name missing') -- cgit v1.2.1 From abc95859d05edc9d167ef967652327091422b682 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Mon, 12 Nov 2012 17:18:41 +0100 Subject: giscanner: unbreak g-ir-annotationtool... ... and by extension misc/update-glib-annotations.py. Commit 5c70ef2eb32949f8889e9ae654d50bfbf838951f broke these by assuming create_source_scanner() is always called with 'options' and 'args' built by the OptionParser() defined in scannermain.py's _get_option_parser(). This is not the case with g-ir-annotationtool, where annotationmain.py's annotation_main() creates it's own OptionParser() accepting a different set of 'options' and 'args' as compared to scannermain.py --- giscanner/scannermain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 6efd291a..45dcbcbd 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -348,7 +348,7 @@ def create_binary(transformer, options, args): return shlibs def create_source_scanner(options, args): - if options.filelist: + if hasattr(options, 'filelist') and options.filelist: filenames = extract_filelist(options) else: filenames = extract_filenames(args) @@ -408,7 +408,7 @@ def scanner_main(args): if options.test_codegen: return test_codegen(options.test_codegen) - if not options.filelist: + if hasattr(options, 'filelist') and not options.filelist: if len(args) <= 1: _error('Need at least one filename') -- cgit v1.2.1 From bdb479f3663d284e1a785f603f17670a754d0bbf Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Fri, 29 Jun 2012 14:43:33 +0200 Subject: giscanner: remove unused variables https://bugzilla.gnome.org/show_bug.cgi?id=688897 --- giscanner/scannermain.py | 1 - 1 file changed, 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 45dcbcbd..56d73f8c 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -310,7 +310,6 @@ def create_transformer(namespace, options): transformer.disable_cache() transformer.set_passthrough_mode() - shown_include_warning = False for include in options.includes: if os.sep in include: _error("Invalid include path %r" % (include, )) -- cgit v1.2.1 From dfeaf33c8a4ae7e25b4a83d0b31c4d435b4ef7de Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 24 Feb 2013 03:55:18 -0500 Subject: scanner: internals cleanup: Key more things off Namespace The .gir format has a weird legacy where stuff like the includes are outside of the . But conceptually they're tied together, so let's start reflecting this in the code. This way we can just pass around and look at a Namespace object instead of a 4-tuple of (namespace, includes, c_includes, pkg_config). https://bugzilla.gnome.org/show_bug.cgi?id=694593 --- giscanner/scannermain.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 56d73f8c..9ca45a2f 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -195,7 +195,6 @@ def passthrough_gir(path, f): writer = GIRWriter(parser.get_namespace(), parser.get_shared_libraries(), - parser.get_includes(), parser.get_pkgconfig_packages(), parser.get_c_includes()) f.write(writer.get_xml()) @@ -473,7 +472,7 @@ def scanner_main(args): else: exported_packages = options.packages - writer = Writer(transformer.namespace, shlibs, transformer.get_includes(), + writer = Writer(transformer.namespace, shlibs, exported_packages, options.c_includes) data = writer.get_xml() -- cgit v1.2.1 From 95f80c1ae03dfe8a68d3c7ec21ce696ac839ea57 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 24 Feb 2013 11:58:57 -0500 Subject: scanner: internals cleanup: Move shared libraries to Namespace Continuing on with previous commit. --- giscanner/scannermain.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 9ca45a2f..ccd828da 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -194,7 +194,6 @@ def passthrough_gir(path, f): parser.parse(path) writer = GIRWriter(parser.get_namespace(), - parser.get_shared_libraries(), parser.get_pkgconfig_packages(), parser.get_c_includes()) f.write(writer.get_xml()) @@ -450,6 +449,8 @@ def scanner_main(args): else: shlibs = [] + transformer.namespace.shared_libraries = shlibs + main = MainTransformer(transformer, blocks) main.transform() @@ -472,7 +473,7 @@ def scanner_main(args): else: exported_packages = options.packages - writer = Writer(transformer.namespace, shlibs, + writer = Writer(transformer.namespace, exported_packages, options.c_includes) data = writer.get_xml() -- cgit v1.2.1 From c0ebb1e9888ee745437e87482d0b89c30cab355f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 24 Feb 2013 12:07:28 -0500 Subject: scanner: internals cleanup: Move c_includes to Namespace Continuation of previous work. --- giscanner/scannermain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index ccd828da..3d402fac 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -194,8 +194,7 @@ def passthrough_gir(path, f): parser.parse(path) writer = GIRWriter(parser.get_namespace(), - parser.get_pkgconfig_packages(), - parser.get_c_includes()) + parser.get_pkgconfig_packages()) f.write(writer.get_xml()) def test_codegen(optstring): @@ -473,8 +472,9 @@ def scanner_main(args): else: exported_packages = options.packages + transformer.namespace.c_includes = options.c_includes writer = Writer(transformer.namespace, - exported_packages, options.c_includes) + exported_packages) data = writer.get_xml() write_output(data, options) -- cgit v1.2.1 From f17dfbe3e65acd9274c2f98292362b0824564e0d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sun, 24 Feb 2013 12:07:28 -0500 Subject: scanner: internals cleanup: Move pkgconfig list to Namespace Continuation of previous work. --- giscanner/scannermain.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 3d402fac..5fa370ce 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -193,8 +193,7 @@ def passthrough_gir(path, f): parser = GIRParser() parser.parse(path) - writer = GIRWriter(parser.get_namespace(), - parser.get_pkgconfig_packages()) + writer = GIRWriter(parser.get_namespace()) f.write(writer.get_xml()) def test_codegen(optstring): @@ -473,8 +472,8 @@ def scanner_main(args): exported_packages = options.packages transformer.namespace.c_includes = options.c_includes - writer = Writer(transformer.namespace, - exported_packages) + transformer.namespace.exported_packages = exported_packages + writer = Writer(transformer.namespace) data = writer.get_xml() write_output(data, options) -- cgit v1.2.1 From 95b03cf87efbd4fea4b7d55601c9752cefd29bfc Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Sun, 24 Feb 2013 17:34:56 +1100 Subject: gi-r-scanner: add support for raw CFLAGS flags option gi-r-scanner chokes when gir_CFLAGS have an '-include
' since this is not a recognised option. This commit adds a new --cflags option that passes cflags directly to the spawned gcc. https://bugzilla.gnome.org/show_bug.cgi?id=695182 --- giscanner/scannermain.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 5fa370ce..8b4363bf 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -44,6 +44,9 @@ from . import utils def get_preprocessor_option_group(parser): group = optparse.OptionGroup(parser, "Preprocessor options") + group.add_option("--cflags", help="Pre-processor cflags", + action="store", dest="cpp_cflags", + default="") group.add_option("-I", help="Pre-processor include file", action="append", dest="cpp_includes", default=[]) @@ -351,7 +354,8 @@ def create_source_scanner(options, args): # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() - ss.set_cpp_options(options.cpp_includes, + ss.set_cpp_options(options.cpp_cflags, + options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files(filenames) -- cgit v1.2.1 From b051c92cdfbe8255de27bba658a5a95d626accb9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 5 Mar 2013 18:23:25 -0500 Subject: Revert "gi-r-scanner: add support for raw CFLAGS flags option" Doesn't work with arguments that have shell quotes. This reverts commit 95b03cf87efbd4fea4b7d55601c9752cefd29bfc. --- giscanner/scannermain.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 8b4363bf..5fa370ce 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -44,9 +44,6 @@ from . import utils def get_preprocessor_option_group(parser): group = optparse.OptionGroup(parser, "Preprocessor options") - group.add_option("--cflags", help="Pre-processor cflags", - action="store", dest="cpp_cflags", - default="") group.add_option("-I", help="Pre-processor include file", action="append", dest="cpp_includes", default=[]) @@ -354,8 +351,7 @@ def create_source_scanner(options, args): # Run the preprocessor, tokenize and construct simple # objects representing the raw C symbols ss = SourceScanner() - ss.set_cpp_options(options.cpp_cflags, - options.cpp_includes, + ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files(filenames) -- cgit v1.2.1 From 7639a440b43ea1197de96035304404b0c87db608 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 6 Mar 2013 12:16:24 -0500 Subject: scanner: Allow CFLAGS to contain arbitrary preprocessor commands like -include Newer spidermonkey .pc file contains a -include argument, which g-ir-scanner doesn't understand. Rather than us attempting to replicate all of cpp's options, use wrapper arguments in Makefile.introspection to pass them through. https://bugzilla.gnome.org/show_bug.cgi?id=695182 --- giscanner/scannermain.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 5fa370ce..42867f08 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -42,8 +42,23 @@ from giscanner.sourcescanner import SourceScanner from giscanner.transformer import Transformer from . import utils +def process_cflags_begin(option, opt, value, parser): + cflags = getattr(parser.values, option.dest) + while len(parser.rargs) > 0 and parser.rargs[0] != '--cflags-end': + cflags.append(parser.rargs.pop(0)) + +def process_cflags_end(option, opt, value, parser): + pass + def get_preprocessor_option_group(parser): group = optparse.OptionGroup(parser, "Preprocessor options") + group.add_option("", "--cflags-begin", + help="Start preprocessor/compiler flags", + dest="cflags", default=[], + action="callback", callback=process_cflags_begin) + group.add_option("", "--cflags-end", + help="End preprocessor/compiler flags", + action="callback", callback=process_cflags_end) group.add_option("-I", help="Pre-processor include file", action="append", dest="cpp_includes", default=[]) @@ -353,7 +368,8 @@ def create_source_scanner(options, args): ss = SourceScanner() ss.set_cpp_options(options.cpp_includes, options.cpp_defines, - options.cpp_undefines) + options.cpp_undefines, + cflags=options.cflags) ss.parse_files(filenames) ss.parse_macros(filenames) return ss -- cgit v1.2.1 From 2806ee7c7db81be0ad164caf68b70163df24386d Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 31 Oct 2012 17:37:47 +0100 Subject: giscanner: prefer "except X as e" over "except X, e" It's more readable and as an added bonus Python 3 compatible. https://bugzilla.gnome.org/show_bug.cgi?id=697616 --- giscanner/scannermain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 42867f08..b068f6fb 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -393,7 +393,7 @@ def write_output(data, options): os.unlink(temp_f_name) try: shutil.move(main_f_name, options.output) - except OSError, e: + except OSError as e: if e.errno == errno.EPERM: os.unlink(main_f_name) return 0 @@ -402,12 +402,12 @@ def write_output(data, options): else: try: output = open(options.output, "w") - except IOError, e: + except IOError as e: _error("opening output for writing: %s" % (e.strerror, )) try: output.write(data) - except IOError, e: + except IOError as e: _error("while writing output: %s" % (e.strerror, )) def scanner_main(args): -- cgit v1.2.1 From b70fe6a5649ed037f2554ae13067fd9929d841f8 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 24 Apr 2013 17:41:49 +0200 Subject: giscanner: Define source and header filename extensions only once Enables us to to use a more effecient list membership test instead of testing the end of some string multiple times. https://bugzilla.gnome.org/show_bug.cgi?id=699533 --- giscanner/scannermain.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index b068f6fb..deefcf99 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -38,7 +38,7 @@ from giscanner.girparser import GIRParser from giscanner.girwriter import GIRWriter from giscanner.maintransformer import MainTransformer from giscanner.shlibs import resolve_shlibs -from giscanner.sourcescanner import SourceScanner +from giscanner.sourcescanner import SourceScanner, ALL_EXTS from giscanner.transformer import Transformer from . import utils @@ -253,10 +253,7 @@ def extract_filenames(args): for arg in args: # We don't support real C++ parsing yet, but we should be able # to understand C API implemented in C++ files. - if (arg.endswith('.c') or arg.endswith('.cpp') or - arg.endswith('.cc') or arg.endswith('.cxx') or - arg.endswith('.h') or arg.endswith('.hpp') or - arg.endswith('.hxx')): + if os.path.splitext(arg)[1] in ALL_EXTS: if not os.path.exists(arg): _error('%s: no such a file or directory' % (arg, )) # Make absolute, because we do comparisons inside scannerparser.c -- cgit v1.2.1 From 2dfdfdf42516bc07a5c2159ae5c696038567b9a1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 27 Mar 2013 16:28:36 -0400 Subject: transformer: Remove annotations The transformer doesn't need the annotations, so why are we giving it to it? https://bugzilla.gnome.org/show_bug.cgi?id=699854 --- giscanner/scannermain.py | 1 - 1 file changed, 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index deefcf99..8ccd1f09 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -452,7 +452,6 @@ def scanner_main(args): blocks = ap.parse(ss.get_comments()) # Transform the C symbols into AST nodes - transformer.set_annotations(blocks) transformer.parse(ss.get_symbols()) if not options.header_only: -- cgit v1.2.1 From c9e2d880011c530ff1454fe31a2d40d189860be5 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 24 Apr 2013 14:06:18 +0200 Subject: tests: Update misc/pep8.py to 1.4.5 Version in our tree is a wee bit outdated. For example, later work will introduce an utf8 encoded python source file which our old pep8.py does not yet understand (yeah, it really was *that* ancient)... Updated from: https://raw.github.com/jcrocholl/pep8/1.4.5/pep8.py Takes 552c1f1525e37a30376790151c1ba437776682c5, f941537d1c0a40f0906490ed160db6c79af572d3, 5a4afe2a77d0ff7d9fea13dd93c3304a6ca993de and a17f157e19bd6792c00321c8020dca5e5a281f45 into account... https://bugzilla.gnome.org/show_bug.cgi?id=699535 --- giscanner/scannermain.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 8ccd1f09..00dc30d6 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -42,14 +42,17 @@ from giscanner.sourcescanner import SourceScanner, ALL_EXTS from giscanner.transformer import Transformer from . import utils + def process_cflags_begin(option, opt, value, parser): cflags = getattr(parser.values, option.dest) while len(parser.rargs) > 0 and parser.rargs[0] != '--cflags-end': cflags.append(parser.rargs.pop(0)) + def process_cflags_end(option, opt, value, parser): pass + def get_preprocessor_option_group(parser): group = optparse.OptionGroup(parser, "Preprocessor options") group.add_option("", "--cflags-begin", @@ -71,6 +74,7 @@ def get_preprocessor_option_group(parser): group.add_option("-p", dest="", help="Ignored") return group + def get_windows_option_group(parser): group = optparse.OptionGroup(parser, "Machine Dependent Options") group.add_option("-m", help="some machine dependent option", @@ -79,13 +83,13 @@ def get_windows_option_group(parser): return group + def _get_option_parser(): parser = optparse.OptionParser('%prog [options] sources') parser.add_option('', "--quiet", action="store_true", dest="quiet", default=False, - help="If passed, do not print details of normal" \ - + " operation") + help="If passed, do not print details of normal operation") parser.add_option("", "--format", action="store", dest="format", default="gir", @@ -204,6 +208,7 @@ match the namespace prefix.""") def _error(msg): raise SystemExit('ERROR: %s' % (msg, )) + def passthrough_gir(path, f): parser = GIRParser() parser.parse(path) @@ -211,6 +216,7 @@ def passthrough_gir(path, f): writer = GIRWriter(parser.get_namespace()) f.write(writer.get_xml()) + def test_codegen(optstring): (namespace, out_h_filename, out_c_filename) = optstring.split(',') if namespace == 'Everything': @@ -221,6 +227,7 @@ def test_codegen(optstring): _error("Invaild namespace %r" % (namespace, )) return 0 + def process_options(output, allowed_flags): for option in output.split(): for flag in allowed_flags: @@ -229,6 +236,7 @@ def process_options(output, allowed_flags): yield option break + def process_packages(options, packages): args = ['pkg-config', '--cflags'] args.extend(packages) @@ -248,6 +256,7 @@ def process_packages(options, packages): options.cpp_defines.extend(pkg_options.cpp_defines) options.cpp_undefines.extend(pkg_options.cpp_undefines) + def extract_filenames(args): filenames = [] for arg in args: @@ -261,6 +270,7 @@ def extract_filenames(args): filenames.append(os.path.abspath(arg)) return filenames + def extract_filelist(options): filenames = [] if not os.path.exists(options.filelist): @@ -271,10 +281,10 @@ def extract_filelist(options): # We don't support real C++ parsing yet, but we should be able # to understand C API implemented in C++ files. filename = line.strip() - if (filename.endswith('.c') or filename.endswith('.cpp') or - filename.endswith('.cc') or filename.endswith('.cxx') or - filename.endswith('.h') or filename.endswith('.hpp') or - filename.endswith('.hxx')): + if (filename.endswith('.c') or filename.endswith('.cpp') + or filename.endswith('.cc') or filename.endswith('.cxx') + or filename.endswith('.h') or filename.endswith('.hpp') + or filename.endswith('.hxx')): if not os.path.exists(filename): _error('%s: Invalid filelist entry-no such file or directory' % (line, )) # Make absolute, because we do comparisons inside scannerparser.c @@ -282,6 +292,7 @@ def extract_filelist(options): filenames.append(os.path.abspath(filename)) return filenames + def create_namespace(options): if options.strip_prefix: print """g-ir-scanner: warning: Option --strip-prefix has been deprecated; @@ -310,6 +321,7 @@ see --identifier-prefix and --symbol-prefix.""" identifier_prefixes=identifier_prefixes, symbol_prefixes=symbol_prefixes) + def create_transformer(namespace, options): transformer = Transformer(namespace, accept_unprefixed=options.accept_unprefixed) @@ -331,6 +343,7 @@ def create_transformer(namespace, options): return transformer + def create_binary(transformer, options, args): # Transform the C AST nodes into higher level # GLib/GObject nodes @@ -341,7 +354,7 @@ def create_binary(transformer, options, args): gdump_parser.init_parse() if options.program: - args=[options.program] + args = [options.program] args.extend(options.program_args) binary = IntrospectionBinary(args) else: @@ -354,6 +367,7 @@ def create_binary(transformer, options, args): gdump_parser.parse() return shlibs + def create_source_scanner(options, args): if hasattr(options, 'filelist') and options.filelist: filenames = extract_filelist(options) @@ -371,6 +385,7 @@ def create_source_scanner(options, args): ss.parse_macros(filenames) return ss + def write_output(data, options): if options.output == "-": output = sys.stdout @@ -407,6 +422,7 @@ def write_output(data, options): except IOError as e: _error("while writing output: %s" % (e.strerror, )) + def scanner_main(args): parser = _get_option_parser() (options, args) = parser.parse_args(args) -- cgit v1.2.1 From 30b17d39adc7a7284b926cac6ada566eb1b62292 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Tue, 14 May 2013 17:06:24 +0200 Subject: giscanner: rename AnnotationParser() to GtkDocCommentBlockParser() Clarify the purpose of what up until now was know as the AnnotationParser() class, as it does more than just extracting annotations, it parses the complete GTK-Doc comment block. --- giscanner/scannermain.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 00dc30d6..40a941ba 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -29,7 +29,7 @@ import sys import tempfile from giscanner import message -from giscanner.annotationparser import AnnotationParser +from giscanner.annotationparser import GtkDocCommentBlockParser from giscanner.ast import Include, Namespace from giscanner.dumper import compile_introspection_binary from giscanner.gdumpparser import GDumpParser, IntrospectionBinary @@ -464,8 +464,8 @@ def scanner_main(args): ss = create_source_scanner(options, args) - ap = AnnotationParser() - blocks = ap.parse(ss.get_comments()) + cbp = GtkDocCommentBlockParser() + blocks = cbp.parse(ss.get_comments()) # Transform the C symbols into AST nodes transformer.parse(ss.get_symbols()) -- cgit v1.2.1 From e88a99496cf4091ec16670a2fe656878fc055692 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 15 May 2013 22:38:28 +0200 Subject: giscanner: rename the parse() method to parse_comment_blocks() We already have a parse_comment_block() method parsing a single GTK-Doc comment block so it only seems natural to have a plural parse_comment_blocks() to go along with that. --- giscanner/scannermain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 40a941ba..e4436b8c 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -465,7 +465,7 @@ def scanner_main(args): ss = create_source_scanner(options, args) cbp = GtkDocCommentBlockParser() - blocks = cbp.parse(ss.get_comments()) + blocks = cbp.parse_comment_blocks(ss.get_comments()) # Transform the C symbols into AST nodes transformer.parse(ss.get_symbols()) -- cgit v1.2.1 From 6d9022311b5d3bfb48895466880c2a15235b63a6 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Wed, 24 Jul 2013 16:56:20 +0200 Subject: giscanner: give message.ERROR a purpose It's not yet being used but will be in the future by annotationparser.py to signal the difference between message.WARNING: something is wrong but the comment block can still be parsed and serialized back into a comment block without information being lost message.ERROR: something is wrong and the comment block can *not* be parsed and serialized back into a comment block without information being lost Different tools can then act accordingly. Nothing will change for g-ir-scanner but this will be important for the GTK-Doc comment block rewriting tool to prevent extremely broken input leading to even more broken output... --- giscanner/scannermain.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index e4436b8c..ab8f5bbf 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -452,7 +452,8 @@ def scanner_main(args): namespace = create_namespace(options) logger = message.MessageLogger.get(namespace=namespace) if options.warn_all: - logger.enable_warnings(True) + logger.enable_warnings((message.WARNING, message.ERROR, message.FATAL)) + transformer = create_transformer(namespace, options) packages = set(options.packages) -- cgit v1.2.1 From ebb80508d6959a0c94351e841c2cab6220602e62 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Thu, 17 Oct 2013 17:43:48 +0200 Subject: giscanner: remove g_realpath giscannermodule expects file names to be canonicalized and symlinks to be resolved (most likely to support users of symlinked /usr/local). Instead of computing absolute and real paths all over the place, we can do this once on entry in SourceScanner().parse_files() and SourceScanner().parse_macros() and clean the rest a bit... https://bugzilla.gnome.org/show_bug.cgi?id=710320 --- giscanner/scannermain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index ab8f5bbf..6ae2dede 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -267,7 +267,7 @@ def extract_filenames(args): _error('%s: no such a file or directory' % (arg, )) # Make absolute, because we do comparisons inside scannerparser.c # against the absolute path that cpp will give us - filenames.append(os.path.abspath(arg)) + filenames.append(arg) return filenames @@ -289,7 +289,7 @@ def extract_filelist(options): _error('%s: Invalid filelist entry-no such file or directory' % (line, )) # Make absolute, because we do comparisons inside scannerparser.c # against the absolute path that cpp will give us - filenames.append(os.path.abspath(filename)) + filenames.append(filename) return filenames -- cgit v1.2.1 From 95cbe0c58f729fbcd27e68a693a8bbcaaf117858 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Wed, 13 Nov 2013 12:31:19 +0100 Subject: giscanner: Make sure we use real paths in more places Ensure we are using the real path also for cflags comming from pkg_config files and command line options. This fixes the generation of the gir files when include paths contain symlinks. https://bugzilla.gnome.org/show_bug.cgi?id=712211 --- giscanner/scannermain.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 6ae2dede..bc7bc16f 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -46,13 +46,19 @@ from . import utils def process_cflags_begin(option, opt, value, parser): cflags = getattr(parser.values, option.dest) while len(parser.rargs) > 0 and parser.rargs[0] != '--cflags-end': - cflags.append(parser.rargs.pop(0)) + arg = parser.rargs.pop(0) + cflags.append(utils.cflag_real_include_path(arg)) def process_cflags_end(option, opt, value, parser): pass +def process_cpp_includes(option, opt, value, parser): + cpp_includes = getattr(parser.values, option.dest) + cpp_includes.append(os.path.realpath(value)) + + def get_preprocessor_option_group(parser): group = optparse.OptionGroup(parser, "Preprocessor options") group.add_option("", "--cflags-begin", @@ -63,8 +69,8 @@ def get_preprocessor_option_group(parser): help="End preprocessor/compiler flags", action="callback", callback=process_cflags_end) group.add_option("-I", help="Pre-processor include file", - action="append", dest="cpp_includes", - default=[]) + dest="cpp_includes", default=[], type="string", + action="callback", callback=process_cpp_includes) group.add_option("-D", help="Pre-processor define", action="append", dest="cpp_defines", default=[]) @@ -252,7 +258,7 @@ def process_packages(options, packages): filtered_output = list(process_options(output, options_whitelist)) parser = _get_option_parser() pkg_options, unused = parser.parse_args(filtered_output) - options.cpp_includes.extend(pkg_options.cpp_includes) + options.cpp_includes.extend([os.path.realpath(f) for f in pkg_options.cpp_includes]) options.cpp_defines.extend(pkg_options.cpp_defines) options.cpp_undefines.extend(pkg_options.cpp_undefines) -- cgit v1.2.1 From b45d3949422faeae297cfd4dd28a9a08df68f3b4 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Sat, 16 Nov 2013 14:18:34 +0100 Subject: giscanner: Handle the case when there's a space between -I cpp flag and the path In this case we were considering -I and the path as two different command line options. This was not a problem in the past (or for other cpp flags) because they are passed directly to gcc that accepts it. Now that we are ensuring that the include paths are always real paths, we need to handle this case to identify include paths in the command line. https://bugzilla.gnome.org/show_bug.cgi?id=712211 --- giscanner/scannermain.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index bc7bc16f..715084d4 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -47,6 +47,9 @@ def process_cflags_begin(option, opt, value, parser): cflags = getattr(parser.values, option.dest) while len(parser.rargs) > 0 and parser.rargs[0] != '--cflags-end': arg = parser.rargs.pop(0) + if arg == "-I" and parser.rargs and parser.rargs[0] != '--cflags-end': + # This is a special case where there's a space between -I and the path. + arg += parser.rargs.pop(0) cflags.append(utils.cflag_real_include_path(arg)) -- cgit v1.2.1 From acdf22eeaa704e6fb155641aaa40c4ae8018290a Mon Sep 17 00:00:00 2001 From: Davide Bertola Date: Thu, 13 Feb 2014 10:05:37 +0100 Subject: Fix errors parsing OSX 10.9 headers Un-defining __BLOCKS__ disables blocks in system headers (like stdlib.h). This avoids errors while compiling. --- giscanner/scannermain.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'giscanner/scannermain.py') diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 715084d4..98d56878 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -27,6 +27,7 @@ import shutil import subprocess import sys import tempfile +import platform from giscanner import message from giscanner.annotationparser import GtkDocCommentBlockParser @@ -383,6 +384,9 @@ def create_source_scanner(options, args): 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() -- cgit v1.2.1