Skip to content

Commit db412d7

Browse files
authored
Factor out and dedup 'validate' step of presubmit (gpuweb#2608)
Prior to this, the gen_listings script actually did a lot of bonus work on top of generating listings: it validated a bunch of things about test files and tests. However this is (1) misleading and (2) called twice during the build process, once for standalone and once for wpt. This change splits validation out into a separate script, and also runs both gen_listings and validate only once instead of twice. On my machine, gen_listings takes 0.75 seconds without validation, but validation adds about 16s. So now, even though crawling happens twice (2 originally, minus 1 by deduplicating, plus 1 in the validate tool) this shaves that off the presubmit time: before: 143s, after: 129s. OK, so it's still really slow, but it's better. Also, removes the quiet-grunt setup that made this really hard to see due to quieting all of the build steps. It was added because development required constant command-line builds, but now that we have the dev server I don't think anyone is doing this anymore. Also also, fixes a bug in gen_version which was preventing it from running without an existing standalone build.
1 parent e218a9a commit db412d7

File tree

8 files changed

+63
-41
lines changed

8 files changed

+63
-41
lines changed

Diff for: Gruntfile.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ module.exports = function (grunt) {
2020
cmd: 'node',
2121
args: ['tools/gen_listings', 'out/', 'src/webgpu', 'src/stress', 'src/manual', 'src/unittests', 'src/demo'],
2222
},
23+
validate: {
24+
cmd: 'node',
25+
args: ['tools/validate', 'src/webgpu', 'src/stress', 'src/manual', 'src/unittests', 'src/demo'],
26+
},
2327
'generate-wpt-cts-html': {
2428
cmd: 'node',
2529
args: ['tools/gen_wpt_cts_html', 'out-wpt/cts.https.html', 'src/common/templates/cts.https.html'],
@@ -155,23 +159,16 @@ module.exports = function (grunt) {
155159
helpMessageTasks.push({ name, desc });
156160
}
157161

158-
grunt.registerTask('set-quiet-mode', () => {
159-
grunt.log.write('Running tasks');
160-
require('quiet-grunt');
161-
});
162-
163-
grunt.registerTask('build-standalone', 'Build out/ (no checks, no WPT)', [
162+
grunt.registerTask('build-standalone', 'Build out/ (no listings, no checks, no WPT)', [
164163
'run:build-out',
165164
'run:copy-assets',
166165
'run:generate-version',
167-
'run:generate-listings',
168166
]);
169-
grunt.registerTask('build-wpt', 'Build out/ (no checks)', [
167+
grunt.registerTask('build-wpt', 'Build out-wpt/ (no checks; run after generate-listings)', [
170168
'run:build-out-wpt',
171169
'run:copy-assets-wpt',
172170
'run:autoformat-out-wpt',
173171
'run:generate-version',
174-
'run:generate-listings',
175172
'copy:out-wpt-generated',
176173
'copy:out-wpt-htmlfiles',
177174
'run:generate-wpt-cts-html',
@@ -181,8 +178,9 @@ module.exports = function (grunt) {
181178
});
182179

183180
registerTaskAndAddToHelp('pre', 'Run all presubmit checks: standalone+wpt+typecheck+unittest+lint', [
184-
'set-quiet-mode',
185181
'clean',
182+
'run:generate-listings',
183+
'run:validate',
186184
'build-standalone',
187185
'build-wpt',
188186
'run:build-out-node',
@@ -194,23 +192,24 @@ module.exports = function (grunt) {
194192
'run:tsdoc-treatWarningsAsErrors',
195193
]);
196194
registerTaskAndAddToHelp('standalone', 'Build standalone and typecheck', [
197-
'set-quiet-mode',
195+
'run:generate-listings',
198196
'build-standalone',
199197
'build-done-message',
198+
'run:validate',
200199
'ts:check',
201200
]);
202201
registerTaskAndAddToHelp('wpt', 'Build for WPT and typecheck', [
203-
'set-quiet-mode',
202+
'run:generate-listings',
204203
'build-wpt',
205204
'build-done-message',
205+
'run:validate',
206206
'ts:check',
207207
]);
208208
registerTaskAndAddToHelp('unittest', 'Build standalone, typecheck, and unittest', [
209209
'standalone',
210210
'run:unittest',
211211
]);
212212
registerTaskAndAddToHelp('check', 'Just typecheck', [
213-
'set-quiet-mode',
214213
'ts:check',
215214
]);
216215

Diff for: package-lock.json

-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"pngjs": "^6.0.0",
6969
"portfinder": "^1.0.32",
7070
"prettier": "~2.1.2",
71-
"quiet-grunt": "^0.2.3",
7271
"screenshot-ftw": "^1.0.5",
7372
"serve-index": "^1.9.1",
7473
"ts-node": "^9.0.0",

Diff for: src/common/tools/crawl.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ async function crawlFilesRecursively(dir: string): Promise<string[]> {
4343
);
4444
}
4545

46-
export async function crawl(
47-
suiteDir: string,
48-
validate: boolean = true
49-
): Promise<TestSuiteListingEntry[]> {
46+
export async function crawl(suiteDir: string, validate: boolean): Promise<TestSuiteListingEntry[]> {
5047
if (!fs.existsSync(suiteDir)) {
5148
console.error(`Could not find ${suiteDir}`);
5249
process.exit(1);

Diff for: src/common/tools/gen_listings.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ into OUT_DIR/{suite}/listing.js. Example:
1313
1414
Options:
1515
--help Print this message and exit.
16-
--no-validate Whether to validate test modules while crawling.
1716
`);
1817
process.exit(rc);
1918
}
@@ -23,11 +22,10 @@ if (argv.indexOf('--help') !== -1) {
2322
usage(0);
2423
}
2524

26-
let validate = true;
2725
{
26+
// Ignore old argument that is now the default
2827
const i = argv.indexOf('--no-validate');
2928
if (i !== -1) {
30-
validate = false;
3129
argv.splice(i, 1);
3230
}
3331
}
@@ -40,10 +38,9 @@ const myself = 'src/common/tools/gen_listings.ts';
4038

4139
const outDir = argv[2];
4240

43-
void (async () => {
44-
for (const suiteDir of argv.slice(3)) {
45-
const listing = await crawl(suiteDir, validate);
46-
41+
for (const suiteDir of argv.slice(3)) {
42+
// Run concurrently for each suite (might be a tiny bit more efficient)
43+
void crawl(suiteDir, false).then(listing => {
4744
const suite = path.basename(suiteDir);
4845
const outFile = path.normalize(path.join(outDir, `${suite}/listing.js`));
4946
fs.mkdirSync(path.join(outDir, suite), { recursive: true });
@@ -55,10 +52,12 @@ void (async () => {
5552
export const listing = ${JSON.stringify(listing, undefined, 2)};
5653
`
5754
);
55+
56+
// If there was a sourcemap for the file we just replaced, delete it.
5857
try {
5958
fs.unlinkSync(outFile + '.map');
6059
} catch (ex) {
6160
// ignore if file didn't exist
6261
}
63-
}
64-
})();
62+
});
63+
}

Diff for: src/common/tools/validate.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as process from 'process';
2+
3+
import { crawl } from './crawl.js';
4+
5+
function usage(rc: number): void {
6+
console.error(`Usage: tools/validate [options] [SUITE_DIRS...]
7+
8+
For each suite in SUITE_DIRS, validate some properties about the file:
9+
- It has a .description and .g
10+
- That each test:
11+
- Has a test function (or is marked unimplemented)
12+
- Has no duplicate cases
13+
- Configures batching correctly, if used
14+
15+
Example:
16+
tools/validate src/unittests/ src/webgpu/
17+
18+
Options:
19+
--help Print this message and exit.
20+
`);
21+
process.exit(rc);
22+
}
23+
24+
const args = process.argv.slice(2);
25+
if (args.indexOf('--help') !== -1) {
26+
usage(0);
27+
}
28+
29+
if (args.length < 1) {
30+
usage(0);
31+
}
32+
33+
for (const suiteDir of args) {
34+
void crawl(suiteDir, true);
35+
}

Diff for: tools/gen_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (!fs.existsSync(myself)) {
1616

1717
const { version } = require('../src/common/tools/version.ts');
1818

19-
fs.mkdirSync('./out/common/framework', { recursive: true });
19+
fs.mkdirSync('./out/common/internal', { recursive: true });
2020
// Overwrite the version.js generated by TypeScript compilation.
2121
fs.writeFileSync(
2222
'./out/common/internal/version.js',

Diff for: tools/validate

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
3+
// Validate several properties of test files and the tests in them.
4+
5+
require('../src/common/tools/setup-ts-in-node.js');
6+
require('../src/common/tools/validate.ts');

0 commit comments

Comments
 (0)