Skip to content

Commit 13f0ffb

Browse files
committed
Switch to python script and add asserts baselines
1 parent 1d5108c commit 13f0ffb

File tree

8 files changed

+27979
-8
lines changed

8 files changed

+27979
-8
lines changed

Diff for: test/abi/Inputs/macOS/arm64/stdlib/baseline-asserts

+13,978
Large diffs are not rendered by default.

Diff for: test/abi/Inputs/macOS/x86_64/stdlib/baseline-asserts

+13,837
Large diffs are not rendered by default.

Diff for: test/abi/macOS/arm64/stdlib-asserts.swift

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols
4+
// RUN: diff -u %S/../../Inputs/macOS/arm64/stdlib/baseline-asserts %t/symbols
5+
6+
// REQUIRES: swift_stdlib_asserts
7+
// REQUIRES: STDLIB_VARIANT=macosx-arm64
8+
9+
// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment below.)
10+
11+
// Welcome, Build Wrangler!
12+
//
13+
// This file lists APIs that have recently changed in a way that potentially
14+
// indicates an ABI- or source-breaking problem.
15+
//
16+
// A failure in this test indicates that there is a potential breaking change in
17+
// the Standard Library. If you observe a failure outside of a PR test, please
18+
// reach out to the Standard Library team directly to make sure this gets
19+
// resolved quickly! If your own PR fails in this test, you probably have an
20+
// ABI- or source-breaking change in your commits. Please go and fix it.
21+
//
22+
// Please DO NOT DISABLE THIS TEST. In addition to ignoring the current set of
23+
// ABI breaks, XFAILing this test also silences any future ABI breaks that may
24+
// land on this branch, which simply generates extra work for the next person
25+
// that picks up the mess.
26+
//
27+
// Instead of disabling this test, you'll need to extend the list of expected
28+
// changes at the bottom. (You'll also need to do this if your own PR triggers
29+
// false positives, or if you have special permission to break things.) You can
30+
// find a diff of what needs to be added in the output of the failed test run.
31+
// The order of lines doesn't matter, and you can also include comments to refer
32+
// to any bugs you filed.
33+
//
34+
// Thank you for your help ensuring the stdlib remains compatible with its past!
35+
// -- Your friendly stdlib engineers
36+
37+
// Standard Library Symbols
38+
39+
Added: _$ss15_getRetainCountySuyXlF
40+
Added: _$ss19_getWeakRetainCountySuyXlF
41+
Added: _$ss22_getUnownedRetainCountySuyXlF
42+
43+
// Runtime Symbols

Diff for: test/abi/macOS/arm64/stdlib.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/arm64/libswiftCore.dylib > %t/symbols
3-
// RUN: { grep -Ev "^/|^$" %s || true; } > %t/changes
4-
// RUN: cat %t/changes | while read line; do if [[ $line =~ ^Added:\ (.*)$ ]]; then sed -i "" "/${BASH_REMATCH[1]}/d" %t/symbols; fi done
5-
// RUN: cat %t/changes | while read line; do if [[ $line =~ ^Removed:\ (.*)$ ]]; then echo "${BASH_REMATCH[1]}" >> %t/symbols; fi done
6-
// RUN: sort %t/symbols -o %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols
74
// RUN: diff -u %S/../../Inputs/macOS/arm64/stdlib/baseline %t/symbols
85

96
// REQUIRES: swift_stdlib_no_asserts

Diff for: test/abi/macOS/x86_64/stdlib-asserts.swift

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols
4+
// RUN: diff -u %S/../../Inputs/macOS/x86_64/stdlib/baseline-asserts %t/symbols
5+
6+
// REQUIRES: swift_stdlib_asserts
7+
// REQUIRES: STDLIB_VARIANT=macosx-x86_64
8+
9+
// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment below.)
10+
11+
// Welcome, Build Wrangler!
12+
//
13+
// This file lists APIs that have recently changed in a way that potentially
14+
// indicates an ABI- or source-breaking problem.
15+
//
16+
// A failure in this test indicates that there is a potential breaking change in
17+
// the Standard Library. If you observe a failure outside of a PR test, please
18+
// reach out to the Standard Library team directly to make sure this gets
19+
// resolved quickly! If your own PR fails in this test, you probably have an
20+
// ABI- or source-breaking change in your commits. Please go and fix it.
21+
//
22+
// Please DO NOT DISABLE THIS TEST. In addition to ignoring the current set of
23+
// ABI breaks, XFAILing this test also silences any future ABI breaks that may
24+
// land on this branch, which simply generates extra work for the next person
25+
// that picks up the mess.
26+
//
27+
// Instead of disabling this test, you'll need to extend the list of expected
28+
// changes at the bottom. (You'll also need to do this if your own PR triggers
29+
// false positives, or if you have special permission to break things.) You can
30+
// find a diff of what needs to be added in the output of the failed test run.
31+
// The order of lines doesn't matter, and you can also include comments to refer
32+
// to any bugs you filed.
33+
//
34+
// Thank you for your help ensuring the stdlib remains compatible with its past!
35+
// -- Your friendly stdlib engineers
36+
37+
// Standard Library Symbols
38+
39+
Added: _$ss15_getRetainCountySuyXlF
40+
Added: _$ss19_getWeakRetainCountySuyXlF
41+
Added: _$ss22_getUnownedRetainCountySuyXlF
42+
43+
// Runtime Symbols

