| 1 |
#!/usr/bin/python3 |
| 2 |
|
| 3 |
# Script to mark private symbols |
| 4 |
# Copyright: 2015 Dmitry Shachnev <[email protected]> |
| 5 |
|
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining |
| 7 |
# a copy of this software and associated documentation files (the |
| 8 |
# "Software"), to deal in the Software without restriction, including |
| 9 |
# without limitation the rights to use, copy, modify, merge, publish, |
| 10 |
# distribute, sublicense, and/or sell copies of the Software, and to |
| 11 |
# permit persons to whom the Software is furnished to do so, subject to |
| 12 |
# the following conditions: |
| 13 |
# |
| 14 |
# The above copyright notice and this permission notice shall be included |
| 15 |
# in all copies or substantial portions of the Software. |
| 16 |
# |
| 17 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 |
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 |
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 |
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
|
| 26 |
'''Mark private symbols based on Qt version tags (symbols that are tagged |
| 27 |
with Qt_5_PRIVATE_API will be marked as private).''' |
| 28 |
|
| 29 |
|
| 30 |
from argparse import ArgumentParser |
| 31 |
from difflib import unified_diff |
| 32 |
from glob import glob |
| 33 |
from sys import stdout, stderr |
| 34 |
|
| 35 |
|
| 36 |
def process_symbols_file(symbols_file_path, write_results=False): |
| 37 |
old_lines = [] |
| 38 |
new_lines = [] |
| 39 |
has_alternative = False |
| 40 |
with open(symbols_file_path) as symbols_file: |
| 41 |
for line in symbols_file: |
| 42 |
old_lines.append(line) |
| 43 |
line = line.rstrip() |
| 44 |
if line.endswith(' 1'): |
| 45 |
line = line[:-2] |
| 46 |
if '@Qt_5_PRIVATE_API' in line or '@Qt_6_PRIVATE_API' in line: |
| 47 |
line += ' 1' |
| 48 |
if line.startswith('| '): |
| 49 |
has_alternative = True |
| 50 |
new_lines.append(line + '\n') |
| 51 |
if not has_alternative: |
| 52 |
print('Skipping file %s, no alternative dependency specified.' % |
| 53 |
symbols_file_path) |
| 54 |
elif write_results: |
| 55 |
with open(symbols_file_path, 'w') as symbols_file: |
| 56 |
for line in new_lines: |
| 57 |
symbols_file.write(line) |
| 58 |
else: |
| 59 |
for line in unified_diff(old_lines, new_lines, |
| 60 |
fromfile=symbols_file_path, |
| 61 |
tofile=symbols_file_path): |
| 62 |
stdout.write(line) |
| 63 |
|
| 64 |
|
| 65 |
if __name__ == '__main__': |
| 66 |
parser = ArgumentParser(description=__doc__) |
| 67 |
group = parser.add_mutually_exclusive_group() |
| 68 |
group.add_argument('--write-results', |
| 69 |
help='write results back into symbols files (default)', |
| 70 |
action='store_false') |
| 71 |
group.add_argument('--print-diff', |
| 72 |
help='print diffs into stdout instead of applying them', |
| 73 |
action='store_true') |
| 74 |
args = parser.parse_args() |
| 75 |
|
| 76 |
symbols_files = glob('debian/*.symbols') |
| 77 |
if not symbols_files: |
| 78 |
print('No symbols files found!', file=stderr) |
| 79 |
for symbols_file_path in symbols_files: |
| 80 |
process_symbols_file(symbols_file_path, not args.print_diff) |