blob: 12d87757138f3b9b37fdbfb9a116ed14e261186e [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
James Kuszmaul60bb8682023-08-07 07:39:34 -070010and aos_starter in particular. To run this, run:
James Kuszmaul77e19812021-05-19 21:36:10 -070011$ bazel run //aos/starter:starter_demo
James Kuszmaul60bb8682023-08-07 07:39:34 -070012This will then print out instructions for running aos_starter.
James Kuszmaul77e19812021-05-19 21:36:10 -070013
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")
James Kuszmaul60bb8682023-08-07 07:39:34 -070024 parser.add_argument("binaries", nargs='+', help="Binaries to provide")
James Kuszmaul77e19812021-05-19 21:36:10 -070025 args = parser.parse_args()
26
27 # Copy all the interesting files into a temporary directory and run
28 # starterd. starterd expects the binaries it is going to run to be
29 # in its working directory; ping and pong also expect the configs
30 # to be placed in a specific location.
31 # TODO(james): Add piping (or just modify the config) such that
32 # ping and pong don't need specially placed configs and so that everything
33 # can take a new --shm_base to allow cleaner running on shared systems.
34 with tempfile.TemporaryDirectory() as tmpdir:
35 shutil.copy(args.starterd, tmpdir + "/starterd")
James Kuszmaul60bb8682023-08-07 07:39:34 -070036 for binary in args.binaries:
37 shutil.copy(binary, tmpdir + "/" + os.path.basename(binary))
James Kuszmaul77e19812021-05-19 21:36:10 -070038 print(f"Running starter from {tmpdir}")
39
James Kuszmaul60bb8682023-08-07 07:39:34 -070040 print(f"\n\nTo run aos_starter, do:\ncd {tmpdir}\n./aos_starter\n\n")
James Kuszmaul77e19812021-05-19 21:36:10 -070041
42 for config in args.configs.split(' '):
43 basename = os.path.basename(config)
44 suffix = '.'.join(basename.split('.')[1:])
45 # ping/pong expect configs at aos/events/pingpong_config.* but
46 # starter* expect them at ./config.*
47 destination = f"{tmpdir}/aos/events/{basename}"
48 os.makedirs(os.path.dirname(destination), exist_ok=True)
49 shutil.copy(config, destination)
James Kuszmaulf668a6b2022-03-08 10:58:23 -080050 shutil.copy(config, f"{tmpdir}/aos_config.{suffix}")
James Kuszmaulb740f452023-11-14 17:44:29 -080051 args = [tmpdir + "/starterd", "--version_string=starter_version"]
James Kuszmaul77e19812021-05-19 21:36:10 -070052 subprocess.run(args, check=True, cwd=tmpdir)