| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Creates a script to run a Fushsia test.""" |
| 8 |
| 9 import argparse |
| 10 import os |
| 11 import re |
| 12 import sys |
| 13 |
| 14 |
| 15 SCRIPT_TEMPLATE = """\ |
| 16 #!/usr/bin/env python |
| 17 # |
| 18 # This file was generated by build/fuchsia/create_test_runner_script.py |
| 19 |
| 20 import os |
| 21 import sys |
| 22 |
| 23 def main(): |
| 24 script_directory = os.path.dirname(__file__) |
| 25 |
| 26 def ResolvePath(path): |
| 27 \"\"\"Returns an absolute filepath given a path relative to this script. |
| 28 \"\"\" |
| 29 return os.path.abspath(os.path.join(script_directory, path)) |
| 30 |
| 31 test_runner_path = ResolvePath('{test_runner_path}') |
| 32 test_runner_args = {test_runner_args} |
| 33 test_runner_path_args = {test_runner_path_args} |
| 34 for arg, path in test_runner_path_args: |
| 35 test_runner_args.extend([arg, ResolvePath(path)]) |
| 36 |
| 37 os.execv(test_runner_path, |
| 38 [test_runner_path] + test_runner_args + sys.argv[1:]) |
| 39 |
| 40 if __name__ == '__main__': |
| 41 sys.exit(main()) |
| 42 """ |
| 43 |
| 44 |
| 45 def MakeDirectory(dir_path): |
| 46 try: |
| 47 os.makedirs(dir_path) |
| 48 except OSError: |
| 49 pass |
| 50 |
| 51 |
| 52 def WriteDepfile(depfile_path, first_gn_output, inputs=None): |
| 53 assert depfile_path != first_gn_output |
| 54 inputs = inputs or [] |
| 55 MakeDirectory(os.path.dirname(depfile_path)) |
| 56 # Ninja does not support multiple outputs in depfiles. |
| 57 with open(depfile_path, 'w') as depfile: |
| 58 depfile.write(first_gn_output.replace(' ', '\\ ')) |
| 59 depfile.write(': ') |
| 60 depfile.write(' '.join(i.replace(' ', '\\ ') for i in inputs)) |
| 61 depfile.write('\n') |
| 62 |
| 63 |
| 64 def main(args): |
| 65 parser = argparse.ArgumentParser() |
| 66 parser.add_argument('--script-output-path', |
| 67 help='Output path for executable script.') |
| 68 parser.add_argument('--depfile', |
| 69 help='Path to the depfile. This must be specified as ' |
| 70 "the action's first output.") |
| 71 parser.add_argument('--test-runner-path', |
| 72 help='Path to test_runner.py (optional).') |
| 73 group = parser.add_argument_group('Test runner path arguments.') |
| 74 group.add_argument('--output-directory') |
| 75 group.add_argument('--runtime-deps-path') |
| 76 group.add_argument('--test-name') |
| 77 args, test_runner_args = parser.parse_known_args(args) |
| 78 |
| 79 def RelativizePathToScript(path): |
| 80 """Returns the path relative to the output script directory.""" |
| 81 return os.path.relpath(path, os.path.dirname(args.script_output_path)) |
| 82 |
| 83 test_runner_path = args.test_runner_path or os.path.join( |
| 84 os.path.dirname(__file__), 'test_runner.py') |
| 85 test_runner_path = RelativizePathToScript(test_runner_path) |
| 86 |
| 87 test_runner_path_args = [] |
| 88 if args.output_directory: |
| 89 test_runner_path_args.append( |
| 90 ('--output-directory', RelativizePathToScript(args.output_directory))) |
| 91 if args.runtime_deps_path: |
| 92 test_runner_path_args.append( |
| 93 ('--runtime-deps-path', RelativizePathToScript(args.runtime_deps_path))) |
| 94 if args.test_name: |
| 95 test_runner_path_args.append( |
| 96 ('--test-name', RelativizePathToScript(args.test_name))) |
| 97 |
| 98 with open(args.script_output_path, 'w') as script: |
| 99 script.write(SCRIPT_TEMPLATE.format( |
| 100 test_runner_path=str(test_runner_path), |
| 101 test_runner_args=str(test_runner_args), |
| 102 test_runner_path_args=str(test_runner_path_args))) |
| 103 |
| 104 os.chmod(args.script_output_path, 0750) |
| 105 |
| 106 if args.depfile: |
| 107 WriteDepfile(args.depfile, args.script_output_path, |
| 108 [__file__]) |
| 109 |
| 110 |
| 111 if __name__ == '__main__': |
| 112 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |