|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +from __future__ import print_function |
| 4 | + |
| 5 | +import argparse |
| 6 | +import os |
| 7 | +import shutil |
| 8 | +import subprocess |
| 9 | + |
| 10 | + |
| 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']) |
| 15 | + |
| 16 | + inner_build_dir = os.path.join(args.build_path, binary_name) |
| 17 | + swiftbuild_args = [ |
| 18 | + swiftbuild_path, |
| 19 | + '--package-path', args.package_path, |
| 20 | + '--build-path', inner_build_dir, |
| 21 | + '--configuration', config, |
| 22 | + '-Xswiftc', '-Xllvm', |
| 23 | + '-Xswiftc', '-align-module-to-page-size', |
| 24 | + '-Xswiftc', opt_flag, |
| 25 | + ] |
| 26 | + if args.verbose: |
| 27 | + swiftbuild_args.append('--verbose') |
| 28 | + subprocess.call(swiftbuild_args) |
| 29 | + |
| 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 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + main() |
0 commit comments