Diff for: test/abi/macOS/x86_64/stdlib.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: nm -g --defined-only -f just-symbols %stdlib_dir/x86_64/libswiftCore.dylib > %t/symbols
3-
// RUN: { grep -Ev "^/|^$" %s || true; } > %t/changes
4-
// RUN: cat %t/changes | while read line; do if [[ $line =~ ^Added:\ (.*)$ ]]; then sed -i "" "/${BASH_REMATCH[1]}/d" %t/symbols; fi done
5-
// RUN: cat %t/changes | while read line; do if [[ $line =~ ^Removed:\ (.*)$ ]]; then echo "${BASH_REMATCH[1]}" >> %t/symbols; fi done
6-
// RUN: sort %t/symbols -o %t/symbols
3+
// RUN: %abi-symbol-checker %s %t/symbols
74
// RUN: diff -u %S/../../Inputs/macOS/x86_64/stdlib/baseline %t/symbols
85

96
// REQUIRES: swift_stdlib_no_asserts

Diff for: test/lit.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ config.swift_libexec_dir = make_path(config.swift, '..', '..', 'libexec')
360360
config.swift_share_dir = make_path(config.swift, '..', '..', 'share')
361361
config.round_trip_syntax_test = make_path(config.swift_utils, 'round-trip-syntax-test')
362362
config.refactor_check_compiles = make_path(config.swift_utils, 'refactor-check-compiles.py')
363+
config.abi_symbol_checker = make_path(config.swift_utils, 'swift-abi-symbol-checker.py')
363364

364365
config.link = lit.util.which('link', config.environment.get('PATH', '')) or \
365366
lit.util.which('lld-link', config.environment.get('PATH', ''))
@@ -2598,6 +2599,7 @@ config.substitutions.append(('%scale-test',
25982599
'{} {} --swiftc-binary={} --tmpdir=%t --exclude-timers'.format(
25992600
shell_quote(sys.executable), config.scale_test,
26002601
config.swiftc)))
2602+
config.substitutions.append(('%abi-symbol-checker', '%s %s' % (shell_quote(sys.executable), config.abi_symbol_checker)))
26012603
config.substitutions.append(('%target-sil-opt\(mock-sdk:([^)]+)\)',
26022604
SubstituteCaptures(r'%s \1 %s' % (
26032605
escape_for_substitute_captures(subst_target_sil_opt_mock_sdk),

Diff for: utils/swift-abi-symbol-checker.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import sys
5+
6+
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+')
10+
11+
changes = changesF.read()
12+
symbols = symbolsF.read().splitlines()
13+
14+
changesF.close()
15+
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 != '']
18+
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')]
23+
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))
28+
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]
31+
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))
37+
38+
sys.exit(-1)
39+
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]
43+
44+
# Append the removals into the symbol list to get back to the baseline
45+
symbols.extend(removals)
46+
47+
# Sort the end result to write back
48+
symbols.sort()
49+
50+
# Go back to beginning of the file and purge everything
51+
symbolsF.seek(0)
52+
symbolsF.truncate()
53+
54+
# Append a newline to each symbol (because writelines doesn't do that for us)
55+
symbols = list(map(lambda s: s + '\n', symbols))
56+
57+
# Write all of our symbols back into the symbols file
58+
symbolsF.writelines(symbols)
59+
60+
# Done
61+
symbolsF.close()
62+
63+
def main(arguments):
64+
parser = argparse.ArgumentParser(
65+
description='Change absolute install names to use @rpath')
66+
67+
parser.add_argument('changes', help='the changes file')
68+
parser.add_argument('symbols', help='the symbols file')
69+
70+
args = parser.parse_args(arguments)
71+
72+
checkSymbols(args.changes, args.symbols)
73+
74+
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)