Skip to content

Commit b903a6c

Browse files
committed
Put symbol generation logic under test
...before adding the logic to filter paths In particular: * print the list of files that `cpio` copies, so we can test explicitly which files end up in the symroot (and also see those when asking for a toolchain in PR testing) * use `find` instead of `grep` to filter files we want symbols generated for -- this is to avoid the script failing when there are no symbol to process, especially in lit tests * remove an unnecessary check for `swift-api-digester` -- this is now a symlink to `swift-frontend` and we only process regular files. Supports rdar://76865276
1 parent 5b1f02d commit b903a6c

File tree

4 files changed

+140
-22
lines changed

4 files changed

+140
-22
lines changed

utils/build-script-impl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,19 @@ if [ -z "${CMAKE}" ] ; then
10151015
fi
10161016

10171017
function xcrun_find_tool() {
1018-
xcrun --sdk macosx --toolchain "${DARWIN_XCRUN_TOOLCHAIN}" --find "$@"
1018+
if [[ "${DRY_RUN}" ]]; then
1019+
echo echo "$@"
1020+
else
1021+
xcrun --sdk macosx --toolchain "${DARWIN_XCRUN_TOOLCHAIN}" --find "$@"
1022+
fi
10191023
}
10201024

10211025
function find_just_built_local_host_llvm_tool() {
1022-
find $(build_directory "${LOCAL_HOST}" llvm) -name "$1" -type f -print
1026+
if [[ "${DRY_RUN}" ]]; then
1027+
echo echo "$1"
1028+
else
1029+
find $(build_directory "${LOCAL_HOST}" llvm) -name "$1" -type f -print
1030+
fi
10231031
}
10241032

10251033
function not() {
@@ -3130,15 +3138,10 @@ for host in "${ALL_HOSTS[@]}"; do
31303138
# descibes
31313139
host_symroot="${INSTALL_SYMROOT}/${host}"
31323140

3133-
# FIXME: Since it's hard to trace output pipe call,
3134-
# For now, We don't support dry-run trace for this block
3135-
# Instead, just echo we do "darwin_intall_extract_symbols".
3136-
if [[ "${DRY_RUN}" ]]; then
3137-
call darwin_install_extract_symbols
3138-
printJSONStartTimestamp dsymutil
3139-
echo xargs -n 1 -P ${DSYMUTIL_JOBS} dsymutil
3140-
printJSONEndTimestamp dsymutil
3141-
else
3141+
# FIXME this if statement is a trick to have a more readable
3142+
# diff for the PR that made the following code
3143+
# amenable to dry run testing
3144+
if [ -n "${DRY_RUN}" -o -z "${DRY_RUN}" ]; then
31423145
set -x
31433146

31443147
CURRENT_INSTALL_DIR=${host_install_destdir}
@@ -3147,7 +3150,7 @@ for host in "${ALL_HOSTS[@]}"; do
31473150
# Copy executables and shared libraries from the `host_install_destdir` to
31483151
# INSTALL_SYMROOT and run dsymutil on them.
31493152
(cd "${CURRENT_INSTALL_DIR}" &&
3150-
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -print | cpio --insecure -pdm "${host_symroot}")
3153+
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -print | cpio --insecure -pdm -v "${host_symroot}")
31513154

31523155
dsymutil_path=
31533156
if [[ -n "${DARWIN_INSTALL_EXTRACT_SYMBOLS_USE_JUST_BUILT_DSYMUTIL}" ]]; then
@@ -3159,15 +3162,11 @@ for host in "${ALL_HOSTS[@]}"; do
31593162
# Run dsymutil on executables and shared libraries.
31603163
#
31613164
# Exclude shell scripts and static archives.
3162-
# Exclude swift-api-digester dSYM to reduce debug toolchain size.
31633165
# Tweak carefully the amount of parallelism -- dsymutil can be memory intensive and
31643166
# as such too many instance can exhaust the memory and slow down/panic the machine
31653167
printJSONStartTimestamp dsymutil
31663168
(cd "${host_symroot}" &&
3167-
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -print | \
3168-
grep -v '.py$' | \
3169-
grep -v '.a$' | \
3170-
grep -v 'swift-api-digester' | \
3169+
find ./"${CURRENT_PREFIX}" -perm -0111 -type f -not -name "*.a" -not -name "*.py" -print | \
31713170
xargs -n 1 -P ${DSYMUTIL_JOBS} ${dsymutil_path})
31723171
printJSONEndTimestamp dsymutil
31733172

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# REQUIRES: standalone_build,OS=macosx
2+
13
# RUN: %empty-directory(%t)
24
# RUN: mkdir -p %t
3-
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --darwin-install-extract-symbols --dsymutil-jobs 5 --cmake %cmake 2>&1 | %FileCheck %s
4-
5-
# REQUIRES: standalone_build,OS=macosx
5+
# RUN: mkdir -p %t/destdir
6+
# RUN: mkdir -p %t/symroot/macosx-%target-cpu
7+
# RUN: SKIP_XCODE_VERSION_CHECK=1 SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script --dry-run --darwin-install-extract-symbols --dsymutil-jobs 5 --cmake %cmake --install-symroot=%t/symroot --install-destdir=%t/destdir --toolchain-prefix= 2>&1 | %FileCheck %s
68

