-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Web Worker script for every test file
This will be needed to launch Service Workers, which cannot be generated at runtime and cannot use dynamic import().
- Loading branch information
Showing
10 changed files
with
114 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as process from 'process'; | ||
|
||
import { crawl } from './crawl.js'; | ||
|
||
function usage(rc: number): void { | ||
console.error(`Usage: tools/gen_listings [options] [OUT_DIR] [SUITE_DIRS...] | ||
For each suite in SUITE_DIRS, generate listings into OUT_DIR/{suite}/listing.js, | ||
and generate Web Worker proxies in OUT_DIR/{suite}/webworker/**/*.worker.js for | ||
every .spec.js file. (Note {suite}/webworker/ is reserved for this purpose.) | ||
Example: | ||
tools/gen_listings gen/ src/unittests/ src/webgpu/ | ||
Options: | ||
--help Print this message and exit. | ||
`); | ||
process.exit(rc); | ||
} | ||
|
||
const argv = process.argv; | ||
if (argv.indexOf('--help') !== -1) { | ||
usage(0); | ||
} | ||
|
||
{ | ||
// Ignore old argument that is now the default | ||
const i = argv.indexOf('--no-validate'); | ||
if (i !== -1) { | ||
argv.splice(i, 1); | ||
} | ||
} | ||
|
||
if (argv.length < 4) { | ||
usage(0); | ||
} | ||
|
||
const myself = 'src/common/tools/gen_listings.ts'; | ||
|
||
const outDir = argv[2]; | ||
|
||
for (const suiteDir of argv.slice(3)) { | ||
// Run concurrently for each suite (might be a tiny bit more efficient) | ||
void crawl(suiteDir, false).then(listing => { | ||
const suite = path.basename(suiteDir); | ||
|
||
// Write listing.js | ||
const outFile = path.normalize(path.join(outDir, `${suite}/listing.js`)); | ||
fs.mkdirSync(path.join(outDir, suite), { recursive: true }); | ||
fs.writeFileSync( | ||
outFile, | ||
`\ | ||
// AUTO-GENERATED - DO NOT EDIT. See ${myself}. | ||
export const listing = ${JSON.stringify(listing, undefined, 2)}; | ||
` | ||
); | ||
|
||
// Write suite/webworker/**/*.worker.js | ||
for (const entry of listing) { | ||
if ('readme' in entry) continue; | ||
|
||
const outFileDir = path.join( | ||
outDir, | ||
suite, | ||
'webworker', | ||
...entry.file.slice(0, entry.file.length - 1) | ||
); | ||
const outFile = path.join(outDir, suite, 'webworker', ...entry.file) + '.worker.js'; | ||
|
||
const relPathToSuiteRoot = Array<string>(entry.file.length).fill('..').join('/'); | ||
|
||
fs.mkdirSync(outFileDir, { recursive: true }); | ||
fs.writeFileSync( | ||
outFile, | ||
`\ | ||
// AUTO-GENERATED - DO NOT EDIT. See ${myself}. | ||
// oldG is a TestGroup<Fixture> object (defined in common/internal/test_group.ts). | ||
import { g as oldG } from '${relPathToSuiteRoot}/${entry.file.join('/')}.spec.js'; | ||
// FIXME: Expose a proxied test interface. I think this can completely replace test_worker-worker.js | ||
// (using this instead of that), but if not then hopefully it can at least share code with it. | ||
console.log(oldG.iterate()); | ||
` | ||
); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers. | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers. | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers. | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers. | ||
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DIRECTORY RESERVED FOR GENERATED FILES. See gen_listings_and_webworkers. | ||
* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
// Crawl a suite directory (e.g. src/webgpu/) to generate a listing.js containing | ||
// the listing of test files in the suite, and some generated test files | ||
// (like suite/serviceworker/**/*.spec.js). | ||
|
||
require('../src/common/tools/setup-ts-in-node.js'); | ||
require('../src/common/tools/gen_listings_and_webworkers.ts'); |