diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-04-14 15:47:20 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-04-14 15:47:20 +0000 |
commit | cfb9f0c454d243ed4c3a6d7eed9141cc66582ef3 (patch) | |
tree | bb55c85ca4bb5ea4e7729b382a58d38606f360b5 /tools | |
parent | 90249cd5ca182f510aaa25bb72bc66ee40bdadd5 (diff) |
Add a script to generate a GNU ld version script from versions/*.abi
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 1 | ||||
-rw-r--r-- | tools/make-version-script.py | 154 |
2 files changed, 155 insertions, 0 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index bd1f4c002..8a3c18b00 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -28,6 +28,7 @@ EXTRA_DIST = \ libglibcodegen.py \ ls-interfaces.xsl \ make-all-async.xsl \ + make-version-script.py \ spec-to-introspect.xsl \ telepathy-glib-env.in \ with-session-bus.sh diff --git a/tools/make-version-script.py b/tools/make-version-script.py new file mode 100644 index 000000000..63c4ac2c8 --- /dev/null +++ b/tools/make-version-script.py @@ -0,0 +1,154 @@ +#!/usr/bin/python + +"""Construct a GNU ld version-script from a set of RFC822-style symbol lists. + +Usage: + make-version-script.py [--symbols SYMBOLS] [--unreleased-version VER] + [FILES...] + +Each FILE starts with RFC822-style headers "Version:" (the name of the +symbol version, e.g. FOO_1.2.3) and "Extends:" (either the previous +version, or "-" if this is the first version). Next there is a blank +line, then a list of C symbols one per line. + +Comments (lines starting with whitespace + "#") are allowed and ignored. + +If --symbols is given, SYMBOLS lists the symbols actually exported by +the library (one per line). If --unreleased-version is given, any symbols +in SYMBOLS but not in FILES are assigned to that version; otherwise, any +such symbols cause an error. + +This script originates in telepathy-glib <http://telepathy.freedesktop.org/> - +please send us any changes that are needed. +""" + +# Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/> +# Copyright (C) 2008 Nokia Corporation +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. + +import sys +from getopt import gnu_getopt +from sets import Set as set + + +def e(format, *args): + sys.stderr.write((format + '\n') % args) + + +def main(abifiles, symbols=None, unreleased_version=None): + + symbol_set = None + + if symbols is not None: + symbol_set = open(symbols, 'r').readlines() + symbol_set = map(str.strip, symbol_set) + symbol_set = set(symbol_set) + + versioned_symbols = set() + + for filename in abifiles: + lines = open(filename, 'r').readlines() + + version = None + extends = None + + for i, line in enumerate(lines): + line = line.strip() + + if line.startswith('#'): + continue + elif not line: + # the transition betwen headers and symbols + cut = i + 1 + break + elif line.lower().startswith('version:'): + line = line[8:].strip() + version = line + continue + elif line.lower().startswith('extends:'): + line = line[8:].strip() + extends = line + continue + else: + e('Could not understand line in %s header: %s', filename, line) + raise SystemExit(1) + + else: + e('No symbols in %s', filename) + raise SystemExit(1) + + if version is None: + e('No Versions: header in %s', filename) + raise SystemExit(1) + + if extends is None: + e('No Extends: header in %s', filename) + raise SystemExit(1) + + lines = lines[cut:] + + print "%s {" % version + print " global:" + + for symbol in lines: + symbol = symbol.strip() + + if symbol.startswith('#'): + continue + + print " %s;" % symbol + versioned_symbols.add(symbol) + + if extends == '-': + print " local:" + print " *;" + print "};" + else: + print "} %s;" % extends + + print + + if symbol_set is not None: + missing = versioned_symbols - symbol_set + + if missing: + e('These symbols have disappeared:') + + for symbol in missing: + e(' %s', symbol) + + raise SystemExit(1) + + unreleased = symbol_set - versioned_symbols + + if unreleased: + if unreleased_version is None: + e('Unversioned symbols are not allowed in releases:') + + for symbol in unreleased: + e(' %s', symbol) + + raise SystemExit(1) + + print "%s {" % unreleased_version + print " global:" + + for symbol in unreleased: + print " %s;" % symbol + + print "} %s;" % version + + +if __name__ == '__main__': + options, argv = gnu_getopt (sys.argv[1:], '', + ['symbols=', 'unreleased-version=']) + + opts = {} + + for option, value in options: + opts[option.lstrip('-').replace('-', '_')] = value + + main(argv, **opts) |