diff --git a/src/e-backport.js b/src/e-backport.js index 41a2c597..f5be5c92 100644 --- a/src/e-backport.js +++ b/src/e-backport.js @@ -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, diff --git a/src/e-init.js b/src/e-init.js index 91ea3640..9b47d1e5 100644 --- a/src/e-init.js +++ b/src/e-init.js @@ -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) { diff --git a/src/e-sync.js b/src/e-sync.js index e76ee639..a0f2ebb2 100644 --- a/src/e-sync.js +++ b/src/e-sync.js @@ -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') { diff --git a/src/utils/depot-tools.js b/src/utils/depot-tools.js index 076c3e26..aef010de 100644 --- a/src/utils/depot-tools.js +++ b/src/utils/depot-tools.js @@ -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; @@ -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`; @@ -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) { diff --git a/src/utils/setup-reclient-chromium.js b/src/utils/setup-reclient-chromium.js index a3817f21..3a5f540a 100644 --- a/src/utils/setup-reclient-chromium.js +++ b/src/utils/setup-reclient-chromium.js @@ -59,7 +59,7 @@ function configureReclient() { 'tools', 'engflow_reclient_configs.patch', ); - const { status: patchStatus } = spawnSync( + spawnSync( evmConfig.current(), 'git', ['apply', reclientConfigPatchPath], @@ -67,14 +67,11 @@ function configureReclient() { 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'], @@ -82,19 +79,16 @@ function configureReclient() { 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', [ @@ -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`); } }