blob: 571e84825279fdac6ad3f6bb2c086246a0a82a53 [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")
27 args = parser.parse_args()
28
29 # Copy all the interesting files into a temporary directory and run
30 # starterd. starterd expects the binaries it is going to run to be
31 # in its working directory; ping and pong also expect the configs
32 # to be placed in a specific location.
33 # TODO(james): Add piping (or just modify the config) such that
34 # ping and pong don't need specially placed configs and so that everything
35 # can take a new --shm_base to allow cleaner running on shared systems.
36 with tempfile.TemporaryDirectory() as tmpdir:
37 shutil.copy(args.starterd, tmpdir + "/starterd")
38 shutil.copy(args.ping, tmpdir + "/ping")
39 shutil.copy(args.pong, tmpdir + "/pong")
40 shutil.copy(args.starter_cmd, tmpdir + "/starter_cmd")
41 print(f"Running starter from {tmpdir}")
42
43 print(f"\n\nTo run starter_cmd, do:\ncd {tmpdir}\n./starter_cmd\n\n")
44
45 for config in args.configs.split(' '):
46 basename = os.path.basename(config)
47 suffix = '.'.join(basename.split('.')[1:])
48 # ping/pong expect configs at aos/events/pingpong_config.* but
49 # starter* expect them at ./config.*
50 destination = f"{tmpdir}/aos/events/{basename}"
51 os.makedirs(os.path.dirname(destination), exist_ok=True)
52 shutil.copy(config, destination)
53 shutil.copy(config, f"{tmpdir}/config.{suffix}")
54 args = [tmpdir + "/starterd"]
55 subprocess.run(args, check=True, cwd=tmpdir)