blob: 442e84e5786718db413c7289d42dc8a8b3cc6c9b [file] [log] [blame]
Corentin Wallez76b49d52022-04-12 16:10:41 +00001#!/usr/bin/env python3
Austin Eng1cdea902022-03-24 00:21:55 +00002#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Copyright 2022 The Dawn & Tint Authors
Austin Eng1cdea902022-03-24 00:21:55 +00004#
Austin Engcc2516a2023-10-17 20:57:54 +00005# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
Austin Eng1cdea902022-03-24 00:21:55 +00007#
Austin Engcc2516a2023-10-17 20:57:54 +00008# 1. Redistributions of source code must retain the above copyright notice, this
9# list of conditions and the following disclaimer.
Austin Eng1cdea902022-03-24 00:21:55 +000010#
Austin Engcc2516a2023-10-17 20:57:54 +000011# 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 Ninomiya5c780d72022-03-17 21:43:17 +000029
30import os
31import shutil
32import sys
33
34from dir_paths import webgpu_cts_root_dir, node_dir
35from tsc_ignore_errors import run_tsc_ignore_errors
36
37try:
38 old_sys_path = sys.path
39 sys.path = [node_dir] + sys.path
40
41 from node import RunNode
42finally:
43 sys.path = old_sys_path
44
45
46def compile_src(out_dir):
47 # First, clean the output directory so deleted files are pruned from old builds.
Austin Eng552045a2022-05-10 18:17:54 +000048 shutil.rmtree(out_dir, ignore_errors=True)
Kai Ninomiya5c780d72022-03-17 21:43:17 +000049
50 run_tsc_ignore_errors([
dan sinclairfb5a4922022-04-19 22:25:45 +000051 "--project",
52 os.path.join(webgpu_cts_root_dir, "tsconfig.json"),
53 "--outDir",
Kai Ninomiya5c780d72022-03-17 21:43:17 +000054 out_dir,
dan sinclairfb5a4922022-04-19 22:25:45 +000055 "--noEmit",
56 "false",
57 "--noEmitOnError",
58 "false",
59 "--declaration",
60 "false",
61 "--sourceMap",
62 "false",
63 "--target",
64 "ES2017",
Kai Ninomiya5c780d72022-03-17 21:43:17 +000065 ])
66
67
68def 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 Eng552045a2022-05-10 18:17:54 +000072 shutil.rmtree(out_dir, ignore_errors=True)
Kai Ninomiya5c780d72022-03-17 21:43:17 +000073
74 args = [
dan sinclairfb5a4922022-04-19 22:25:45 +000075 "--project",
76 os.path.join(webgpu_cts_root_dir, "node.tsconfig.json"),
77 "--outDir",
Kai Ninomiya5c780d72022-03-17 21:43:17 +000078 out_dir,
dan sinclairfb5a4922022-04-19 22:25:45 +000079 "--noEmit",
80 "false",
81 "--noEmitOnError",
82 "false",
83 "--declaration",
84 "false",
85 "--sourceMap",
86 "false",
87 "--target",
88 "ES6",
Kai Ninomiya5c780d72022-03-17 21:43:17 +000089 ]
90 args.extend(additional_args)
91
92 run_tsc_ignore_errors(args)
93
94
dan sinclairfb5a4922022-04-19 22:25:45 +000095if __name__ == "__main__":
Kai Ninomiya5c780d72022-03-17 21:43:17 +000096 if len(sys.argv) != 2:
dan sinclairfb5a4922022-04-19 22:25:45 +000097 print("Usage: compile_src.py GEN_DIR")
Kai Ninomiya5c780d72022-03-17 21:43:17 +000098 sys.exit(1)
99
100 gen_dir = sys.argv[1]
101
102 # Compile the CTS src.
dan sinclairfb5a4922022-04-19 22:25:45 +0000103 compile_src(os.path.join(gen_dir, "src"))
104 compile_src_for_node(os.path.join(gen_dir, "src-node"))
Kai Ninomiya5c780d72022-03-17 21:43:17 +0000105
dan sinclairfb5a4922022-04-19 22:25:45 +0000106 # Run gen_listings.js to overwrite the placeholder src/webgpu/listings.js created
Kai Ninomiya5c780d72022-03-17 21:43:17 +0000107 # from transpiling src/
108 RunNode([
dan sinclairfb5a4922022-04-19 22:25:45 +0000109 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 Ninomiya5c780d72022-03-17 21:43:17 +0000114 ])