Skip to content

Commit f9ebe85

Browse files
committed
Add base file support for assert config
1 parent 6e76d0d commit f9ebe85

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

test/abi/macOS/arm64/stdlib-asserts.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
3-
// RUN: %abi-symbol-checker %s %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols --base %S/stdlib.swift
44
// RUN: diff -u %S/../../Inputs/macOS/arm64/stdlib/baseline-asserts %t/symbols
55

66
// REQUIRES: swift_stdlib_asserts
@@ -34,15 +34,10 @@
3434
// Thank you for your help ensuring the stdlib remains compatible with its past!
3535
// -- Your friendly stdlib engineers
3636

37-
// Standard Library Symbols
38-
39-
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
40-
Added: _$ss15_getRetainCountySuyXlF
37+
// *** NOTE: ***
38+
// You will normally add new entries in 'abi/macOS/arm64/stdlib.swift' instead
39+
// of this file. This file is dedicated for assert only symbols.
4140

42-
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
43-
Added: _$ss19_getWeakRetainCountySuyXlF
44-
45-
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
46-
Added: _$ss22_getUnownedRetainCountySuyXlF
41+
// Standard Library Symbols
4742

4843
// Runtime Symbols

test/abi/macOS/arm64/stdlib.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ Added: _$ss19_getWeakRetainCountySuyXlF
4545
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4646
Added: _$ss22_getUnownedRetainCountySuyXlF
4747

48+
// Swift.hello() -> ()
49+
Added: _$ss5helloyyF
50+
51+
// static Swift.Unicode.UTF16._isASCII(Swift.UInt16) -> Swift.Bool
52+
Removed: _$ss7UnicodeO5UTF16O8_isASCIIySbs6UInt16VFZ
53+
4854
// Runtime Symbols

test/abi/macOS/x86_64/stdlib-asserts.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %llvm-nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
3-
// RUN: %abi-symbol-checker %s %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols --base %S/stdlib.swift
44
// RUN: diff -u %S/../../Inputs/macOS/x86_64/stdlib/baseline-asserts %t/symbols
55

66
// REQUIRES: swift_stdlib_asserts
@@ -34,15 +34,10 @@
3434
// Thank you for your help ensuring the stdlib remains compatible with its past!
3535
// -- Your friendly stdlib engineers
3636

37-
// Standard Library Symbols
38-
39-
// Swift._getRetainCount(Swift.AnyObject) -> Swift.UInt
40-
Added: _$ss15_getRetainCountySuyXlF
37+
// *** NOTE: ***
38+
// You will normally add new entries in 'abi/macOS/x86_64/stdlib.swift' instead
39+
// of this file. This file is dedicated for assert only symbols.
4140

42-
// Swift._getWeakRetainCount(Swift.AnyObject) -> Swift.UInt
43-
Added: _$ss19_getWeakRetainCountySuyXlF
44-
45-
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
46-
Added: _$ss22_getUnownedRetainCountySuyXlF
41+
// Standard Library Symbols
4742

4843
// Runtime Symbols

test/abi/macOS/x86_64/stdlib.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ Added: _$ss19_getWeakRetainCountySuyXlF
4545
// Swift._getUnownedRetainCount(Swift.AnyObject) -> Swift.UInt
4646
Added: _$ss22_getUnownedRetainCountySuyXlF
4747

48+
// Swift.hello() -> ()
49+
Added: _$ss5helloyyF
50+
51+
// static Swift.Unicode.UTF16._isASCII(Swift.UInt16) -> Swift.Bool
52+
Removed: _$ss7UnicodeO5UTF16O8_isASCIIySbs6UInt16VFZ
53+
4854
// Runtime Symbols

utils/swift-abi-symbol-checker.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
import 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

7897
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)