blob: 5a50890ff3a93e902f5e46941371f6a2a8db2778 [file] [log] [blame]
James Kuszmaul77e19812021-05-19 21:36:10 -07001import argparse
2import os
3import shutil
4import subprocess
5import sys
6import tempfile
7
8DESCRIPTION = """
9This script provides a convenient way to experiment with the starter
10and starter_cmd in particular. To run this, run:
11$ bazel run //aos/starter:starter_demo
12This will then print out instructions for running starter_cmd.
13
14If running via bazel, you should not need to specify the positional
15arguments.
16"""
17
18if __name__ == '__main__':
19 parser = argparse.ArgumentParser(
20 description=DESCRIPTION,
21 formatter_class=argparse.RawDescriptionHelpFormatter)
22 parser.add_argument("starterd", help="Location of starterd")
23 parser.add_argument("configs", help="Location of the config files")
24 parser.add_argument("ping", help="Location of ping")
25 parser.add_argument("pong", help="Location of pong")
26 parser.add_argument("starter_cmd", help="Location of starter_cmd")
Austin Schuh48d10d62022-10-16 22:19:23 -070027 parser.add_argument("aos_dump", help="Location of aos_dump")
28 parser.add_argument("logger_main", help="Location of logger_main")
James Kuszmaul77e19812021-05-19 21:36:10 -070029 args = parser.parse_args()
30
31 # Copy all the interesting files into a temporary directory and run
32 # starterd. starterd expects the binaries it is going to run to be
33 # in its working directory; ping and pong also expect the configs
34 # to be placed in a specific location.
35 # TODO(james): Add piping (or just modify the config) such that
36 # ping and pong don't need specially placed configs and so that everything
37 # can take a new --shm_base to allow cleaner running on shared systems.
38 with tempfile.TemporaryDirectory() as tmpdir:
39 shutil.copy(args.starterd, tmpdir + "/starterd")
40 shutil.copy(args.ping, tmpdir + "/ping")
41 shutil.copy(args.pong, tmpdir + "/pong")
42 shutil.copy(args.starter_cmd, tmpdir + "/starter_cmd")
Austin Schuh48d10d62022-10-16 22:19:23 -070043 shutil.copy(args.aos_dump, tmpdir + "/aos_dump")
44 shutil.copy(args.logger_main, tmpdir + "/logger_main")
James Kuszmaul77e19812021-05-19 21:36:10 -070045 print(f"Running starter from {tmpdir}")
46
47 print(f"\n\nTo run starter_cmd, do:\ncd {tmpdir}\n./starter_cmd\n\n")
48
49 for config in args.configs.split(' '):
50 basename = os.path.basename(config)
51 suffix = '.'.join(basename.split('.')[1:])
52 # ping/pong expect configs at aos/events/pingpong_config.* but
53 # starter* expect them at ./config.*
54 destination = f"{tmpdir}/aos/events/{basename}"
55 os.makedirs(os.path.dirname(destination), exist_ok=True)
56 shutil.copy(config, destination)
James Kuszmaulf668a6b2022-03-08 10:58:23 -080057 shutil.copy(config, f"{tmpdir}/aos_config.{suffix}")
James Kuszmaul77e19812021-05-19 21:36:10 -070058 args = [tmpdir + "/starterd"]
59 subprocess.run(args, check=True, cwd=tmpdir)