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
= [
19 module
.exports = function (grunt
) {
22 // Project configuration.
24 pkg
: grunt
.file
.readJSON('package.json'),
29 'out-wpt': ['out-wpt/'],
30 'out-node': ['out-node/'],
36 args
: ['tools/gen_version'],
38 'generate-listings-and-webworkers': {
40 args
: ['tools/gen_listings_and_webworkers', 'gen/', ...kAllSuites
.map(s
=> 'src/' + s
)],
44 args
: ['tools/validate', ...kAllSuites
.map(s
=> 'src/' + s
)],
47 // Note this generates files into the src/ directory (not the gen/ directory).
49 args
: ['tools/gen_cache', 'src/webgpu'],
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': {
59 args
: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_unchunked.json'],
61 'write-out-wpt-cts-html-chunked2sec': {
63 args
: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_chunked2sec.json'],
65 'write-out-wpt-cts-html-withsomeworkers': {
67 args
: ['tools/gen_wpt_cts_html', 'tools/gen_wpt_cfg_withsomeworkers.json'],
71 args
: ['tools/run_node', 'unittests:*'],
76 'node_modules/@babel/cli/bin/babel',
77 '--extensions=.ts,.js',
81 // These files will be generated, instead of compiled from TypeScript.
82 '--ignore=src/common/internal/version.ts',
83 '--ignore=src/*/listing.ts',
89 'node_modules/@babel/cli/bin/babel',
90 '--extensions=.ts,.js',
91 '--source-maps=false',
92 '--delete-dir-on-start',
96 '--only=src/external/',
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',
112 'node_modules/typescript/lib/tsc.js',
114 'node.tsconfig.json',
122 'node_modules/@babel/cli/bin/babel',
124 '--out-dir=out/resources/',
131 'node_modules/@babel/cli/bin/babel',
133 '--out-dir=out-wpt/resources/',
137 'copy-assets-node': {
140 'node_modules/@babel/cli/bin/babel',
142 '--out-dir=out-node/resources/',
148 args
: ['node_modules/eslint/bin/eslint', ...kFilesForEslint
, '--max-warnings=0'],
152 args
: ['node_modules/eslint/bin/eslint', ...kFilesForEslint
, '--fix'],
154 'autoformat-out-wpt': {
156 // MAINTENANCE_TODO(gpuweb/cts#3128): This autoformat step is broken after a dependencies upgrade.
158 'node_modules/prettier/bin/prettier.cjs',
166 args
: ['node_modules/typedoc/bin/typedoc'],
168 'tsdoc-treatWarningsAsErrors': {
170 args
: ['node_modules/typedoc/bin/typedoc', '--treatWarningsAsErrors'],
175 args
: ['node_modules/http-server/bin/http-server', '-p8080', '-a127.0.0.1', '-c-1'],
181 // Must run after generate-common and run:build-out.
183 { expand
: true, dest
: 'out/', cwd
: 'gen', src
: 'common/internal/version.js' },
184 { expand
: true, dest
: 'out/', cwd
: 'gen', src
: '*/**/*.js' },
188 // Must run after generate-common and run:build-out-wpt.
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' }],
205 'write-out-wpt-cts-html-all': {
207 'run:write-out-wpt-cts-html',
208 'run:write-out-wpt-cts-html-chunked2sec',
209 'run:write-out-wpt-cts-html-withsomeworkers',
213 tasks
: ['build-standalone', 'build-wpt', 'run:build-out-node'],
219 'run:validate-cache',
222 'run:tsdoc-treatWarningsAsErrors',
225 'all-builds-and-checks': {
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', () => {
250 path
.join('node_modules', '.bin', 'tsc'),
251 ['--project', 'tsconfig.json', '--noEmit'],
259 grunt
.registerTask('generate-common', 'Generate files into gen/ and src/', [
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)', [
270 'copy:htmlfiles-to-out',
272 grunt
.registerTask('build-wpt', 'Build out-wpt/ (no checks; run after generate-common)', [
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)', [
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', () => {
292 =====================================================
293 ==== Build completed! Continuing checks/tests... ====
294 =====================================================`);
297 grunt
.registerTask('pre', ['all']);
299 registerTaskAndAddToHelp('all', 'Run all builds and checks', [
301 'concurrent:all-builds-and-checks',
303 registerTaskAndAddToHelp('standalone', 'Build standalone (out/) (no checks)', [
306 'build-done-message',
308 registerTaskAndAddToHelp('wpt', 'Build for WPT (out-wpt/) (no checks)', [
311 'build-done-message',
313 registerTaskAndAddToHelp('node', 'Build node (out-node/) (no checks)', [
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}`);