Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v8): fix spawning of subprocesses #726

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions components/git/v8.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lib/update-v8/majorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
})
};
}
Expand All @@ -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' }
})
};
}
Expand Down Expand Up @@ -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' } });
}
}
15 changes: 11 additions & 4 deletions lib/update-v8/minorUpdate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawn } from 'node:child_process';
import path from 'node:path';
import { promises as fs } from 'node:fs';

Expand Down Expand Up @@ -35,7 +36,7 @@ function getLatestV8Version() {
captureStdout: true,
spawnArgs: {
cwd: ctx.v8Dir,
encoding: 'utf8'
stdio: ['ignore', 'pipe', 'ignore']
}
});
const tags = filterAndSortTags(result);
Expand Down Expand Up @@ -66,23 +67,29 @@ 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) {
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
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) {
Expand Down
8 changes: 6 additions & 2 deletions lib/update-v8/updateV8Clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
};
Expand Down
Loading