44import sys
55
66
7- def checkSymbols (changesFile , symbolsFile ):
7+ def getAdditionsAndRemovals (changesFile ):
88 changesF = open (changesFile )
9- # We need to write back to the temporary symbol file for diffing
10- symbolsF = open (symbolsFile , 'r+' )
11-
129 changes = changesF .read ()
13- symbols = symbolsF .read ().splitlines ()
14-
1510 changesF .close ()
1611
1712 # Get rid of lines that start with either '//' or a newline
@@ -27,6 +22,29 @@ def checkSymbols(changesFile, symbolsFile):
2722 # Map the removals by removing the 'Removed: ' prefix to get just the symbol
2823 removals = list (map (lambda r : r .removeprefix ('Removed: ' ), removals ))
2924
25+ return (additions , removals )
26+
27+
28+ def checkSymbols (args ):
29+ # If we were passed a base file, read those changes first. This most likely
30+ # occurs in assert configurations getting the non-assert base.
31+ baseAdditions = []
32+ baseRemovals = []
33+
34+ if args .base :
35+ (baseAdditions , baseRemovals ) = getAdditionsAndRemovals (args .base )
36+
37+ (additions , removals ) = getAdditionsAndRemovals (args .changes )
38+
39+ # Append the base additions and removals to ours.
40+ additions .extend (baseAdditions )
41+ removals .extend (baseRemovals )
42+
43+ # We need to write back to the temporary symbol file for diffing
44+ symbolsF = open (args .symbols , 'r+' )
45+
46+ symbols = symbolsF .read ().splitlines ()
47+
3048 # Check for added symbols that are not actually in the just built dylib.
3149 notInDylib = [a for a in additions if a not in symbols ]
3250
@@ -69,10 +87,11 @@ def main(arguments):
6987
7088 parser .add_argument ('changes' , help = 'the changes file' )
7189 parser .add_argument ('symbols' , help = 'the symbols file' )
90+ parser .add_argument ('--base' , help = 'the base changes file' )
7291
7392 args = parser .parse_args (arguments )
7493
75- checkSymbols (args . changes , args . symbols )
94+ checkSymbols (args )
7695
7796
7897sys .exit (main (sys .argv [1 :]))
0 commit comments