Skip to content

Commit d31cebe

Browse files
committed
[build] ensure benchmark toolchain tests use the just built libraries
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 910d918 commit d31cebe

File tree

1 file changed

+27
-4
lines changed
  • utils/swift_build_support/swift_build_support/products

1 file changed

+27
-4
lines changed

utils/swift_build_support/swift_build_support/products/benchmarks.py

Lines changed: 27 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,12 @@ 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+
"""
105+
89106
toolchain_path = swiftpm.SwiftPM.get_install_destdir(args,
90107
host_target,
91108
product.build_dir)
@@ -94,6 +111,12 @@ def run_build_script_helper(host_target, product, args):
94111
toolchain_path += \
95112
targets.darwin_toolchain_prefix(args.install_prefix)
96113

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

0 commit comments

Comments
 (0)