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 |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 10 | and aos_starter in particular. To run this, run: |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 11 | $ bazel run //aos/starter:starter_demo |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 12 | This will then print out instructions for running aos_starter. |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 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") |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 24 | parser.add_argument("binaries", nargs='+', help="Binaries to provide") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 25 | 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 Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 36 | for binary in args.binaries: |
| 37 | shutil.copy(binary, tmpdir + "/" + os.path.basename(binary)) |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 38 | print(f"Running starter from {tmpdir}") |
| 39 | |
James Kuszmaul | 60bb868 | 2023-08-07 07:39:34 -0700 | [diff] [blame] | 40 | print(f"\n\nTo run aos_starter, do:\ncd {tmpdir}\n./aos_starter\n\n") |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 41 | |
| 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 Kuszmaul | f668a6b | 2022-03-08 10:58:23 -0800 | [diff] [blame] | 50 | shutil.copy(config, f"{tmpdir}/aos_config.{suffix}") |
James Kuszmaul | b740f45 | 2023-11-14 17:44:29 -0800 | [diff] [blame^] | 51 | args = [tmpdir + "/starterd", "--version_string=starter_version"] |
James Kuszmaul | 77e1981 | 2021-05-19 21:36:10 -0700 | [diff] [blame] | 52 | subprocess.run(args, check=True, cwd=tmpdir) |