Corentin Wallez | 76b49d5 | 2022-04-12 16:10:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 2 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Copyright 2022 The Dawn & Tint Authors |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 4 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 7 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 8 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | # list of conditions and the following disclaimer. |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 10 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # |
| 15 | # 3. Neither the name of the copyright holder nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 29 | |
| 30 | import os |
| 31 | import shutil |
| 32 | import sys |
| 33 | |
| 34 | from dir_paths import webgpu_cts_root_dir, node_dir |
| 35 | from tsc_ignore_errors import run_tsc_ignore_errors |
| 36 | |
| 37 | try: |
| 38 | old_sys_path = sys.path |
| 39 | sys.path = [node_dir] + sys.path |
| 40 | |
| 41 | from node import RunNode |
| 42 | finally: |
| 43 | sys.path = old_sys_path |
| 44 | |
| 45 | |
| 46 | def compile_src(out_dir): |
| 47 | # First, clean the output directory so deleted files are pruned from old builds. |
Austin Eng | 552045a | 2022-05-10 18:17:54 +0000 | [diff] [blame] | 48 | shutil.rmtree(out_dir, ignore_errors=True) |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 49 | |
| 50 | run_tsc_ignore_errors([ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 51 | "--project", |
| 52 | os.path.join(webgpu_cts_root_dir, "tsconfig.json"), |
| 53 | "--outDir", |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 54 | out_dir, |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 55 | "--noEmit", |
| 56 | "false", |
| 57 | "--noEmitOnError", |
| 58 | "false", |
| 59 | "--declaration", |
| 60 | "false", |
| 61 | "--sourceMap", |
| 62 | "false", |
| 63 | "--target", |
| 64 | "ES2017", |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 65 | ]) |
| 66 | |
| 67 | |
| 68 | def compile_src_for_node(out_dir, additional_args=None, clean=True): |
| 69 | additional_args = additional_args or [] |
| 70 | if clean: |
| 71 | # First, clean the output directory so deleted files are pruned from old builds. |
Austin Eng | 552045a | 2022-05-10 18:17:54 +0000 | [diff] [blame] | 72 | shutil.rmtree(out_dir, ignore_errors=True) |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 73 | |
| 74 | args = [ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 75 | "--project", |
| 76 | os.path.join(webgpu_cts_root_dir, "node.tsconfig.json"), |
| 77 | "--outDir", |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 78 | out_dir, |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 79 | "--noEmit", |
| 80 | "false", |
| 81 | "--noEmitOnError", |
| 82 | "false", |
| 83 | "--declaration", |
| 84 | "false", |
| 85 | "--sourceMap", |
| 86 | "false", |
| 87 | "--target", |
| 88 | "ES6", |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 89 | ] |
| 90 | args.extend(additional_args) |
| 91 | |
| 92 | run_tsc_ignore_errors(args) |
| 93 | |
| 94 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 95 | if __name__ == "__main__": |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 96 | if len(sys.argv) != 2: |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 97 | print("Usage: compile_src.py GEN_DIR") |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 98 | sys.exit(1) |
| 99 | |
| 100 | gen_dir = sys.argv[1] |
| 101 | |
| 102 | # Compile the CTS src. |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 103 | compile_src(os.path.join(gen_dir, "src")) |
| 104 | compile_src_for_node(os.path.join(gen_dir, "src-node")) |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 105 | |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 106 | # Run gen_listings.js to overwrite the placeholder src/webgpu/listings.js created |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 107 | # from transpiling src/ |
| 108 | RunNode([ |
dan sinclair | fb5a492 | 2022-04-19 22:25:45 +0000 | [diff] [blame] | 109 | os.path.join(gen_dir, "src-node", "common", "tools", |
| 110 | "gen_listings.js"), |
| 111 | "--no-validate", |
| 112 | os.path.join(gen_dir, "src"), |
| 113 | os.path.join(gen_dir, "src-node", "webgpu"), |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 114 | ]) |