Austin Eng | 92b32e8 | 2022-11-21 15:16:51 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright 2022 The Dawn Authors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import argparse |
| 18 | import os |
| 19 | import sys |
| 20 | |
| 21 | from dir_paths import node_dir |
| 22 | |
| 23 | |
| 24 | def gen_cache(js_script, out_dir): |
| 25 | old_sys_path = sys.path |
| 26 | try: |
| 27 | sys.path = old_sys_path + [node_dir] |
| 28 | from node import RunNode |
| 29 | finally: |
| 30 | sys.path = old_sys_path |
| 31 | |
| 32 | # Save the cwd. gen_cache.js needs to be run from a specific directory. |
| 33 | cwd = os.getcwd() |
| 34 | cts_dir = os.path.realpath( |
| 35 | os.path.join(cwd, os.path.dirname(js_script), '..', '..', '..')) |
| 36 | os.chdir(cts_dir) |
| 37 | RunNode([ |
| 38 | os.path.join(cwd, js_script), |
| 39 | os.path.join(cwd, out_dir), |
| 40 | os.path.join('src-node', 'webgpu') |
| 41 | ]) |
| 42 | |
| 43 | |
| 44 | # Generate a cache for CTS runs. |
| 45 | if __name__ == '__main__': |
| 46 | parser = argparse.ArgumentParser() |
| 47 | parser.add_argument('js_script', help='Path to gen_cache.js') |
| 48 | parser.add_argument('out_dir', help='Output directory for the cache') |
| 49 | args = parser.parse_args() |
| 50 | |
| 51 | gen_cache(args.js_script, args.out_dir) |