2 # Processing of symbols and abilist files.
3 # Copyright (C) 2020-2022 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 """Symbol processing for glibc."""
24 def replace_file(path
, new_contents
):
25 """Atomically replace PATH with lines from NEW_CONTENTS.
27 NEW_CONTENTS must be a sequence of strings.
31 with
open(temppath
, 'w') as out
:
32 for line
in new_contents
:
34 os
.rename(temppath
, path
)
36 class VersionedSymbol
:
37 """A combination of a symbol and its version."""
39 def __init__(self
, symbol
, version
):
40 """Construct a new versioned symbol."""
44 self
.version
= version
47 return self
.symbol
+ '@' + self
.version
49 def __eq__(self
, other
):
50 return self
.symbol
== other
.symbol
and self
.version
== other
.version
53 return hash(self
.symbol
) ^
hash(self
.version
)
55 def read_abilist(path
):
56 """Read the abilist file at PATH.
58 Return a dictionary from VersionedSymbols to their flags (as
63 with
open(path
) as inp
:
65 version
, symbol
, flags
= line
.strip().split(' ', 2)
66 versym
= VersionedSymbol(symbol
, version
)
68 raise IOError("{}: duplicate symbol {}".format(path
, versym
))
69 result
[versym
] = flags
72 def abilist_lines(symbols
):
73 """Build the abilist file contents (as a list of lines).
75 SYMBOLS is a dictionary from VersionedSymbols to their flags.
79 for versym
, flags
in symbols
.items():
80 result
.append('{} {} {}\n'.format(
81 versym
.version
, versym
.symbol
, flags
))