Files
linux/debian/lib/python/debian_linux/abi.py
Ben Hutchings 676810be34 debian/lib/python/debian_linux/abi.py: Add support for namespaces
Exported symbols can now be defined to belong to a specific namespace,
and Module.symvers includes this as an additional field between name
and module.

The namespace can be an empty string, so when reading we need to split
fields on '\t' and not the default of one-or-more-whitespace.  We then
also need to separate fields with '\t' when writing an ABI reference.

Namespaces are intended for grouping symbols exported for use by
groups of in-tree modules, and we ought to add support for ignoring
ABI changes on this basis.  For now, just add it as an attribute of
Symbol which is compared when checking for ABI changes.
2019-11-19 06:42:10 +00:00

45 lines
1.4 KiB
Python

class Symbol(object):
def __init__(self, name, namespace, module, version, export):
self.name, self.namespace, self.module = name, namespace, module
self.version, self.export = version, export
def __eq__(self, other):
if not isinstance(other, Symbol):
return NotImplemented
# Symbols are resolved to modules by depmod at installation/
# upgrade time, not compile time, so moving a symbol between
# modules is not an ABI change. Compare everything else.
if self.name != other.name:
return False
if self.namespace != other.namespace:
return False
if self.version != other.version:
return False
if self.export != other.export:
return False
return True
def __ne__(self, other):
ret = self.__eq__(other)
if ret is NotImplemented:
return ret
return not ret
class Symbols(dict):
def __init__(self, file=None):
if file:
self.read(file)
def read(self, file):
for line in file:
version, name, namespace, module, export = line.split('\t')
self[name] = Symbol(name, namespace, module, version, export)
def write(self, file):
for s in sorted(self.values(), key=lambda i: i.name):
file.write("%s\t%s\t%s\t%s\n" %
(s.version, s.name, s.namespace, s.module, s.export))