79
# CHECK: --- Extracting symbols ---
810
# CHECK: { "command": "dsymutil", "start": "
9-
# CHECK-NEXT: xargs -n 1 -P 5 dsymutil
10-
# CHECK-NEXT: { "command": "dsymutil", "end": "
11+
# CHECK: xargs -n 1 -P 5 {{.*}}dsymutil
12+
# CHECK: { "command": "dsymutil", "end": "
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# REQUIRES: standalone_build
2+
# REQUIRES: OS=macosx
3+
4+
# RUN: %empty-directory(%t)
5+
# RUN: mkdir -p %t
6+
# RUN: split-file %s %t
7+
8+
# Even though we are running build-script with dry-run,
9+
# symbol extraction runs real commands against the file system.
10+
# Thus we generate a series of files
11+
# to target each of the cases handled by the code
12+
# RUN: mkdir -p %t/destdir
13+
# RUN: %swiftc_driver %t/hello.swift -o %t/destdir/swift-demangle
14+
# RUN: ln -s %t/destdir/swift-demangle %t/destdir/swift-api-digester
15+
# RUN: cp %t/swift-util.py %t/destdir/
16+
# RUN: chmod a+x %t/destdir/swift-util.py
17+
# RUN: %swiftc_driver %t/dylib.swift -emit-library -o %t/destdir/libswiftDemangle.dylib
18+
# RUN: %swiftc_driver %t/dylib.swift -emit-library -static -o %t/destdir/libswiftASTSectionImporter.a
19+
# Targets marked with INSTALL_WITH_SHARED are executable (e.g. compatibility libraries)
20+
# RUN: cp %t/destdir/libswiftASTSectionImporter.a %t/destdir/libswiftCompatibility51.a
21+
# RUN: chmod a+x %t/destdir/libswiftCompatibility51.a
22+
# RUN: mkdir -p %t/symroot/macosx-%target-cpu
23+
24+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script-impl --dry-run --build-dir=%t/build --workspace=%swift_src_root/.. --cmake %cmake --only-execute macosx-%target-cpu-extractsymbols --host-cc /usr/bin/true --darwin-install-extract-symbols=1 --host-target=macosx-%target-cpu --install-symroot=%t/symroot --install-destdir=%t/destdir --build-jobs=1 > %t/build-script-impl-output.txt 2>&1
25+
# RUN: %FileCheck --input-file=%t/build-script-impl-output.txt %s
26+
# RUN: %FileCheck --input-file=%t/build-script-impl-output.txt --check-prefixes CHECK-SKIPPED %s
27+
28+
# CHECK: --- Extracting symbols ---
29+
30+
# Ensure we copy executable regular files to the symroot
31+
# CHECK-LABEL: cpio
32+
# CHECK-DAG: swift-demangle
33+
# CHECK-DAG: swift-util.py
34+
# CHECK-DAG: libswiftDemangle.dylib
35+
# CHECK-DAG: libswiftCompatibility51.a
36+
37+
# Ensure we extract symbols only for executables and
38+
# and dylibs
39+
# CHECK-LABEL: command": "dsymutil", "start"
40+
# CHECK-DAG: dsymutil {{.*}}swift-demangle
41+
# CHECK-DAG: dsymutil {{.*}}libswiftDemangle.dylib
42+
43+
# Ensure we strip executables, shared libraries and static
44+
# libraries
45+
# CHECK-LABEL: xcrun_find_tool strip
46+
# CHECK-DAG: strip {{.*}}swift-demangle
47+
# CHECK-DAG: strip {{.*}}libswiftDemangle.dylib
48+
# CHECK-DAG: strip {{.*}}libswiftASTSectionImporter.a
49+
# CHECK-DAG: strip {{.*}}libswiftCompatibility51.a
50+
# CHECK-DAG: strip {{.*}}swift-util.py
51+
52+
# Ensure we codesign dylibds
53+
# CHECK-LABEL: xcrun_find_tool codesign
54+
# CHECK: codesign {{.*}}libswiftDemangle.dylib
55+
56+
# CHECK-SKIPPED: --- Extracting symbols ---
57+
58+
# Ensure symroot does not contain symlinks and static archives
59+
# that are not executable
60+
# CHECK-SKIPPED-LABEL: cpio
61+
# CHECK-SKIPPED-NOT: swift-api-digester
62+
# CHECK-SKIPPED-NOT: libswiftASTSectionImporter.a
63+
64+
# Ensure we don't extract symbols for static archives, symlinks
65+
# and Python scripts
66+
# CHECK-SKIPPED-LABEL: command": "dsymutil", "start"
67+
# CHECK-SKIPPED-NOT: dsymutil {{.*}}libswiftASTSectionImporter.a
68+
# CHECK-SKIPPED-NOT: dsymutil {{.*}}libswiftCompatibility51.a
69+
# CHECK-SKIPPED-NOT: dsymutil {{.*}}swift-util.py
70+
# CHECK-SKIPPED-NOT: dsymutil {{.*}}swift-api-digester
71+
72+
# Ensure we don't strip symlinks
73+
# CHECK-SKIPPED-LABEL: xcrun_find_tool strip
74+
# CHECK-SKIPPED-NOT: strip {{.*}}swift-api-digester
75+
76+
# Ensure we don't codesign executables, symlinks,
77+
# static archives and python scripts
78+
# CHECK-SKIPPED-LABEL: xcrun_find_tool codesign
79+
# CHECK-SKIPPED-NOT: codesign {{.*}}swift-demangle
80+
# CHECK-SKIPPED-NOT: codesign {{.*}}libswiftASTSectionImporter.a
81+
# CHECK-SKIPPED-NOT: codesign {{.*}}libswiftCompatibility51.a
82+
# CHECK-SKIPPED-NOT: codesign {{.*}}swift-util.py
83+
# CHECK-SKIPPED-NOT: codesign {{.*}}swift-api-digester
84+
85+
#--- hello.swift
86+
print("hello")
87+
88+
#--- dylib.swift
89+
func greet(person: String) -> String {
90+
return "Hello \(person)"
91+
}
92+
#--- swift-util.py
93+
print("hello")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# REQUIRES: standalone_build
2+
# REQUIRES: OS=macosx
3+
4+
# As a result of incremental changes,
5+
# in dry-run mode the symbol extraction
6+
# still runs some real commands against the installation
7+
# and symbol directories (e.g. find and cpio)
8+
# This test explictly checks that such commands
9+
# do not cause build-script to fail when run
10+
# against empty directories (which is the typical
11+
# scenario in dry-run)
12+
# RUN: %empty-directory(%t)
13+
# RUN: mkdir -p %t
14+
# RUN: mkdir -p %t/destdir
15+
# RUN: mkdir -p %t/symroot/macosx-%target-cpu
16+
# RUN: SWIFT_BUILD_ROOT=%t %swift_src_root/utils/build-script-impl --dry-run --build-dir=%t/build --workspace=%swift_src_root/.. --cmake %cmake --only-execute macosx-%target-cpu-extractsymbols --host-cc /usr/bin/true --darwin-install-extract-symbols=1 --host-target=macosx-%target-cpu --install-symroot=%t/symroot --install-destdir=%t/destdir --build-jobs=1 2>&1 | %FileCheck %s
17+
18+
# CHECK: --- Extracting symbols ---
19+
20+
# CHECK-NOT: {{^}}echo dsymutil
21+
22+
# CHECK-NOT: {{^[^\+].*}}strip
23+
24+
# CHECK-NOT: {{^[^\+].*}}codesign

0 commit comments

Comments
 (0)