diff --git a/build/commands/scripts/bootstrap.js b/build/commands/scripts/bootstrap.js deleted file mode 100644 index 62f99d884c8..00000000000 --- a/build/commands/scripts/bootstrap.js +++ /dev/null @@ -1,86 +0,0 @@ -const dotenv = require('dotenv') -const program = require('commander'); -const path = require('path') -const spawn = require('child_process').spawn - -const scriptDir = path.basename(__dirname) -const rootDir = scriptDir.join('..') -const depotToolsDir = rootDir.join('vendor', 'depot_tools') -const srcDir = rootDir.join('src') -const muonDir = srdDir.join('electron') -const patchesDir = srdDir.join('libchromiumcontent') -const process.env.PATH = process.env.PATH.split(path.delimiter).push(depotToolsDir).join(path.delimiter) - -const defaultChromeRef = process.env.npm_package_config_chrome_ref -const defaultMuonRef = process.env.npm_package_config_muon_ref -const defaultPatchesRef = process.env.npm_package_config_patches_ref - -const default_options = { - env: process.env, - shell: true, - stdio: 'inherit', - cwd: srcDir -} - -const submoduleSync = (options = {}) => { - spawnSync('git', ['submodule', 'sync'], Object.assign(default_options, options)) - spawnSync('git', ['submodule', 'update', '--init', '--recursive'], Object.assign(default_options, options)) -} -const gclientSync = (options = {}) => { - spawnSync('gclient', ['sync', '--force', '--nohooks', '--with_branch_heads'], Object.assign(default_options, options)) -} - -const gclientRunhooks = (options = {}) => { - spawnSync('gclient', ['runnohooks'], Object.assign(default_options, options)) -} - -const fetch = (options = {}) => { - spawnSync('git', ['fetch', 'origin'], Object.assign(default_options, options)) -} - -const fetchTags = (options = {}) => { - spawnSync('git', ['fetch', 'origin', '--tags'], Object.assign(default_options, options)) -} - -const setVersion = (version, options = {}) => { - spawnSync('git', ['reset', '--hard', version], Object.assign(default_options, options)) -} - -const setChromeVersion = (version) => { - const options = { cwd: srdDir } - setVersion(options) -} - -const setMuonVersion = (version) => { - const options = { cwd: mounDir } - fetch(options) - fetchTags(options) - setVersion(version, options) -} - -const setPatchesVersion = (version) => { - const options = { cwd: patchesDir } - fetch(options) - fetchTags(options) - setVersion(version, options) -} - -program - .version(process.env.npm_package_version) - .option('--chrome', 'chrome git ref to checkout') - .option('--muon', 'muon git ref to checkout') - .option('--patches', 'patches git ref to checkout') - .action((version) => { - // sync depot tools into vendo/depot_tools - submoduleSync() - // initial gclient sync - gclientSync({cwd: rootDir}) - fetchtags() - setChromeVersion(options.chrome || defaultChromeRef) - // update DEPS - gclientSync() - setMuonVersion(options.muon || defaultMuonRef) - setPatchesVersion(options.patches || defaultMuonRef) - // run post-sync hooks - gclientRunhooks() - }) diff --git a/build/commands/scripts/sync.js b/build/commands/scripts/sync.js new file mode 100644 index 00000000000..3a1499550a4 --- /dev/null +++ b/build/commands/scripts/sync.js @@ -0,0 +1,122 @@ +const dotenv = require('dotenv') +const program = require('commander'); +const path = require('path') +const spawnSync = require('child_process').spawnSync +const fs = require('fs-extra') + +const scriptDir = path.dirname(__filename) +const rootDir = path.join(scriptDir, '..') +const depotToolsDir = path.join(rootDir, 'vendor', 'depot_tools') +const srcDir = path.join(rootDir, 'src') +const muonDir = path.join(srcDir, 'electron') +const patchesDir = path.join(srcDir, 'libchromiumcontent') +const resourcesDir = path.join(rootDir, 'resources') + +let shell_path = process.env.PATH.split(path.delimiter) +shell_path.push(depotToolsDir) +shell_path = shell_path.join(path.delimiter) +process.env.PATH = shell_path + +const defaultChromeRef = process.env.npm_package_config_chrome_ref +const defaultMuonRef = process.env.npm_package_config_muon_ref +const defaultPatchesRef = process.env.npm_package_config_patches_ref + +const default_options = { + env: process.env, + shell: true, + stdio: 'inherit', + cwd: srcDir +} + +const run = (command, arguments, options) => { + const prog = spawnSync(command, arguments, options) + if (prog.status !== 0) { + process.exit(1) + } +} +const submoduleSync = (options = {}) => { + run('git', ['submodule', 'sync'], Object.assign(default_options, options)) + run('git', ['submodule', 'update', '--init', '--recursive'], Object.assign(default_options, options)) +} +const gclientSync = (options = {}) => { + run('gclient', ['sync', '--force', '--nohooks', '--with_branch_heads'], Object.assign(default_options, options)) +} + +const gclientRunhooks = (options = {}) => { + run('gclient', ['runnohooks'], Object.assign(default_options, options)) +} + +const fetch = (options = {}) => { + run('git', ['fetch', 'origin'], Object.assign(default_options, options)) +} + +const fetchTags = (options = {}) => { + run('git', ['fetch', 'origin', '--tags'], Object.assign(default_options, options)) +} + +const setVersion = (version, options = {}) => { + run('git', ['reset', '--hard', version], Object.assign(default_options, options)) +} + +const setChromeVersion = (version) => { + const options = { cwd: srcDir } + setVersion(version, options) +} + +const setMuonVersion = (version) => { + const options = { cwd: muonDir } + fetch(options) + fetchTags(options) + setVersion(version, options) +} + +const setPatchesVersion = (version) => { + const options = { cwd: patchesDir } + fetch(options) + fetchTags(options) + setVersion(version, options) +} + +const updateBranding = () => { + const braveThemeDir = path.join(srcDir, 'chrome', 'app', 'theme', 'brave') + fs.ensureDirSync(braveThemeDir) + fs.copySync(path.join(resourcesDir, 'BRANDING'), path.join(braveThemeDir, 'BRANDING')) +} + +program + .version(process.env.npm_package_version) + .option('--chrome ', 'chrome git ref to checkout') + .option('--muon ', 'muon git ref to checkout') + .option('--patches ', 'patches git ref to checkout') + .parse(process.argv) + +// sync depot tools into vendo/depot_tools +console.log('Updating submodules...') +submoduleSync() +// initial gclient sync +console.log('gclient sync...') +gclientSync({cwd: rootDir}) + +console.log('fetching chrome tags...') +fetchTags() + +const chromeRef = program.chrome || defaultChromeRef +console.log('git checkout chrome ' + chromeRef + '...') +setChromeVersion(program.chrome || defaultChromeRef) + +const muonRef = program.muon || defaultMuonRef +console.log('git checkout muon ' + muonRef + '...') +setMuonVersion(muonRef) + +const patchesRef = program.patches || defaultPatchesRef +console.log('git checkout patches ' + patchesRef + '...') +setPatchesVersion(program.patches || patchesRef) +// update DEPS +console.log('gclient sync...') +gclientSync() + +// run post-sync hooks +console.log('gclient runhooks...') +gclientRunhooks() +console.log('update branding...') +updateBranding()