Skip to content

Commit 53ff974

Browse files
committed
[benchmarks] Change the build_script_helper to use subdirectories for each build and install final binaries in a toplevel ./bin build directory.
This will let me: 1. Add -Osize support easily. 2. Put all of the binaries in the same directory so that Benchmark_Driver can work with them via the -tools argument.
1 parent 115f7a4 commit 53ff974

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

benchmark/scripts/build_script_helper.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,53 @@
44

55
import argparse
66
import os
7+
import shutil
78
import subprocess
89

910

10-
def main():
11-
parser = argparse.ArgumentParser()
12-
parser.add_argument('--verbose', '-v', action='store_true')
13-
parser.add_argument('--package-path', type=str, required=True)
14-
parser.add_argument('--build-path', type=str, required=True)
15-
parser.add_argument('--toolchain', type=str, required=True)
16-
17-
# Build the debug/release versions.
18-
args = parser.parse_args()
19-
swiftbuild_path = os.path.join(args.toolchain, 'usr', 'bin', 'swift-build')
20-
swiftbuild_args = [
21-
swiftbuild_path,
22-
'--package-path', args.package_path,
23-
'--build-path', args.build_path,
24-
'--configuration', 'debug',
25-
]
26-
if args.verbose:
27-
swiftbuild_args.append('--verbose')
28-
subprocess.call(swiftbuild_args)
11+
def perform_build(args, swiftbuild_path, config, binary_name, opt_flag):
12+
assert(config in ['debug', 'release'])
13+
assert(binary_name in ['Benchmark_O', 'Benchmark_Onone'])
14+
assert(opt_flag in ['-O', '-Onone'])
2915

16+
inner_build_dir = os.path.join(args.build_path, binary_name)
3017
swiftbuild_args = [
3118
swiftbuild_path,
3219
'--package-path', args.package_path,
33-
'--build-path', args.build_path,
34-
'--configuration', 'release',
20+
'--build-path', inner_build_dir,
21+
'--configuration', config,
3522
'-Xswiftc', '-Xllvm',
3623
'-Xswiftc', '-align-module-to-page-size',
24+
'-Xswiftc', opt_flag,
3725
]
3826
if args.verbose:
3927
swiftbuild_args.append('--verbose')
4028
subprocess.call(swiftbuild_args)
4129

30+
# Copy the benchmark file into the final ./bin directory.
31+
binpath = os.path.join(inner_build_dir, config, 'SwiftBench')
32+
finalpath = os.path.join(args.build_path, 'bin', binary_name)
33+
shutil.copy(binpath, finalpath)
34+
35+
36+
def main():
37+
parser = argparse.ArgumentParser()
38+
parser.add_argument('--verbose', '-v', action='store_true')
39+
parser.add_argument('--package-path', type=str, required=True)
40+
parser.add_argument('--build-path', type=str, required=True)
41+
parser.add_argument('--toolchain', type=str, required=True)
42+
43+
args = parser.parse_args()
44+
45+
# Create our bin directory so we can copy in the binaries.
46+
bin_dir = os.path.join(args.build_path, 'bin')
47+
if not os.path.isdir(bin_dir):
48+
os.makedirs(bin_dir)
49+
50+
swiftbuild_path = os.path.join(args.toolchain, 'usr', 'bin', 'swift-build')
51+
perform_build(args, swiftbuild_path, 'debug', 'Benchmark_Onone', '-Onone')
52+
perform_build(args, swiftbuild_path, 'release', 'Benchmark_O', '-O')
53+
4254

4355
if __name__ == "__main__":
4456
main()

utils/swift_build_support/swift_build_support/products/benchmarks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test(self, host_target):
3636
.release.
3737
"""
3838
cmdline = ['--num-iters=1', 'XorLoop']
39-
debug_bench = os.path.join(self.build_dir, 'debug', 'SwiftBench')
40-
shell.call([debug_bench] + cmdline)
39+
bench_Onone = os.path.join(self.build_dir, 'bin', 'Benchmark_Onone')
40+
shell.call([bench_Onone] + cmdline)
4141

42-
release_bench = os.path.join(self.build_dir, 'release', 'SwiftBench')
43-
shell.call([release_bench] + cmdline)
42+
bench_O = os.path.join(self.build_dir, 'bin', 'Benchmark_O')
43+
shell.call([bench_O] + cmdline)
4444

4545

4646
def run_build_script_helper(host_target, product, args):

0 commit comments

Comments
 (0)