|
| 1 | +import fs from 'node:fs'; |
| 2 | +import util from 'node:util'; |
| 3 | + |
| 4 | +import {execute} from './execute.js'; |
| 5 | +import { |
| 6 | + prependPathIfItExists, |
| 7 | +} from './utils.js'; |
| 8 | +import { |
| 9 | + kDepotToolsPath, |
| 10 | + kDawnPath, |
| 11 | + kOutDir, |
| 12 | + kBuildPath, |
| 13 | +} from './constants.js'; |
| 14 | + |
| 15 | +prependPathIfItExists(kDepotToolsPath); |
| 16 | + |
| 17 | +function showHelp(options) { |
| 18 | + const longest = Object.entries(options).reduce((max, [k]) => Math.max(max, k.length), 0); |
| 19 | + const help = ` |
| 20 | +Usage: node run cts [options] [query] |
| 21 | +
|
| 22 | +Options: |
| 23 | +${Object.entries(options).map(([k, v]) => `${k.padEnd(longest)} : ${v.description ?? ''}`).join('\n')} |
| 24 | +`; |
| 25 | + console.log(help); |
| 26 | +} |
| 27 | + |
| 28 | +function parseArgs(options) { |
| 29 | + try { |
| 30 | + const args = process.argv.slice(2); |
| 31 | + const { values, positionals } = util.parseArgs({ args, options }); |
| 32 | + if (values.help) { |
| 33 | + showHelp(options); |
| 34 | + process.exit(0); |
| 35 | + } |
| 36 | + return { values, positionals }; |
| 37 | + } catch (e) { |
| 38 | + console.error(e.message); |
| 39 | + showHelp(options); |
| 40 | + process.exit(1); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +async function main() { |
| 45 | + const kDefaultCTSPath = `${kDawnPath}/third_party/webgpu-cts`; |
| 46 | + const options = { |
| 47 | + help: { type: 'boolean', short: 'h', description: 'show this help' }, |
| 48 | + cts: { type: 'string', description: 'path to CTS', default: kDefaultCTSPath}, |
| 49 | + } |
| 50 | + const { values, positionals } = parseArgs(options); |
| 51 | + const ctsPath = values.cts; |
| 52 | + const ctsQuery = positionals[0] ?? 'webgpu:*'; |
| 53 | + |
| 54 | + // hack around the fact that run-cts modifies the listing file (T_T) |
| 55 | + // This isn't perfect because Ctrl-C fails to stop run-cts (-_-;) |
| 56 | + const listingFilename = `${ctsPath}/src/webgpu/listing_meta.json`; |
| 57 | + const listing = fs.readFileSync(listingFilename, {encoding: 'utf-8'}); |
| 58 | + |
| 59 | + try { |
| 60 | + process.chdir(`${kDawnPath}/third_party/webgpu-cts`); |
| 61 | + await execute('npm', ['ci']); |
| 62 | + fs.writeFileSync(`${kOutDir}/package.json`, JSON.stringify({ |
| 63 | + name: "placeholder", |
| 64 | + version: "1.0.0", |
| 65 | + })); |
| 66 | + process.chdir(kDawnPath); |
| 67 | + await execute('vpython3', ['tools/run.py', 'run-cts', `--cts=${ctsPath}`,`--bin=${kBuildPath}`, ctsQuery]); |
| 68 | + } finally { |
| 69 | + fs.writeFileSync(listingFilename, listing); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +main(); |
0 commit comments