Skip to content

Commit 2cdc482

Browse files
authored
refactor: add optional fatal message to depot-tools spawnSync (#699)
1 parent b97e8ec commit 2cdc482

File tree

5 files changed

+35
-55
lines changed

5 files changed

+35
-55
lines changed

src/e-backport.js

+18-27
Original file line numberDiff line numberDiff line change
@@ -65,42 +65,33 @@ program
6565
return;
6666
}
6767

68-
const checkoutResult = spawnSync(config, 'git', ['checkout', targetBranch], gitOpts);
69-
if (checkoutResult.status !== 0) {
70-
fatal('Failed to checkout base branch');
71-
return;
72-
}
73-
74-
const ensureLatestResult = spawnSync(config, 'git', ['pull', 'origin', targetBranch], gitOpts);
75-
if (ensureLatestResult.status !== 0) {
76-
fatal('Failed to update base branch');
77-
return;
78-
}
79-
80-
const ensureMergeRefLocal = spawnSync(config, 'git', ['fetch', 'origin', pr.base.ref], gitOpts);
81-
if (ensureMergeRefLocal.status !== 0) {
82-
fatal('Failed to fetch latest upstream');
83-
return;
84-
}
68+
spawnSync(config, 'git', ['checkout', targetBranch], gitOpts, 'Failed to checkout base branch');
69+
spawnSync(
70+
config,
71+
'git',
72+
['pull', 'origin', targetBranch],
73+
gitOpts,
74+
'Failed to update base branch',
75+
);
76+
spawnSync(
77+
config,
78+
'git',
79+
['fetch', 'origin', pr.base.ref],
80+
gitOpts,
81+
'Failed to fetch latest upstream',
82+
);
8583

8684
const manualBpBranch = `manual-bp/${user.login}/pr/${prNumber}/branch/${targetBranch}`;
8785
spawnSync(config, 'git', ['branch', '-D', manualBpBranch], gitOpts);
88-
const backportBranchResult = spawnSync(
86+
spawnSync(
8987
config,
9088
'git',
9189
['checkout', '-b', manualBpBranch],
9290
gitOpts,
91+
`Failed to checkout new branch "${manualBpBranch}"`,
9392
);
94-
if (backportBranchResult.status !== 0) {
95-
fatal(`Failed to checkout new branch "${manualBpBranch}"`);
96-
return;
97-
}
9893

99-
const yarnInstallResult = spawnSync(config, 'yarn', ['install'], gitOpts);
100-
if (yarnInstallResult.status !== 0) {
101-
fatal(`Failed to do "yarn install" on new branch`);
102-
return;
103-
}
94+
spawnSync(config, 'yarn', ['install'], gitOpts, `Failed to do "yarn install" on new branch`);
10495

10596
const cherryPickResult = spawnSync(config, 'git', ['cherry-pick', pr.merge_commit_sha], {
10697
cwd: gitOpts.cwd,

src/e-init.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,7 @@ function runGClientConfig(config) {
9292
cwd: root,
9393
shell: true,
9494
};
95-
const { status } = depot.spawnSync(config, exec, args, opts);
96-
97-
if (status !== 0) {
98-
fatal('gclient config failed');
99-
}
95+
depot.spawnSync(config, exec, args, opts, 'gclient config failed');
10096
}
10197

10298
function ensureRoot(config, force) {

src/e-sync.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ function runGClientSync(syncArgs, syncOpts) {
6868
}
6969
: {},
7070
};
71-
const { status } = depot.spawnSync(config, exec, args, opts);
72-
73-
if (status !== 0) {
74-
fatal('gclient sync failed');
75-
}
71+
depot.spawnSync(config, exec, args, opts, 'gclient sync failed');
7672

7773
// Only set remotes if we're building an Electron target.
7874
if (config.defaultTarget !== 'chrome') {

src/utils/depot-tools.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const os = require('os');
44
const childProcess = require('child_process');
55
const pathKey = require('path-key');
66

7-
const { color } = require('./logging');
7+
const { color, fatal } = require('./logging');
88

99
const defaultDepotPath = path.resolve(__dirname, '..', '..', 'third_party', 'depot_tools');
1010
const DEPOT_TOOLS_DIR = process.env.DEPOT_TOOLS_DIR || defaultDepotPath;
@@ -121,7 +121,7 @@ function depotOpts(config, opts = {}) {
121121
return opts;
122122
}
123123

124-
function depotSpawnSync(config, cmd, args, opts_in) {
124+
function depotSpawnSync(config, cmd, args, opts_in, fatalMessage) {
125125
const opts = depotOpts(config, opts_in);
126126
if (os.platform() === 'win32' && ['python', 'python3'].includes(cmd)) {
127127
cmd = `${cmd}.bat`;
@@ -133,7 +133,13 @@ function depotSpawnSync(config, cmd, args, opts_in) {
133133
console.log(color.childExec(cmd, args, opts));
134134
}
135135
}
136-
return childProcess.spawnSync(cmd, args, opts);
136+
const result = childProcess.spawnSync(cmd, args, opts);
137+
if (fatalMessage !== undefined && result.status !== 0) {
138+
fatal(fatalMessage);
139+
return;
140+
}
141+
142+
return result;
137143
}
138144

139145
function depotExecFileSync(config, exec, args, opts_in) {

src/utils/setup-reclient-chromium.js

+6-15
Original file line numberDiff line numberDiff line change
@@ -59,42 +59,36 @@ function configureReclient() {
5959
'tools',
6060
'engflow_reclient_configs.patch',
6161
);
62-
const { status: patchStatus } = spawnSync(
62+
spawnSync(
6363
evmConfig.current(),
6464
'git',
6565
['apply', reclientConfigPatchPath],
6666
{
6767
cwd: engflowConfigsDir,
6868
stdio: 'inherit',
6969
},
70+
'Failed to apply EngFlow reclient configs patch',
7071
);
7172

72-
if (patchStatus !== 0) {
73-
fatal('Failed to apply EngFlow reclient configs patch');
74-
}
75-
7673
const configureReclientScript = path.join(engflowConfigsDir, 'configure_reclient.py');
77-
const { status: configureReclientStatus } = spawnSync(
74+
spawnSync(
7875
evmConfig.current(),
7976
'python3',
8077
[configureReclientScript, '--src_dir=src', '--force'],
8178
{
8279
cwd: root,
8380
stdio: 'inherit',
8481
},
82+
'Failed to configure EngFlow reclient configs',
8583
);
8684

87-
if (configureReclientStatus !== 0) {
88-
fatal('Failed to configure EngFlow reclient configs');
89-
}
90-
9185
const configureConfigScript = path.join(
9286
srcDir,
9387
'buildtools',
9488
'reclient_cfgs',
9589
'configure_reclient_cfgs.py',
9690
);
97-
const { status: configureConfigStatus } = spawnSync(
91+
spawnSync(
9892
evmConfig.current(),
9993
'python3',
10094
[
@@ -111,12 +105,9 @@ function configureReclient() {
111105
cwd: root,
112106
stdio: 'inherit',
113107
},
108+
'Failed to configure RBE config scripts for untrusted RBE',
114109
);
115110

116-
if (configureConfigStatus !== 0) {
117-
fatal('Failed to configure RBE config scripts for untrusted RBE');
118-
}
119-
120111
console.info(`${color.info} Successfully configured EngFlow reclient configs for Chromium`);
121112
}
122113
}

0 commit comments

Comments
 (0)