2016-11-09 21:02:49 -07:00
|
|
|
const path = require('path')
|
|
|
|
const spawnSync = require('child_process').spawnSync
|
|
|
|
const config = require('./config')
|
2016-11-10 01:14:33 -07:00
|
|
|
const fs = require('fs')
|
2016-11-09 21:02:49 -07:00
|
|
|
|
|
|
|
const runGClient = (args, options = {}) => {
|
|
|
|
options.cwd = options.cwd || config.rootDir
|
|
|
|
options = mergeWithDefault(options)
|
|
|
|
options.env.GCLIENT_FILE = config.gClientFile
|
|
|
|
util.run('gclient', args, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeWithDefault = (options) => {
|
|
|
|
return Object.assign({}, config.defaultOptions, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
const util = {
|
|
|
|
run: (cmd, args = [], options = {}) => {
|
|
|
|
console.log(cmd, args.join(' '))
|
|
|
|
const prog = spawnSync(cmd, args, options)
|
|
|
|
if (prog.status !== 0) {
|
2016-11-27 19:29:59 -07:00
|
|
|
console.log(prog.stdout && prog.stdout.toString())
|
|
|
|
console.error(prog.stderr && prog.stderr.toString())
|
2016-11-09 21:02:49 -07:00
|
|
|
process.exit(1)
|
|
|
|
}
|
2016-11-16 13:01:25 -07:00
|
|
|
return prog
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
2016-11-10 01:14:33 -07:00
|
|
|
buildGClientConfig: () => {
|
|
|
|
function replacer(key, value) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-12-14 17:04:43 -07:00
|
|
|
let solutions = config.projectNames.filter((projectName) => config.projects[projectName].ref).map((projectName) => {
|
2016-11-10 01:14:33 -07:00
|
|
|
let project = config.projects[projectName]
|
|
|
|
return {
|
|
|
|
managed: "%False%",
|
|
|
|
name: project.gclientName,
|
|
|
|
url: project.url,
|
|
|
|
custom_deps: project.custom_deps
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const out = 'solutions = ' + JSON.stringify(solutions, replacer, 2)
|
|
|
|
.replace(/"%None%"/g, "None")
|
|
|
|
.replace(/"%False%"/g, "False")
|
|
|
|
fs.writeFileSync(config.defaultGClientFile, out)
|
|
|
|
},
|
|
|
|
|
2017-01-16 08:14:51 -07:00
|
|
|
updateBranding: () => {
|
|
|
|
console.log('update branding...')
|
|
|
|
const braveThemeDir = path.join(config.srcDir, 'chrome', 'app', 'theme', 'brave')
|
|
|
|
fs.ensureDirSync(braveThemeDir)
|
|
|
|
fs.copySync(path.join(config.resourcesDir, 'BRANDING'), path.join(braveThemeDir, 'BRANDING'))
|
|
|
|
},
|
|
|
|
|
|
|
|
buildNode: (options = config.defaultOptions) => {
|
|
|
|
console.log('building node...')
|
|
|
|
fs.copySync(path.join(config.resourcesDir, 'node_config.gypi'), path.join(config.projects.node.dir, 'config.gypi'))
|
|
|
|
|
|
|
|
options.env.GYP_INCLUDE_LAST = 'electron/build/node/node.gypi'
|
|
|
|
options.env.GYP_CHROMIUM_NO_ACTION = 0
|
|
|
|
options.env = config.addPathToEnv(options.env, config.buildToolsDir)
|
|
|
|
util.run('python', [path.join(config.buildToolsDir, 'gyp_chromium.py'),
|
|
|
|
'-D', 'target_arch=' + config.gypTargetArch,
|
|
|
|
'-D', 'host_arch=x64',
|
|
|
|
'-D', 'buildtype=Custom', // don't apply Dev or Official configs
|
|
|
|
'-D', 'component=' + config.component,
|
|
|
|
'-Goutput_dir=' + config.outputDir.split(path.sep).slice(0, -1).join(path.sep),
|
|
|
|
path.join(config.projects.node.dir, 'node.gyp')], options)
|
|
|
|
util.run('ninja', ['-C', config.outputDir, 'node'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
buildChromedriver: (options = config.defaultOptions) => {
|
|
|
|
console.log('building chromedriver...')
|
|
|
|
let buildArgs = config.buildArgs()
|
|
|
|
buildArgs.muon_build = false
|
|
|
|
let outputDir = path.join(config.outputDir.split(path.sep).slice(0, -1).join(path.sep), 'Chromedriver')
|
|
|
|
|
|
|
|
const args = util.buildArgsToString(buildArgs)
|
|
|
|
util.run('gn', ['gen', outputDir, '--args="' + args + '"'], options)
|
|
|
|
util.run('ninja', ['-C', outputDir, 'build_chromedriver'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
buildMuon: (options = config.defaultOptions) => {
|
|
|
|
console.log('building muon...')
|
|
|
|
|
|
|
|
const args = util.buildArgsToString(config.buildArgs())
|
|
|
|
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options)
|
|
|
|
util.run('ninja', ['-C', config.outputDir, 'electron'], options)
|
|
|
|
},
|
|
|
|
|
2016-11-09 21:02:49 -07:00
|
|
|
submoduleSync: (options = { cwd: config.rootDir }) => {
|
|
|
|
options = mergeWithDefault(options)
|
|
|
|
util.run('git', ['submodule', 'sync'], options)
|
|
|
|
util.run('git', ['submodule', 'update', '--init', '--recursive'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
gclientSync: (options = {}) => {
|
|
|
|
runGClient(['sync', '--force', '--nohooks', '--with_branch_heads'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
gclientRunhooks: (options = {}) => {
|
|
|
|
runGClient(['runhooks'], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
fetch: (options = {}) => {
|
|
|
|
options = mergeWithDefault(options)
|
2016-11-28 12:12:04 -07:00
|
|
|
util.run('git', ['fetch', '--all', '--tags'], options)
|
2016-11-09 21:02:49 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
setVersion: (version, options = {}) => {
|
|
|
|
util.run('git', ['reset', '--hard', version], options)
|
|
|
|
},
|
|
|
|
|
|
|
|
setDepVersion: (dir, version) => {
|
|
|
|
const options = { cwd: dir }
|
|
|
|
util.fetch(options)
|
|
|
|
util.setVersion(version, options)
|
|
|
|
},
|
2016-11-27 19:29:59 -07:00
|
|
|
|
|
|
|
buildArgsToString: (buildArgs) => {
|
|
|
|
let args = ''
|
|
|
|
for (let arg in buildArgs) {
|
|
|
|
let val = buildArgs[arg]
|
|
|
|
if (typeof val === 'string') {
|
|
|
|
val = '"' + val + '"'
|
|
|
|
} else {
|
|
|
|
val = JSON.stringify(val)
|
|
|
|
}
|
|
|
|
args += arg + '=' + val + ' '
|
|
|
|
}
|
|
|
|
return args.replace(/"/g,'\\"')
|
|
|
|
}
|
2016-11-09 21:02:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = util
|