blob: c92c8a7dd13521ca4342e46e444b2cc75d1dff3b [file] [log] [blame]
Randall Bosettiee604ea2020-07-27 18:47:41 +00001#!/usr/bin/env python3.8
Joshua Seatonfebb0232019-03-13 23:29:23 -07002# Copyright 2019 The Fuchsia Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import argparse
7import os
8import stat
9import string
10import sys
11
Joshua Seaton8bc918c2019-12-09 04:33:49 +000012
Joshua Seatonfebb0232019-03-13 23:29:23 -070013def main():
Joshua Seaton8bc918c2019-12-09 04:33:49 +000014 parser = argparse.ArgumentParser(
15 description='Generate a script that invokes a Dart application')
16 parser.add_argument(
17 '--wd',
18 help='Path to the working directory, relative to that of the script',
19 required=True)
20 parser.add_argument(
21 '--out', help='Path to the invocation file to generate', required=True)
22 parser.add_argument(
23 '--dart',
24 help='Path to the Dart binary, relative to the working directory',
25 required=True)
26 parser.add_argument(
27 '--snapshot',
28 help='Path to the binary snapshot, relative to the working directory',
29 required=True)
30 parser.add_argument(
31 '--args',
32 help='Command-line arguments to prepend to those passed to the script',
33 required=False,
34 default='')
35 args = parser.parse_args()
Joshua Seatonfebb0232019-03-13 23:29:23 -070036
Joshua Seaton8bc918c2019-12-09 04:33:49 +000037 app_file = args.out
38 app_path = os.path.dirname(app_file)
39 if not os.path.exists(app_path):
40 os.makedirs(app_path)
Joshua Seatonfebb0232019-03-13 23:29:23 -070041
Joshua Seaton8bc918c2019-12-09 04:33:49 +000042 script_template = string.Template(
43 '''#!/bin/sh
Joshua Seatonfebb0232019-03-13 23:29:23 -070044# DO NOT EDIT
45# This script is generated by:
Gary Miguel3d25ef42020-06-16 22:52:06 +000046# //build/dart/gen_dart_test_invocation.py
Joshua Seatonfebb0232019-03-13 23:29:23 -070047
48cd "$$(dirname $$0)/$wd"
49
50$dart \\
51 $snapshot \\
Ross Wang09f5ce92019-04-04 23:30:07 +000052 $args \\
Joshua Seatonfebb0232019-03-13 23:29:23 -070053 "$$@"
54''')
Joshua Seaton8bc918c2019-12-09 04:33:49 +000055 with open(app_file, 'w') as file:
56 file.write(script_template.substitute(args.__dict__))
57 permissions = (
58 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP |
59 stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH)
60 os.chmod(app_file, permissions)
Joshua Seatonfebb0232019-03-13 23:29:23 -070061
62
63if __name__ == '__main__':
Joshua Seaton8bc918c2019-12-09 04:33:49 +000064 sys.exit(main())