From 992f9eb44ac9086e950e11a2e6dc2a7dfa54dd3c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 12 Sep 2023 22:31:36 +0200 Subject: [PATCH] fix(v8): fix spawning of subprocesses (#726) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaƫl Zasso --- components/git/v8.js | 10 +++++++--- lib/update-v8/majorUpdate.js | 6 +++--- lib/update-v8/minorUpdate.js | 15 +++++++++++---- lib/update-v8/updateV8Clone.js | 8 ++++++-- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/components/git/v8.js b/components/git/v8.js index 202fd9fb..53996229 100644 --- a/components/git/v8.js +++ b/components/git/v8.js @@ -1,11 +1,12 @@ import path from 'node:path'; +import { Readable } from 'node:stream'; import logSymbols from 'log-symbols'; import { minor, major, backport } from '../../lib/update-v8/index.js'; import { defaultBaseDir } from '../../lib/update-v8/constants.js'; import { checkCwd } from '../../lib/update-v8/common.js'; -import { runAsync } from '../../lib/run.js'; +import { forceRunAsync, runAsync } from '../../lib/run.js'; export const command = 'v8 [major|minor|backport]'; export const describe = 'Update or patch the V8 engine'; @@ -83,13 +84,16 @@ export function handler(argv) { return runAsync('git', args, { spawnArgs: { cwd: options.nodeDir, - ...input && { input } + stdio: input ? [Readable.from(input), 'ignore', 'ignore'] : 'ignore' } }); }; options.execGitV8 = function execGitV8(...args) { - return runAsync('git', args, { captureStdout: true, spawnArgs: { cwd: options.v8Dir } }); + return forceRunAsync('git', args, { + captureStdout: true, + spawnArgs: { cwd: options.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] } + }); }; Promise.resolve() diff --git a/lib/update-v8/majorUpdate.js b/lib/update-v8/majorUpdate.js index ac8f70e2..9a6fe036 100644 --- a/lib/update-v8/majorUpdate.js +++ b/lib/update-v8/majorUpdate.js @@ -89,7 +89,7 @@ function cloneLocalV8() { title: 'Clone branch to deps/v8', task: (ctx) => runAsync('git', ['clone', '-b', ctx.branch, ctx.v8Dir, 'deps/v8'], { - spawnArgs: { cwd: ctx.nodeDir } + spawnArgs: { cwd: ctx.nodeDir, stdio: 'ignore' } }) }; } @@ -107,7 +107,7 @@ function addDepsV8() { // Add all V8 files with --force before updating DEPS. We have to do this // because some files are checked in by V8 despite .gitignore rules. task: (ctx) => runAsync('git', ['add', '--force', 'deps/v8'], { - spawnArgs: { cwd: ctx.nodeDir } + spawnArgs: { cwd: ctx.nodeDir, stdio: 'ignore' } }) }; } @@ -166,6 +166,6 @@ async function fetchFromGit(cwd, repo, commit) { await removeDirectory(path.join(cwd, '.git')); function exec(...options) { - return runAsync('git', options, { spawnArgs: { cwd } }); + return runAsync('git', options, { spawnArgs: { cwd, stdio: 'ignore' } }); } } diff --git a/lib/update-v8/minorUpdate.js b/lib/update-v8/minorUpdate.js index 6368df85..3f797784 100644 --- a/lib/update-v8/minorUpdate.js +++ b/lib/update-v8/minorUpdate.js @@ -1,3 +1,4 @@ +import { spawn } from 'node:child_process'; import path from 'node:path'; import { promises as fs } from 'node:fs'; @@ -35,7 +36,7 @@ function getLatestV8Version() { captureStdout: true, spawnArgs: { cwd: ctx.v8Dir, - encoding: 'utf8' + stdio: ['ignore', 'pipe', 'ignore'] } }); const tags = filterAndSortTags(result); @@ -66,16 +67,16 @@ function doMinorUpdate() { } async function applyPatch(ctx, latestStr) { - const diff = await runAsync( + const diff = spawn( 'git', ['format-patch', '--stdout', `${ctx.currentVersion}...${latestStr}`], - { captureStdout: true, spawnArgs: { cwd: ctx.v8Dir, encoding: 'utf8' } } + { cwd: ctx.v8Dir, stdio: ['ignore', 'pipe', 'ignore'] } ); try { await runAsync('git', ['apply', '--directory', 'deps/v8'], { spawnArgs: { cwd: ctx.nodeDir, - input: diff + stdio: [diff.stdout, 'ignore', 'ignore'] } }); } catch (e) { @@ -83,6 +84,12 @@ async function applyPatch(ctx, latestStr) { await fs.writeFile(file, diff); throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`); } + if (diff.exitCode !== 0) { + const err = new Error(`git format-patch failed: ${diff.exitCode}`); + err.code = diff.exitCode; + err.messageOnly = true; + throw err; + } } function filterAndSortTags(tags) { diff --git a/lib/update-v8/updateV8Clone.js b/lib/update-v8/updateV8Clone.js index 37384e19..640110a7 100644 --- a/lib/update-v8/updateV8Clone.js +++ b/lib/update-v8/updateV8Clone.js @@ -24,7 +24,9 @@ function fetchOrigin() { title: 'Fetch V8', task: async(ctx, task) => { try { - await runAsync('git', ['fetch', 'origin'], { spawnArgs: { cwd: ctx.v8Dir } }); + await runAsync('git', ['fetch', 'origin'], { + spawnArgs: { cwd: ctx.v8Dir, stdio: 'ignore' } + }); } catch (e) { if (e.code === 'ENOENT') { ctx.shouldClone = true; @@ -42,7 +44,9 @@ function createClone() { title: 'Clone V8', task: async(ctx) => { await fs.mkdir(ctx.baseDir, { recursive: true }); - await runAsync('git', ['clone', v8Git], { spawnArgs: { cwd: ctx.baseDir } }); + await runAsync('git', ['clone', v8Git], { + spawnArgs: { cwd: ctx.baseDir, stdio: 'ignore' } + }); }, enabled: (ctx) => ctx.shouldClone };