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

refactor: add optional fatal message to depot-tools spawnSync #699

Merged
merged 1 commit into from
Feb 19, 2025
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
45 changes: 18 additions & 27 deletions src/e-backport.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,42 +65,33 @@ program
return;
}

const checkoutResult = spawnSync(config, 'git', ['checkout', targetBranch], gitOpts);
if (checkoutResult.status !== 0) {
fatal('Failed to checkout base branch');
return;
}

const ensureLatestResult = spawnSync(config, 'git', ['pull', 'origin', targetBranch], gitOpts);
if (ensureLatestResult.status !== 0) {
fatal('Failed to update base branch');
return;
}

const ensureMergeRefLocal = spawnSync(config, 'git', ['fetch', 'origin', pr.base.ref], gitOpts);
if (ensureMergeRefLocal.status !== 0) {
fatal('Failed to fetch latest upstream');
return;
}
spawnSync(config, 'git', ['checkout', targetBranch], gitOpts, 'Failed to checkout base branch');
spawnSync(
config,
'git',
['pull', 'origin', targetBranch],
gitOpts,
'Failed to update base branch',
);
spawnSync(
config,
'git',
['fetch', 'origin', pr.base.ref],
gitOpts,
'Failed to fetch latest upstream',
);

const manualBpBranch = `manual-bp/${user.login}/pr/${prNumber}/branch/${targetBranch}`;
spawnSync(config, 'git', ['branch', '-D', manualBpBranch], gitOpts);
const backportBranchResult = spawnSync(
spawnSync(
config,
'git',
['checkout', '-b', manualBpBranch],
gitOpts,
`Failed to checkout new branch "${manualBpBranch}"`,
);
if (backportBranchResult.status !== 0) {
fatal(`Failed to checkout new branch "${manualBpBranch}"`);
return;
}

const yarnInstallResult = spawnSync(config, 'yarn', ['install'], gitOpts);
if (yarnInstallResult.status !== 0) {
fatal(`Failed to do "yarn install" on new branch`);
return;
}
spawnSync(config, 'yarn', ['install'], gitOpts, `Failed to do "yarn install" on new branch`);

const cherryPickResult = spawnSync(config, 'git', ['cherry-pick', pr.merge_commit_sha], {
cwd: gitOpts.cwd,
Expand Down
6 changes: 1 addition & 5 deletions src/e-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ function runGClientConfig(config) {
cwd: root,
shell: true,
};
const { status } = depot.spawnSync(config, exec, args, opts);

if (status !== 0) {
fatal('gclient config failed');
}
depot.spawnSync(config, exec, args, opts, 'gclient config failed');
}

function ensureRoot(config, force) {
Expand Down
6 changes: 1 addition & 5 deletions src/e-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ function runGClientSync(syncArgs, syncOpts) {
}
: {},
};
const { status } = depot.spawnSync(config, exec, args, opts);

if (status !== 0) {
fatal('gclient sync failed');
}
depot.spawnSync(config, exec, args, opts, 'gclient sync failed');

// Only set remotes if we're building an Electron target.
if (config.defaultTarget !== 'chrome') {
Expand Down
12 changes: 9 additions & 3 deletions src/utils/depot-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const os = require('os');
const childProcess = require('child_process');
const pathKey = require('path-key');

const { color } = require('./logging');
const { color, fatal } = require('./logging');

const defaultDepotPath = path.resolve(__dirname, '..', '..', 'third_party', 'depot_tools');
const DEPOT_TOOLS_DIR = process.env.DEPOT_TOOLS_DIR || defaultDepotPath;
Expand Down Expand Up @@ -121,7 +121,7 @@ function depotOpts(config, opts = {}) {
return opts;
}

function depotSpawnSync(config, cmd, args, opts_in) {
function depotSpawnSync(config, cmd, args, opts_in, fatalMessage) {
const opts = depotOpts(config, opts_in);
if (os.platform() === 'win32' && ['python', 'python3'].includes(cmd)) {
cmd = `${cmd}.bat`;
Expand All @@ -133,7 +133,13 @@ function depotSpawnSync(config, cmd, args, opts_in) {
console.log(color.childExec(cmd, args, opts));
}
}
return childProcess.spawnSync(cmd, args, opts);
const result = childProcess.spawnSync(cmd, args, opts);
if (fatalMessage !== undefined && result.status !== 0) {
fatal(fatalMessage);
return;
}

return result;
}

function depotExecFileSync(config, exec, args, opts_in) {
Expand Down
21 changes: 6 additions & 15 deletions src/utils/setup-reclient-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,42 +59,36 @@ function configureReclient() {
'tools',
'engflow_reclient_configs.patch',
);
const { status: patchStatus } = spawnSync(
spawnSync(
evmConfig.current(),
'git',
['apply', reclientConfigPatchPath],
{
cwd: engflowConfigsDir,
stdio: 'inherit',
},
'Failed to apply EngFlow reclient configs patch',
);

if (patchStatus !== 0) {
fatal('Failed to apply EngFlow reclient configs patch');
}

const configureReclientScript = path.join(engflowConfigsDir, 'configure_reclient.py');
const { status: configureReclientStatus } = spawnSync(
spawnSync(
evmConfig.current(),
'python3',
[configureReclientScript, '--src_dir=src', '--force'],
{
cwd: root,
stdio: 'inherit',
},
'Failed to configure EngFlow reclient configs',
);

if (configureReclientStatus !== 0) {
fatal('Failed to configure EngFlow reclient configs');
}

const configureConfigScript = path.join(
srcDir,
'buildtools',
'reclient_cfgs',
'configure_reclient_cfgs.py',
);
const { status: configureConfigStatus } = spawnSync(
spawnSync(
evmConfig.current(),
'python3',
[
Expand All @@ -111,12 +105,9 @@ function configureReclient() {
cwd: root,
stdio: 'inherit',
},
'Failed to configure RBE config scripts for untrusted RBE',
);

if (configureConfigStatus !== 0) {
fatal('Failed to configure RBE config scripts for untrusted RBE');
}

console.info(`${color.info} Successfully configured EngFlow reclient configs for Chromium`);
}
}
Expand Down