James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 1 | import argparse |
| 2 | import os |
| 3 | import shutil |
| 4 | import subprocess |
| 5 | import sys |
| 6 | import tempfile |
| 7 | |
| 8 | DESCRIPTION = """ |
| 9 | This script provides a convenient way to experiment with the starter |
| 10 | and starter_cmd in particular. To run this, run: |
| 11 | $ bazel run //aos/starter:starter_demo |
| 12 | This will then print out instructions for running starter_cmd. |
| 13 | |
| 14 | If running via bazel, you should not need to specify the positional |
| 15 | arguments. |
| 16 | """ |
| 17 | |
| 18 | if __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 Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 27 | parser.add_argument("aos_dump", help="Location of aos_dump") |
| 28 | parser.add_argument("logger_main", help="Location of logger_main") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 29 | 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 Schuh | 48d10d6 | 2022-10-16 22:19:23 -0700 | [diff] [blame] | 43 | shutil.copy(args.aos_dump, tmpdir + "/aos_dump") |
| 44 | shutil.copy(args.logger_main, tmpdir + "/logger_main") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 45 | 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 Kuszmaul | f668a6b | 2022-03-08 10:58:23 -0800 | [diff] [blame] | 57 | shutil.copy(config, f"{tmpdir}/aos_config.{suffix}") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 58 | args = [tmpdir + "/starterd"] |
| 59 | subprocess.run(args, check=True, cwd=tmpdir) |