|
3 | 3 | import argparse |
4 | 4 | import sys |
5 | 5 |
|
| 6 | + |
6 | 7 | def checkSymbols(changesFile, symbolsFile): |
7 | | - changesF = open(changesFile) |
8 | | - # We need to write back to the temporary symbol file for diffing |
9 | | - symbolsF = open(symbolsFile, 'r+') |
| 8 | + changesF = open(changesFile) |
| 9 | + # We need to write back to the temporary symbol file for diffing |
| 10 | + symbolsF = open(symbolsFile, 'r+') |
| 11 | + |
| 12 | + changes = changesF.read() |
| 13 | + symbols = symbolsF.read().splitlines() |
10 | 14 |
|
11 | | - changes = changesF.read() |
12 | | - symbols = symbolsF.read().splitlines() |
| 15 | + changesF.close() |
13 | 16 |
|
14 | | - changesF.close() |
| 17 | + # Get rid of lines that start with either '//' or a newline |
| 18 | + changes = [c for c in changes.splitlines() if not c.startswith('//') and c != ''] |
15 | 19 |
|
16 | | - # Get rid of lines that start with either '//' or a newline |
17 | | - changes = [c for c in changes.splitlines() if not c.startswith('//') and c != ''] |
| 20 | + # Filter the changes for lines that start with Added |
| 21 | + additions = [a for a in changes if a.startswith('Added')] |
| 22 | + # Filter the changes for lines that start with Removed |
| 23 | + removals = [r for r in changes if r.startswith('Removed')] |
18 | 24 |
|
19 | | - # Filter the changes for lines that start with Added |
20 | | - additions = [a for a in changes if a.startswith('Added')] |
21 | | - # Filter the changes for lines that start with Removed |
22 | | - removals = [r for r in changes if r.startswith('Removed')] |
| 25 | + # Map the additions by removing the 'Added: ' prefix to get just the symbol |
| 26 | + additions = list(map(lambda a: a.removeprefix('Added: '), additions)) |
| 27 | + # Map the removals by removing the 'Removed: ' prefix to get just the symbol |
| 28 | + removals = list(map(lambda r: r.removeprefix('Removed: '), removals)) |
23 | 29 |
|
24 | | - # Map the additions by removing the 'Added: ' prefix to get just the symbol |
25 | | - additions = list(map(lambda a: a.removeprefix('Added: '), additions)) |
26 | | - # Map the removals by removing the 'Removed: ' prefix to get just the symbol |
27 | | - removals = list(map(lambda r: r.removeprefix('Removed: '), removals)) |
| 30 | + # Check for added symbols that are not actually in the just built dylib. |
| 31 | + notInDylib = [a for a in additions if a not in symbols] |
28 | 32 |
|
29 | | - # Check for added symbols that are not actually in the just built dylib. |
30 | | - notInDylib = [a for a in additions if not a in symbols] |
| 33 | + # If there were symbols marked as 'Added' in the changes file, but they didn't |
| 34 | + # actually appear in the dylib then print those symbols out and fail. |
| 35 | + if notInDylib: |
| 36 | + for symbol in notInDylib: |
| 37 | + print(('{} was marked as \'Added\', but it was not found in the ' |
| 38 | + 'just built library').format(symbol)) |
31 | 39 |
|
32 | | - # If there were symbols marked as 'Added' in the changes file, but they didn't |
33 | | - # actually appear in the dylib then print those symbols out and fail. |
34 | | - if notInDylib: |
35 | | - for symbol in notInDylib: |
36 | | - print('{} was marked as \'Added:\', but it was not found in the just built library'.format(symbol)) |
| 40 | + sys.exit(-1) |
37 | 41 |
|
38 | | - sys.exit(-1) |
| 42 | + # Filter the built symbols for the additions because we're removing them to |
| 43 | + # get back to the baseline |
| 44 | + symbols = [s for s in symbols if s not in additions] |
39 | 45 |
|
40 | | - # Filter the built symbols for the additions because we're removing them to |
41 | | - # get back to the baseline |
42 | | - symbols = [s for s in symbols if not s in additions] |
| 46 | + # Append the removals into the symbol list to get back to the baseline |
| 47 | + symbols.extend(removals) |
43 | 48 |
|
44 | | - # Append the removals into the symbol list to get back to the baseline |
45 | | - symbols.extend(removals) |
| 49 | + # Sort the end result to write back |
| 50 | + symbols.sort() |
46 | 51 |
|
47 | | - # Sort the end result to write back |
48 | | - symbols.sort() |
| 52 | + # Go back to beginning of the file and purge everything |
| 53 | + symbolsF.seek(0) |
| 54 | + symbolsF.truncate() |
49 | 55 |
|
50 | | - # Go back to beginning of the file and purge everything |
51 | | - symbolsF.seek(0) |
52 | | - symbolsF.truncate() |
| 56 | + # Append a newline to each symbol (because writelines doesn't do that for us) |
| 57 | + symbols = list(map(lambda s: s + '\n', symbols)) |
53 | 58 |
|
54 | | - # Append a newline to each symbol (because writelines doesn't do that for us) |
55 | | - symbols = list(map(lambda s: s + '\n', symbols)) |
| 59 | + # Write all of our symbols back into the symbols file |
| 60 | + symbolsF.writelines(symbols) |
56 | 61 |
|
57 | | - # Write all of our symbols back into the symbols file |
58 | | - symbolsF.writelines(symbols) |
| 62 | + # Done |
| 63 | + symbolsF.close() |
59 | 64 |
|
60 | | - # Done |
61 | | - symbolsF.close() |
62 | 65 |
|
63 | 66 | def main(arguments): |
64 | | - parser = argparse.ArgumentParser( |
65 | | - description='Change absolute install names to use @rpath') |
| 67 | + parser = argparse.ArgumentParser( |
| 68 | + description='Change absolute install names to use @rpath') |
| 69 | + |
| 70 | + parser.add_argument('changes', help='the changes file') |
| 71 | + parser.add_argument('symbols', help='the symbols file') |
66 | 72 |
|
67 | | - parser.add_argument('changes', help='the changes file') |
68 | | - parser.add_argument('symbols', help='the symbols file') |
| 73 | + args = parser.parse_args(arguments) |
69 | 74 |
|
70 | | - args = parser.parse_args(arguments) |
| 75 | + checkSymbols(args.changes, args.symbols) |
71 | 76 |
|
72 | | - checkSymbols(args.changes, args.symbols) |
73 | 77 |
|
74 | 78 | sys.exit(main(sys.argv[1:])) |
0 commit comments