diff options
author | Dieter Verfaillie <dieterv@optionexplicit.be> | 2012-04-02 17:42:22 +0200 |
---|---|---|
committer | Johan Dahlin <jdahlin@litl.com> | 2012-04-05 10:22:59 -0300 |
commit | 79c2ee4c05d2722faaf4256992756fe8e8a5721b (patch) | |
tree | 8d55856e4ab888577e004a700fca0d720c53e312 /misc | |
parent | f1d2547d0fba03431d5f85376088638bb461869e (diff) | |
download | gobject-introspection-79c2ee4c05d2722faaf4256992756fe8e8a5721b.tar.gz |
update-glib-annotations.py: reduce code duplication
https://bugzilla.gnome.org/show_bug.cgi?id=672254
Diffstat (limited to 'misc')
-rwxr-xr-x | misc/update-glib-annotations.py | 118 |
1 files changed, 55 insertions, 63 deletions
diff --git a/misc/update-glib-annotations.py b/misc/update-glib-annotations.py index 315b43ce..82bd2491 100755 --- a/misc/update-glib-annotations.py +++ b/misc/update-glib-annotations.py @@ -3,87 +3,69 @@ # e.g.: # ./update-glib-annotations.py ../../glib ../../glib/_build + import os import sys + import subprocess -possible_builddirs = ['../_build/', '..'] + +possible_builddirs = ['../_build/', '..', '../../build/'] builddir = None for d in possible_builddirs: if os.path.isfile(os.path.join(d, 'g-ir-annotation-tool')): builddir = d break assert builddir is not None -annotation_tool_base_args = [os.path.join(builddir, 'g-ir-annotation-tool'), '--extract'] +annotation_tool_base_args = [os.path.join(builddir, 'g-ir-annotation-tool'), + '--extract'] + def directory_includes(dirs, srcdir, builddir): result = [] result.append('-I' + srcdir) + if srcdir != builddir: result.append('-I' + builddir) + for name in dirs: result.append('-I' + os.path.join(srcdir, name)) if srcdir != builddir: result.append('-I' + os.path.join(builddir, name)) + return result -def extract_glib_annotations(srcdir, builddir, outfile): - projname = 'glib' - headersfile = os.path.join(builddir, projname, projname + '-public-headers.txt') - subdir = os.path.join(srcdir, projname) - f = open(headersfile) - line = f.read() - f.close() - sources = [] - for headername in line.split(' '): - headername = headername.strip() - if headername == 'gi18n-lib.h': - continue - sources.append(os.path.join(subdir, headername)) - for sourcename in os.listdir(subdir): - if sourcename.endswith('.c'): - sources.append(os.path.join(subdir, sourcename)) - return subprocess.check_call(annotation_tool_base_args + - ['-DGLIB_COMPILATION'] + directory_includes(['glib', 'gmodule'], srcdir, builddir) + sources, - stdout=outfile) -def extract_gobject_annotations(srcdir, builddir, outfile): - projname = 'gobject' - headersfile = os.path.join(builddir, projname, projname + '-public-headers.txt') - subdir = os.path.join(srcdir, projname) - f = open(headersfile) - line = f.read() - f.close() +def extract_annotations(module, srcdir, builddir, outfile): sources = [] - for headername in line.split(' '): - headername = headername.strip() - sources.append(os.path.join(subdir, headername)) - for sourcename in os.listdir(subdir): - if sourcename.endswith('.c'): - sources.append(os.path.join(subdir, sourcename)) - return subprocess.check_call(annotation_tool_base_args + - ['-DGOBJECT_COMPILATION'] + directory_includes(['glib', 'gobject', 'gmodule'], srcdir, builddir) + sources, - stdout=outfile) + subdir = os.path.join(srcdir, module['name']) + headersfile = os.path.join(builddir, + module['name'], + module['name'] + '-public-headers.txt') + includes = directory_includes(module['includes'], + srcdir, builddir) -def extract_gio_annotations(srcdir, builddir, outfile): - projname = 'gio' - headersfile = os.path.join(builddir, projname, projname + '-public-headers.txt') - subdir = os.path.join(srcdir, projname) f = open(headersfile) line = f.read() f.close() - sources = [] + for headername in line.split(' '): headername = headername.strip() + if headername in module['skip_headers']: + continue sources.append(os.path.join(subdir, headername)) + for sourcename in os.listdir(subdir): if sourcename.endswith('.c'): sources.append(os.path.join(subdir, sourcename)) + return subprocess.check_call(annotation_tool_base_args + - ['-DGOBJECT_COMPILATION', - '-DGIO_COMPILATION'] + directory_includes(['glib', 'gmodule', 'gobject', 'gio'], srcdir, builddir) + sources, + module['defines'] + + includes + + sources, stdout=outfile) + if __name__ == '__main__': srcdir = sys.argv[1] if len(sys.argv) == 3: @@ -93,29 +75,39 @@ if __name__ == '__main__': print "Using source directory: %r build directory: %r" % (srcdir, builddir) - srcname = '../gir/glib-2.0.c' - srcfile = open(srcname + '.tmp', 'w') - extract_glib_annotations(srcdir, builddir, srcfile) - srcfile.close() - os.rename(srcname + '.tmp', srcname) + modules = [{'name': 'glib', + 'srcname': '../gir/glib-2.0.c', + 'skip_headers': ['gi18n-lib.h'], + 'includes': ['glib', 'gmodule'], + 'defines': ['-DGLIB_COMPILATION']}, - print "Updated %r" % (srcname, ) + {'name': 'gobject', + 'srcname': '../gir/gobject-2.0.c', + 'skip_headers': [], + 'includes': ['glib', 'gobject', 'gmodule'], + 'defines': ['-DGOBJECT_COMPILATION']}, - srcname = '../gir/gobject-2.0.c' - srcfile = open(srcname + '.tmp', 'w') - extract_gobject_annotations(srcdir, builddir, srcfile) - srcfile.close() - os.rename(srcname + '.tmp', srcname) + {'name': 'gio', + 'srcname': '../gir/gio-2.0.c', + 'skip_headers': [], + 'includes': ['glib', 'gmodule', 'gobject', 'gio'], + 'defines': ['-DGOBJECT_COMPILATION', '-DGIO_COMPILATION']}] - print "Updated %r" % (srcname, ) + for module in modules: + srcname = module['srcname'] + tmpname = module['srcname'] + '.tmp' - srcname = '../gir/gio-2.0.c' - srcfile = open(srcname + '.tmp', 'w') - extract_gio_annotations(srcdir, builddir, srcfile) - srcfile.close() - os.rename(srcname + '.tmp', srcname) + if os.path.isfile(tmpname): + os.unlink(tmpname) - print "Updated %r" % (srcname, ) + if os.path.isfile(srcname): + os.unlink(srcname) - print "Done; run \"git diff\" to see any changes." + srcfile = open(tmpname, 'w') + extract_annotations(module, srcdir, builddir, srcfile) + srcfile.close() + os.rename(tmpname, srcname) + print "Updated %r" % (srcname, ) + + print "Done; run \"git diff\" to see any changes." |