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") |
| 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) |
James Kuszmaul | f668a6b | 2022-03-08 10:58:23 -0800 | [diff] [blame^] | 53 | shutil.copy(config, f"{tmpdir}/aos_config.{suffix}") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 54 | args = [tmpdir + "/starterd"] |
| 55 | subprocess.run(args, check=True, cwd=tmpdir) |