blob: 351a75ee236e4a661a35022c71bf83334cf576af [file] [log] [blame]
#!/usr/bin/env fuchsia-vendored-python
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import os
import stat
import string
import sys
def main():
parser = argparse.ArgumentParser(
description="Generate a script that invokes a Dart application"
)
parser.add_argument(
"--wd",
help="Path to the working directory, relative to that of the script",
required=True,
)
parser.add_argument(
"--out", help="Path to the invocation file to generate", required=True
)
parser.add_argument(
"--dart",
help="Path to the Dart binary, relative to the working directory",
required=True,
)
parser.add_argument(
"--snapshot",
help="Path to the binary snapshot, relative to the working directory",
required=True,
)
parser.add_argument(
"--args",
help="Command-line arguments to prepend to those passed to the script",
required=False,
default="",
)
args = parser.parse_args()
app_file = args.out
app_path = os.path.dirname(app_file)
if app_path == "":
# This script is intended for non-device tests, which do not sit
# in the root of the output directory. Get that out of the way here.
raise ValueError("empty directory for --out parameter is not expected")
if not os.path.exists(app_path):
os.makedirs(app_path)
script_template = string.Template(
"""#!/bin/sh
# DO NOT EDIT
# This script is generated by:
# //build/dart/gen_dart_test_invocation.py
cd "$$(dirname $$0)/$wd"
$dart \\
$snapshot \\
$args \\
"$$@"
"""
)
with open(app_file, "w") as file:
file.write(script_template.substitute(args.__dict__))
permissions = (
stat.S_IRUSR
| stat.S_IWUSR
| stat.S_IXUSR
| stat.S_IRGRP
| stat.S_IWGRP
| stat.S_IXGRP
| stat.S_IROTH
)
os.chmod(app_file, permissions)
if __name__ == "__main__":
sys.exit(main())