Skip to content

Commit 3504310

Browse files
authored
[build] ensure benchmark toolchain tests use the just built libraries (#38158)
The binaries would prefer the dylibs shipped in the OS to the ones just built -- employ `DYLD_LIBRARY_PATH` to pick up the latter instead. The main purpose of this change is to unblock the generation of nightly toolchains. Addresses rdar://79788142
1 parent 0cc6ce9 commit 3504310

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

utils/build-presets.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,6 @@ mixin-preset=
13051305
# SKIP LLDB TESTS (67923799)
13061306
skip-test-lldb
13071307

1308-
# SKIP testing benchmarks (79788142)
1309-
skip-test-toolchain-benchmarks
1310-
13111308
[preset: buildbot_osx_package,use_os_runtime]
13121309
mixin-preset=
13131310
buildbot_osx_package

utils/swift_build_support/swift_build_support/products/benchmarks.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,31 @@ def build(self, host_target):
5151
def should_test(self, host_target):
5252
return self.args.test_toolchainbenchmarks
5353

54+
def _get_test_environment(self, host_target):
55+
if platform.system() == 'Darwin':
56+
# the resulting binaries would search first in /usr/lib/swift,
57+
# we need to prefer the libraries we just built
58+
return {'DYLD_LIBRARY_PATH': os.path.join(
59+
_get_toolchain_path(host_target, self, self.args),
60+
'usr', 'lib', 'swift', 'macosx')}
61+
62+
return None
63+
5464
def test(self, host_target):
5565
"""Just run a single instance of the command for both .debug and
5666
.release.
5767
"""
5868
cmdline = ['--num-iters=1', 'XorLoop']
69+
test_environment = self._get_test_environment(host_target)
70+
5971
bench_Onone = os.path.join(self.build_dir, 'bin', 'Benchmark_Onone')
60-
shell.call([bench_Onone] + cmdline)
72+
shell.call([bench_Onone] + cmdline, env=test_environment)
6173

6274
bench_O = os.path.join(self.build_dir, 'bin', 'Benchmark_O')
63-
shell.call([bench_O] + cmdline)
75+
shell.call([bench_O] + cmdline, env=test_environment)
6476

6577
bench_Osize = os.path.join(self.build_dir, 'bin', 'Benchmark_Osize')
66-
shell.call([bench_Osize] + cmdline)
78+
shell.call([bench_Osize] + cmdline, env=test_environment)
6779

6880
def should_install(self, host_target):
6981
return False
@@ -85,7 +97,11 @@ def get_dependencies(cls):
8597
swiftpm.SwiftPM]
8698

8799

88-
def run_build_script_helper(host_target, product, args):
100+
def _get_toolchain_path(host_target, product, args):
101+
# TODO check if we should prefer using product.install_toolchain_path
102+
# this logic initially was inside run_build_script_helper
103+
# and was factored out so it can be used in testing as well
104+
89105
toolchain_path = swiftpm.SwiftPM.get_install_destdir(args,
90106
host_target,
91107
product.build_dir)
@@ -94,6 +110,12 @@ def run_build_script_helper(host_target, product, args):
94110
toolchain_path += \
95111
targets.darwin_toolchain_prefix(args.install_prefix)
96112

113+
return toolchain_path
114+
115+
116+
def run_build_script_helper(host_target, product, args):
117+
toolchain_path = _get_toolchain_path(host_target, product, args)
118+
97119
# Our source_dir is expected to be './$SOURCE_ROOT/benchmarks'. That is due
98120
# the assumption that each product is in its own build directory. This
99121
# product is not like that and has its package/tools instead in

0 commit comments

Comments
 (0)