Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / webgpu / tests / cts / checkout / Gruntfile.js
blob54092f99d1b7debc864a6b5bd48e68dca1067100
1 /* eslint-disable node/no-unpublished-require */
2 /* eslint-disable no-console */
4 const timer = require('grunt-timer');
5 const { spawnSync } = require('child_process');
6 const path = require('path');
8 const kAllSuites = ['webgpu', 'stress', 'manual', 'unittests', 'demo'];
10 const kFilesForEslint = [
11 // TS
12 'src/**/*.ts',
13 // JS
14 '*.js',
15 '.*.js',
16 'tools/**/*.js',
19 module.exports = function (grunt) {
20 timer.init(grunt);
22 // Project configuration.
23 grunt.initConfig({
24 pkg: grunt.file.readJSON('package.json'),
26 clean: {
27 gen: ['gen/'],
28 out: ['out/'],
29 'out-wpt': ['out-wpt/'],
30 'out-node': ['out-node/'],
33 run: {
34 'generate-version': {
35 cmd: 'node',
36 args: ['tools/gen_version'],
38 'generate-listings-and-webworkers': {
39 cmd: 'node',
40 args: ['tools/gen_listings_and_webworkers', 'gen/', ...kAllSuites.map(s => 'src/' + s)],
42 validate: {
43 cmd: 'node',
44 args: ['tools/validate', ...kAllSuites.map(s => 'src/' + s)],
46 'generate-cache': {
47 // Note this generates files into the src/ directory (not the gen/ directory).
48 cmd: 'node',
49 args: ['tools/gen_cache', 'src/webgpu'],
51 'validate-cache': {
52 cmd: 'node',
53 args: ['tools/gen_cache', 'src/webgpu', '--validate'],
55 // Note these generate `cts*.https.html` directly into the out-wpt/ directory rather than
56 // the gen/ directory (as well as generating a `webgpu_variant_list*.json` file in gen/).
57 'write-out-wpt-cts-html': {
58 cmd: 'node',
59 args: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_unchunked.json'],
61 'write-out-wpt-cts-html-chunked2sec': {
62 cmd: 'node',
63 args: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_chunked2sec.json'],
65 'write-out-wpt-cts-html-withsomeworkers': {
66 cmd: 'node',
67 args: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_withsomeworkers.json'],
69 unittest: {
70 cmd: 'node',
71 args: ['tools/run_node', 'unittests:*'],
73 'build-out': {
74 cmd: 'node',
75 args: [
76 'node_modules/@babel/cli/bin/babel',
77 '--extensions=.ts,.js',
78 '--source-maps=true',
79 '--out-dir=out/',
80 'src/',
81 // These files will be generated, instead of compiled from TypeScript.
82 '--ignore=src/common/internal/version.ts',
83 '--ignore=src/*/listing.ts',
86 'build-out-wpt': {
87 cmd: 'node',
88 args: [
89 'node_modules/@babel/cli/bin/babel',
90 '--extensions=.ts,.js',
91 '--source-maps=false',
92 '--delete-dir-on-start',
93 '--out-dir=out-wpt/',
94 'src/',
95 '--only=src/common/',
96 '--only=src/external/',
97 '--only=src/webgpu/',
98 // These files will be generated, instead of compiled from TypeScript.
99 '--ignore=src/common/internal/version.ts',
100 '--ignore=src/*/listing.ts',
101 // These files are only used by non-WPT builds.
102 '--ignore=src/common/runtime/cmdline.ts',
103 '--ignore=src/common/runtime/server.ts',
104 '--ignore=src/common/runtime/standalone.ts',
105 '--ignore=src/common/runtime/helper/sys.ts',
106 '--ignore=src/common/tools',
109 'build-out-node': {
110 cmd: 'node',
111 args: [
112 'node_modules/typescript/lib/tsc.js',
113 '--project',
114 'node.tsconfig.json',
115 '--outDir',
116 'out-node/',
119 'copy-assets': {
120 cmd: 'node',
121 args: [
122 'node_modules/@babel/cli/bin/babel',
123 'src/resources/',
124 '--out-dir=out/resources/',
125 '--copy-files',
128 'copy-assets-wpt': {
129 cmd: 'node',
130 args: [
131 'node_modules/@babel/cli/bin/babel',
132 'src/resources/',
133 '--out-dir=out-wpt/resources/',
134 '--copy-files',
137 'copy-assets-node': {
138 cmd: 'node',
139 args: [
140 'node_modules/@babel/cli/bin/babel',
141 'src/resources/',
142 '--out-dir=out-node/resources/',
143 '--copy-files',
146 lint: {
147 cmd: 'node',
148 args: ['node_modules/eslint/bin/eslint', ...kFilesForEslint, '--max-warnings=0'],
150 fix: {
151 cmd: 'node',
152 args: ['node_modules/eslint/bin/eslint', ...kFilesForEslint, '--fix'],
154 'autoformat-out-wpt': {
155 cmd: 'node',
156 // MAINTENANCE_TODO(gpuweb/cts#3128): This autoformat step is broken after a dependencies upgrade.
157 args: [
158 'node_modules/prettier/bin/prettier.cjs',
159 '--log-level=warn',
160 '--write',
161 'out-wpt/**/*.js',
164 tsdoc: {
165 cmd: 'node',
166 args: ['node_modules/typedoc/bin/typedoc'],
168 'tsdoc-treatWarningsAsErrors': {
169 cmd: 'node',
170 args: ['node_modules/typedoc/bin/typedoc', '--treatWarningsAsErrors'],
173 serve: {
174 cmd: 'node',
175 args: ['node_modules/http-server/bin/http-server', '-p8080', '-a127.0.0.1', '-c-1'],
179 copy: {
180 'gen-to-out': {
181 // Must run after generate-common and run:build-out.
182 files: [
183 { expand: true, dest: 'out/', cwd: 'gen', src: 'common/internal/version.js' },
184 { expand: true, dest: 'out/', cwd: 'gen', src: '*/**/*.js' },
187 'gen-to-out-wpt': {
188 // Must run after generate-common and run:build-out-wpt.
189 files: [
190 { expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'common/internal/version.js' },
191 { expand: true, dest: 'out-wpt/', cwd: 'gen', src: 'webgpu/**/*.js' },
194 'htmlfiles-to-out': {
195 // Must run after run:build-out.
196 files: [{ expand: true, dest: 'out/', cwd: 'src', src: 'webgpu/**/*.html' }],
198 'htmlfiles-to-out-wpt': {
199 // Must run after run:build-out-wpt.
200 files: [{ expand: true, dest: 'out-wpt/', cwd: 'src', src: 'webgpu/**/*.html' }],
204 concurrent: {
205 'write-out-wpt-cts-html-all': {
206 tasks: [
207 'run:write-out-wpt-cts-html',
208 'run:write-out-wpt-cts-html-chunked2sec',
209 'run:write-out-wpt-cts-html-withsomeworkers',
212 'all-builds': {
213 tasks: ['build-standalone', 'build-wpt', 'run:build-out-node'],
215 'all-checks': {
216 tasks: [
217 'ts-check',
218 'run:validate',
219 'run:validate-cache',
220 'run:unittest',
221 'run:lint',
222 'run:tsdoc-treatWarningsAsErrors',
225 'all-builds-and-checks': {
226 tasks: [
227 'build-all', // Internally concurrent
228 'concurrent:all-checks',
234 grunt.loadNpmTasks('grunt-contrib-clean');
235 grunt.loadNpmTasks('grunt-contrib-copy');
236 grunt.loadNpmTasks('grunt-concurrent');
237 grunt.loadNpmTasks('grunt-run');
239 const helpMessageTasks = [];
240 function registerTaskAndAddToHelp(name, desc, deps) {
241 grunt.registerTask(name, deps);
242 addExistingTaskToHelp(name, desc);
244 function addExistingTaskToHelp(name, desc) {
245 helpMessageTasks.push({ name, desc });
248 grunt.registerTask('ts-check', () => {
249 spawnSync(
250 path.join('node_modules', '.bin', 'tsc'),
251 ['--project', 'tsconfig.json', '--noEmit'],
253 shell: true,
254 stdio: 'inherit',
259 grunt.registerTask('generate-common', 'Generate files into gen/ and src/', [
260 'clean:gen',
261 'run:generate-version',
262 'run:generate-listings-and-webworkers',
263 'run:generate-cache',
265 grunt.registerTask('build-standalone', 'Build out/ (no checks; run after generate-common)', [
266 'clean:out',
267 'run:build-out',
268 'run:copy-assets',
269 'copy:gen-to-out',
270 'copy:htmlfiles-to-out',
272 grunt.registerTask('build-wpt', 'Build out-wpt/ (no checks; run after generate-common)', [
273 'clean:out-wpt',
274 'run:build-out-wpt',
275 'run:copy-assets-wpt',
276 'copy:gen-to-out-wpt',
277 'copy:htmlfiles-to-out-wpt',
278 'concurrent:write-out-wpt-cts-html-all',
279 'run:autoformat-out-wpt',
281 grunt.registerTask('build-node', 'Build out-node/ (no checks; run after generate-common)', [
282 'clean:out-node',
283 'run:build-out-node',
284 'run:copy-assets-node',
286 grunt.registerTask('build-all', 'Build out*/ (no checks; run after generate-common)', [
287 'concurrent:all-builds',
288 'build-done-message',
290 grunt.registerTask('build-done-message', () => {
291 grunt.log.writeln(`\
292 =====================================================
293 ==== Build completed! Continuing checks/tests... ====
294 =====================================================`);
297 grunt.registerTask('pre', ['all']);
299 registerTaskAndAddToHelp('all', 'Run all builds and checks', [
300 'generate-common',
301 'concurrent:all-builds-and-checks',
303 registerTaskAndAddToHelp('standalone', 'Build standalone (out/) (no checks)', [
304 'generate-common',
305 'build-standalone',
306 'build-done-message',
308 registerTaskAndAddToHelp('wpt', 'Build for WPT (out-wpt/) (no checks)', [
309 'generate-common',
310 'build-wpt',
311 'build-done-message',
313 registerTaskAndAddToHelp('node', 'Build node (out-node/) (no checks)', [
314 'generate-common',
315 'build-node',
316 'build-done-message',
318 registerTaskAndAddToHelp('checks', 'Run all checks (and build tsdoc)', ['concurrent:all-checks']);
319 registerTaskAndAddToHelp('unittest', 'Just run unittests', ['run:unittest']);
320 registerTaskAndAddToHelp('typecheck', 'Just typecheck', ['ts-check']);
321 registerTaskAndAddToHelp('tsdoc', 'Just build tsdoc', ['run:tsdoc']);
323 registerTaskAndAddToHelp('serve', 'Serve out/ (without building anything)', ['run:serve']);
324 registerTaskAndAddToHelp('lint', 'Check lint and formatting', ['run:lint']);
325 registerTaskAndAddToHelp('fix', 'Fix lint and formatting', ['run:fix']);
327 addExistingTaskToHelp('clean', 'Delete built and generated files');
329 grunt.registerTask('default', '', () => {
330 console.error('\nRecommended tasks:');
331 const nameColumnSize = Math.max(...helpMessageTasks.map(({ name }) => name.length));
332 for (const { name, desc } of helpMessageTasks) {
333 console.error(`$ grunt ${name.padEnd(nameColumnSize)} # ${desc}`);