diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-05-18 22:00:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 22:00:11 +0200 |
commit | 4e1ca1d1787f25ab9f0a72ccf9d8028f70b3a7ed (patch) | |
tree | 2d0062ec1dd864c7ed98301119ac5f1c133f844a /tools | |
parent | 5ad8919d642b646caa3328930dd1a3f290bc587e (diff) |
refactor: use spawn API across codebase (#14414)
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/flamebench.js | 25 | ||||
-rwxr-xr-x | tools/format.js | 22 | ||||
-rwxr-xr-x | tools/lint.js | 32 | ||||
-rw-r--r-- | tools/util.js | 19 | ||||
-rwxr-xr-x | tools/wgpu_sync.js | 14 | ||||
-rwxr-xr-x | tools/wpt.ts | 7 | ||||
-rw-r--r-- | tools/wpt/runner.ts | 30 | ||||
-rw-r--r-- | tools/wpt/utils.ts | 53 |
8 files changed, 95 insertions, 107 deletions
diff --git a/tools/flamebench.js b/tools/flamebench.js index 35f739e1e..5293fa9a1 100755 --- a/tools/flamebench.js +++ b/tools/flamebench.js @@ -3,35 +3,34 @@ import { join, ROOT_PATH as ROOT } from "./util.js"; async function bashOut(subcmd) { - const p = Deno.run({ - cmd: ["bash", "-c", subcmd], + const { status, stdout } = await Deno.spawn("bash", { + args: ["-c", subcmd], stdout: "piped", stderr: "null", }); // Check for failure - const { success } = await p.status(); - if (!success) { + if (!status.success) { throw new Error("subcmd failed"); } // Gather output - const output = new TextDecoder().decode(await p.output()); - // Cleanup - p.close(); + const output = new TextDecoder().decode(stdout); return output.trim(); } async function bashThrough(subcmd, opts = {}) { - const p = Deno.run({ ...opts, cmd: ["bash", "-c", subcmd] }); + const { status } = await Deno.spawn("bash", { + ...opts, + args: ["-c", subcmd], + stdout: "inherit", + stderr: "inherit", + }); // Exit process on failure - const { success, code } = await p.status(); - if (!success) { - Deno.exit(code); + if (!status.success) { + Deno.exit(status.code); } - // Cleanup - p.close(); } async function availableBenches() { diff --git a/tools/format.js b/tools/format.js index a829c86dd..2cd90f622 100755 --- a/tools/format.js +++ b/tools/format.js @@ -5,14 +5,14 @@ import { getPrebuiltToolPath, join, ROOT_PATH } from "./util.js"; async function dprint() { const configFile = join(ROOT_PATH, ".dprint.json"); const execPath = getPrebuiltToolPath("dprint"); - const p = Deno.run({ - cmd: [execPath, "fmt", "--config=" + configFile], + const { status } = await Deno.spawn(execPath, { + args: ["fmt", "--config=" + configFile], + stdout: "inherit", + stderr: "inherit", }); - const { success } = await p.status(); - if (!success) { + if (!status.success) { throw new Error("dprint failed"); } - p.close(); } async function main() { @@ -20,17 +20,15 @@ async function main() { await dprint(); if (Deno.args.includes("--check")) { - const git = Deno.run({ - cmd: ["git", "status", "-uno", "--porcelain", "--ignore-submodules"], - stdout: "piped", + const { status, stdout } = await Deno.spawn("git", { + args: ["status", "-uno", "--porcelain", "--ignore-submodules"], + stderr: "inherit", }); - const { success } = await git.status(); - if (!success) { + if (!status.success) { throw new Error("git status failed"); } - const out = new TextDecoder().decode(await git.output()); - git.close(); + const out = new TextDecoder().decode(stdout); if (out) { console.log("run tools/format.js"); diff --git a/tools/lint.js b/tools/lint.js index a431e05c0..5ecf1c3c4 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -39,14 +39,14 @@ async function dlint() { const chunks = splitToChunks(sourceFiles, `${execPath} run`.length); for (const chunk of chunks) { - const p = Deno.run({ - cmd: [execPath, "run", "--config=" + configFile, ...chunk], + const { status } = await Deno.spawn(execPath, { + args: ["run", "--config=" + configFile, ...chunk], + stdout: "inherit", + stderr: "inherit", }); - const { success } = await p.status(); - if (!success) { + if (!status.success) { throw new Error("dlint failed"); } - p.close(); } } @@ -70,14 +70,14 @@ async function dlintPreferPrimordials() { const chunks = splitToChunks(sourceFiles, `${execPath} run`.length); for (const chunk of chunks) { - const p = Deno.run({ - cmd: [execPath, "run", "--rule", "prefer-primordials", ...chunk], + const { status } = await Deno.spawn(execPath, { + args: ["run", "--rule", "prefer-primordials", ...chunk], + stdout: "inherit", + stderr: "inherit", }); - const { success } = await p.status(); - if (!success) { + if (!status.success) { throw new Error("prefer-primordials failed"); } - p.close(); } } @@ -101,14 +101,14 @@ async function clippy() { console.log("clippy"); const currentBuildMode = buildMode(); - const cmd = ["cargo", "clippy", "--all-targets", "--locked"]; + const cmd = ["clippy", "--all-targets", "--locked"]; if (currentBuildMode != "debug") { cmd.push("--release"); } - const p = Deno.run({ - cmd: [ + const { status } = await Deno.spawn("cargo", { + args: [ ...cmd, "--", "-D", @@ -116,12 +116,12 @@ async function clippy() { "-D", "clippy::await_holding_refcell_ref", ], + stdout: "inherit", + stderr: "inherit", }); - const { success } = await p.status(); - if (!success) { + if (!status.success) { throw new Error("clippy failed"); } - p.close(); } async function main() { diff --git a/tools/util.js b/tools/util.js index fa62097d4..c76456b9a 100644 --- a/tools/util.js +++ b/tools/util.js @@ -8,24 +8,21 @@ import { } from "../test_util/std/path/mod.ts"; export { dirname, fromFileUrl, join, resolve, toFileUrl }; export { existsSync, walk } from "../test_util/std/fs/mod.ts"; -export { readLines } from "../test_util/std/io/mod.ts"; +export { TextLineStream } from "../test_util/std/streams/delimiter.ts"; export { delay } from "../test_util/std/async/delay.ts"; export const ROOT_PATH = dirname(dirname(fromFileUrl(import.meta.url))); -async function getFilesFromGit(baseDir, cmd) { - const p = Deno.run({ - cmd, - stdout: "piped", +async function getFilesFromGit(baseDir, args) { + const { status, stdout } = await Deno.spawn("git", { + stderr: "inherit", + args, }); - const output = new TextDecoder().decode(await p.output()); - const { success } = await p.status(); - if (!success) { + const output = new TextDecoder().decode(stdout); + if (!status.success) { throw new Error("gitLsFiles failed"); } - p.close(); - const files = output.split("\0").filter((line) => line.length > 0).map( (filePath) => { return Deno.realPathSync(join(baseDir, filePath)); @@ -38,7 +35,6 @@ async function getFilesFromGit(baseDir, cmd) { function gitLsFiles(baseDir, patterns) { baseDir = Deno.realPathSync(baseDir); const cmd = [ - "git", "-C", baseDir, "ls-files", @@ -57,7 +53,6 @@ function gitLsFiles(baseDir, patterns) { function gitStaged(baseDir, patterns) { baseDir = Deno.realPathSync(baseDir); const cmd = [ - "git", "-C", baseDir, "diff", diff --git a/tools/wgpu_sync.js b/tools/wgpu_sync.js index c5b6ffc45..3c6217709 100755 --- a/tools/wgpu_sync.js +++ b/tools/wgpu_sync.js @@ -10,15 +10,17 @@ const V_WGPU = "0.12"; const TARGET_DIR = join(ROOT_PATH, "ext", "webgpu"); async function bash(subcmd, opts = {}) { - const p = Deno.run({ ...opts, cmd: ["bash", "-c", subcmd] }); + const { status } = await Deno.spawn("bash", { + ...opts, + args: ["-c", subcmd], + stdout: "inherit", + sdterr: "inherit", + }); // Exit process on failure - const { success, code } = await p.status(); - if (!success) { - Deno.exit(code); + if (!status.success) { + Deno.exit(status.code); } - // Cleanup - p.close(); } async function clearTargetDir() { diff --git a/tools/wpt.ts b/tools/wpt.ts index 52d57ad28..615fbf752 100755 --- a/tools/wpt.ts +++ b/tools/wpt.ts @@ -90,10 +90,11 @@ async function setup() { `The WPT require certain entries to be present in your ${hostsPath} file. Should these be configured automatically?`, ); if (autoConfigure) { - const proc = runPy(["wpt", "make-hosts-file"], { stdout: "piped" }); - const status = await proc.status(); + const { status, stdout } = await runPy(["wpt", "make-hosts-file"], { + stdout: "piped", + }).output(); assert(status.success, "wpt make-hosts-file should not fail"); - const entries = new TextDecoder().decode(await proc.output()); + const entries = new TextDecoder().decode(stdout); const file = await Deno.open(hostsPath, { append: true }).catch((err) => { if (err instanceof Deno.errors.PermissionDenied) { throw new Error( diff --git a/tools/wpt/runner.ts b/tools/wpt/runner.ts index 5e0285e77..269e6ffd1 100644 --- a/tools/wpt/runner.ts +++ b/tools/wpt/runner.ts @@ -1,5 +1,5 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { delay, join, readLines, ROOT_PATH, toFileUrl } from "../util.js"; +import { delay, join, ROOT_PATH, TextLineStream, toFileUrl } from "../util.js"; import { assert, denoBinary, ManifestTestOptions, runPy } from "./utils.ts"; import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.3-alpha2/deno-dom-wasm.ts"; @@ -32,8 +32,7 @@ export async function runWithTestUtil<T>( const passedTime = performance.now() - start; if (passedTime > 15000) { proc.kill("SIGINT"); - await proc.status(); - proc.close(); + await proc.status; throw new Error("Timed out while trying to start wpt test util."); } } @@ -45,8 +44,7 @@ export async function runWithTestUtil<T>( } finally { if (verbose) console.log("Killing wpt test util."); proc.kill("SIGINT"); - await proc.status(); - proc.close(); + await proc.status; } } @@ -89,21 +87,17 @@ export async function runSingleTest( const startTime = new Date().getTime(); - const cmd = [ - denoBinary(), + const args = [ "run", - ]; - - cmd.push( "-A", "--unstable", - ); + ]; if (inspectBrk) { - cmd.push("--inspect-brk"); + args.push("--inspect-brk"); } - cmd.push( + args.push( "--enable-testing-features-do-not-use", "--location", url.toString(), @@ -113,8 +107,8 @@ export async function runSingleTest( "[]", ); - const proc = Deno.run({ - cmd, + const proc = Deno.spawnChild(denoBinary(), { + args, env: { NO_COLOR: "1", }, @@ -127,7 +121,9 @@ export async function runSingleTest( let harnessStatus = null; - const lines = readLines(proc.stderr); + const lines = proc.stderr.pipeThrough(new TextDecoderStream()).pipeThrough( + new TextLineStream(), + ); for await (const line of lines) { if (line.startsWith("{")) { const data = JSON.parse(line); @@ -144,7 +140,7 @@ export async function runSingleTest( const duration = new Date().getTime() - startTime; - const { code } = await proc.status(); + const { code } = await proc.status; return { status: code, harnessStatus, diff --git a/tools/wpt/utils.ts b/tools/wpt/utils.ts index f64e20f8f..80580928c 100644 --- a/tools/wpt/utils.ts +++ b/tools/wpt/utils.ts @@ -53,7 +53,7 @@ export interface ManifestTestOptions { const MANIFEST_PATH = join(ROOT_PATH, "./tools/wpt/manifest.json"); export async function updateManifest() { - const proc = runPy( + const status = await runPy( [ "wpt", "manifest", @@ -64,8 +64,7 @@ export async function updateManifest() { ...(rebuild ? ["--rebuild"] : []), ], {}, - ); - const status = await proc.status(); + ).status; assert(status.success, "updating wpt manifest should succeed"); } @@ -119,23 +118,26 @@ export function assert(condition: unknown, message: string): asserts condition { } } -export function runPy( +export function runPy<T extends Omit<Deno.SpawnOptions, "cwd">>( args: string[], - options: Omit<Omit<Deno.RunOptions, "cmd">, "cwd">, -): Deno.Process { + options: T, +): Deno.Child<T> { const cmd = Deno.build.os == "windows" ? "python.exe" : "python3"; - return Deno.run({ - cmd: [cmd, ...args], - cwd: join(ROOT_PATH, "./test_util/wpt/"), + return Deno.spawnChild(cmd, { + args, + stdout: "inherit", + stderr: "inherit", ...options, + cwd: join(ROOT_PATH, "./test_util/wpt/"), }); } export async function checkPy3Available() { - const proc = runPy(["--version"], { stdout: "piped" }); - const status = await proc.status(); + const { status, stdout } = await runPy(["--version"], { + stdout: "piped", + }).output(); assert(status.success, "failed to run python --version"); - const output = new TextDecoder().decode(await proc.output()); + const output = new TextDecoder().decode(stdout); assert( output.includes("Python 3."), `The ${ @@ -146,12 +148,12 @@ export async function checkPy3Available() { export async function cargoBuild() { if (binary) return; - const proc = Deno.run({ - cmd: ["cargo", "build", ...(release ? ["--release"] : [])], + const { status } = await Deno.spawn("cargo", { + args: ["build", ...(release ? ["--release"] : [])], cwd: ROOT_PATH, + stdout: "inherit", + stderr: "inherit", }); - const status = await proc.status(); - proc.close(); assert(status.success, "cargo build failed"); } @@ -173,22 +175,17 @@ export async function generateRunInfo(): Promise<unknown> { "darwin": "mac", "linux": "linux", }; - const proc = Deno.run({ - cmd: ["git", "rev-parse", "HEAD"], + const proc = await Deno.spawn("git", { + args: ["rev-parse", "HEAD"], cwd: join(ROOT_PATH, "test_util", "wpt"), - stdout: "piped", + stderr: "inherit", }); - await proc.status(); - const revision = (new TextDecoder().decode(await proc.output())).trim(); - proc.close(); - const proc2 = Deno.run({ - cmd: [denoBinary(), "eval", "console.log(JSON.stringify(Deno.version))"], + const revision = (new TextDecoder().decode(proc.stdout)).trim(); + const proc2 = await Deno.spawn(denoBinary(), { + args: ["eval", "console.log(JSON.stringify(Deno.version))"], cwd: join(ROOT_PATH, "test_util", "wpt"), - stdout: "piped", }); - await proc2.status(); - const version = JSON.parse(new TextDecoder().decode(await proc2.output())); - proc2.close(); + const version = JSON.parse(new TextDecoder().decode(proc2.stdout)); const runInfo = { "os": oses[Deno.build.os], "processor": Deno.build.arch, |