Features and fixes for create_dist

* Add mac signing id and keychain parameters
* Add gclient_verbose option to sync
* Allow util.js func options to be set with out explicit cwd
* Use git -C option to specify repos

  Switching directories on windows can cause strange issues in
  the case of depot_tools assumingly because the shell will see
  the git in the current directory and run that instead of what is
  run elsewhere.

* Fix setting references on the command line with yarn sync.

  Commander camelcases options with dashs which breaks when used with
  '--brave-core_ref'. This also renames the option to --brave_core_ref
This commit is contained in:
Ryan Gerstenkorn 2018-05-26 19:59:44 -05:00
parent aa02380fde
commit c261a1cb84
8 changed files with 53 additions and 25 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ src
npm-debug.log npm-debug.log
.gclient .gclient
.sccache .sccache
**.sw[po]

View File

@ -9,7 +9,7 @@ const build = (buildConfig = config.defaultBuildConfig, options) => {
util.updateBranding() util.updateBranding()
} }
util.buildMuon() util.buildMuon('brave')
} }
module.exports = build module.exports = build

View File

@ -25,6 +25,7 @@ const Config = function () {
this.resourcesDir = path.join(this.rootDir, 'resources') this.resourcesDir = path.join(this.rootDir, 'resources')
this.defaultGClientFile = path.join(this.rootDir, '.gclient') this.defaultGClientFile = path.join(this.rootDir, '.gclient')
this.gClientFile = process.env.BRAVE_GCLIENT_FILE || this.defaultGClientFile this.gClientFile = process.env.BRAVE_GCLIENT_FILE || this.defaultGClientFile
this.gClientVerbose = getNPMConfig(['gclient_verbose']) || false
this.targetArch = 'x64' this.targetArch = 'x64'
this.gypTargetArch = 'x64' this.gypTargetArch = 'x64'
this.officialBuild = true this.officialBuild = true
@ -35,6 +36,8 @@ const Config = function () {
const braveCoreDirPackage = path.join(this.projects['brave-core'].dir, 'package') const braveCoreDirPackage = path.join(this.projects['brave-core'].dir, 'package')
this.braveCoreVersion = getNPMConfig(['brave_version']) || (fs.existsSync(braveCoreDirPackage + '.json') && require(braveCoreDirPackage)['version']) || '' this.braveCoreVersion = getNPMConfig(['brave_version']) || (fs.existsSync(braveCoreDirPackage + '.json') && require(braveCoreDirPackage)['version']) || ''
this.releaseTag = this.braveCoreVersion.split('+')[0] this.releaseTag = this.braveCoreVersion.split('+')[0]
this.mac_signing_identifier = getNPMConfig(['mac_signing_identifier']) || ''
this.mac_signing_keychain = getNPMConfig(['mac_signing_keychain']) || 'login'
this.channel = '' this.channel = ''
} }
@ -66,7 +69,8 @@ Config.prototype.buildArgs = function () {
} }
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
args.mac_signing_identifier = getNPMConfig(['mac_signing_identifier']) || '' args.mac_signing_identifier = this.mac_signing_identifier
args.mac_signing_keychain = this.mac_signing_keychain
} }
if (this.debugBuild) { if (this.debugBuild) {
@ -223,6 +227,15 @@ Config.prototype.update = function (options) {
if (options.channel !== 'release') if (options.channel !== 'release')
this.channel = options.channel this.channel = options.channel
if (options.mac_signing_identifier)
this.mac_signing_identifier = options.mac_signing_identifier
if (options.mac_signing_keychain)
this.mac_signing_keychain = options.mac_signing_keychain
if (options.gclient_verbose)
this.gClientVerbose = options.gclient_verbose
this.projectNames.forEach((projectName) => { this.projectNames.forEach((projectName) => {
// don't update refs for projects that have them // don't update refs for projects that have them
if (!this.projects[projectName].ref) if (!this.projects[projectName].ref)
@ -262,6 +275,7 @@ Object.defineProperty(Config.prototype, 'defaultOptions', {
stdio: 'inherit', stdio: 'inherit',
cwd: this.srcDir, cwd: this.srcDir,
shell: true, shell: true,
git_cwd: '.',
} }
}, },
}) })

View File

@ -3,19 +3,16 @@ const util = require('../lib/util')
const path = require('path') const path = require('path')
const fs = require('fs-extra') const fs = require('fs-extra')
const createDist = (options) => { const createDist = (buildConfig = config.defaultBuildConfig, options) => {
config.buildConfig = buildConfig
config.update(options) config.update(options)
let cmdOptions = config.defaultOptions
const args = util.buildArgsToString(config.buildArgs())
if (!options.no_branding_update) { if (!options.no_branding_update) {
util.updateBranding() util.updateBranding()
} }
fs.removeSync(path.join(config.outputDir, 'dist')) fs.removeSync(path.join(config.outputDir, 'dist'))
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], cmdOptions) util.buildMuon('create_dist')
util.run('ninja', ['-C', config.outputDir, 'create_dist'], cmdOptions)
renameLinuxDistr(options) renameLinuxDistr(options)
} }

View File

@ -4,6 +4,7 @@ const config = require('./config')
const fs = require('fs-extra') const fs = require('fs-extra')
const runGClient = (args, options = {}) => { const runGClient = (args, options = {}) => {
if (options.verbose) args.push('--verbose')
options.cwd = options.cwd || config.rootDir options.cwd = options.cwd || config.rootDir
options = mergeWithDefault(options) options = mergeWithDefault(options)
options.env.GCLIENT_FILE = config.gClientFile options.env.GCLIENT_FILE = config.gClientFile
@ -16,10 +17,12 @@ const mergeWithDefault = (options) => {
const util = { const util = {
run: (cmd, args = [], options = {}) => { run: (cmd, args = [], options = {}) => {
if (!options.env) options.env = {}
console.log(cmd, args.join(' ')) console.log(cmd, args.join(' '))
const continueOnFail = options.continueOnFail const continueOnFail = options.continueOnFail
delete options.continueOnFail delete options.continueOnFail
const prog = spawnSync(cmd, args, options) const prog = spawnSync(cmd, args, options)
if (prog.status !== 0) { if (prog.status !== 0) {
if (!continueOnFail) { if (!continueOnFail) {
@ -70,20 +73,21 @@ const util = {
fs.copySync(path.join(braveAppDir, 'strings'), path.join(chromeComponentsDir, 'strings')) fs.copySync(path.join(braveAppDir, 'strings'), path.join(chromeComponentsDir, 'strings'))
}, },
buildMuon: (options = config.defaultOptions) => { buildMuon: (target = 'brave', options = config.defaultOptions) => {
console.log('building brave...') console.log('building ' + target + '...')
const args = util.buildArgsToString(config.buildArgs()) const args = util.buildArgsToString(config.buildArgs())
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options) util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options)
util.run('ninja', ['-C', config.outputDir, 'brave'], options) util.run('ninja', ['-C', config.outputDir, target], options)
}, },
submoduleSync: (options = { cwd: config.rootDir }) => { submoduleSync: (options = {}) => {
if (!options.cwd) options.cwd = config.rootDir // default cwd `./src` may not exist yet
options = mergeWithDefault(options) options = mergeWithDefault(options)
util.run('git', ['submodule', 'sync'], options) util.run('git', ['submodule', 'sync'], options)
util.run('git', ['submodule', 'update', '--init', '--recursive'], options) util.run('git', ['submodule', 'update', '--init', '--recursive'], options)
util.run('git', ['clean', '-fxd'], Object.assign(options, {cwd: config.depotToolsDir})) util.run('git', ['-C', config.depotToolsDir, 'clean', '-fxd'], options)
util.run('git', ['reset', '--hard', 'HEAD'], Object.assign(options, {cwd: config.depotToolsDir})) util.run('git', ['-C', config.depotToolsDir, 'reset', '--hard', 'HEAD'], options)
}, },
gclientSync: (options = {}) => { gclientSync: (options = {}) => {
@ -95,17 +99,19 @@ const util = {
}, },
fetch: (options = {}) => { fetch: (options = {}) => {
if (!options.cwd) options.cwd = config.rootDir
options = mergeWithDefault(options) options = mergeWithDefault(options)
util.run('git', ['fetch', '--all', '--tags'], options) util.run('git', ['-C', options.git_cwd, 'fetch', '--all', '--tags'], options)
}, },
setVersion: (version, options = {}) => { setVersion: (version, options = {}) => {
util.run('git', ['clean', '-f'], options) if (!options.cwd) options.cwd = config.rootDir
util.run('git', ['reset', '--hard', version], options) util.run('git', ['-C', options.git_cwd, 'clean', '-f'], options)
util.run('git', ['-C', options.git_cwd, 'reset', '--hard', version], options)
}, },
setDepVersion: (dir, version) => { setDepVersion: (dir, version) => {
const options = { cwd: dir } const options = { git_cwd: dir }
util.fetch(options) util.fetch(options)
util.setVersion(version, options) util.setVersion(version, options)
}, },

View File

@ -24,6 +24,8 @@ program
.command('build') .command('build')
.option('-C <build_dir>', 'build config (out/Debug, out/Release') .option('-C <build_dir>', 'build config (out/Debug, out/Release')
.option('--target_arch <target_arch>', 'target architecture', 'x64') .option('--target_arch <target_arch>', 'target architecture', 'x64')
.option('--mac_signing_identifier <id>', 'The identifier to use for signing')
.option('--mac_signing_keychain <keychain>', 'The identifier to use for signing', 'login')
.option('--debug_build <debug_build>', 'keep debugging symbols') .option('--debug_build <debug_build>', 'keep debugging symbols')
.option('--official_build <official_build>', 'force official build settings') .option('--official_build <official_build>', 'force official build settings')
.option('--brave_google_api_key <brave_google_api_key>') .option('--brave_google_api_key <brave_google_api_key>')
@ -35,12 +37,17 @@ program
program program
.command('create_dist') .command('create_dist')
.option('--mac_signing_identifier', 'The identifier to use for signing') .option('-C <build_dir>', 'build config (out/Debug, out/Release')
.option('--target_arch <target_arch>', 'target architecture', 'x64') .option('--target_arch <target_arch>', 'target architecture', 'x64')
.option('--mac_signing_identifier <id>', 'The identifier to use for signing')
.option('--mac_signing_keychain <keychain>', 'The identifier to use for signing', 'login')
.option('--debug_build <debug_build>', 'keep debugging symbols') .option('--debug_build <debug_build>', 'keep debugging symbols')
.option('--official_build <official_build>', 'force official build settings') .option('--official_build <official_build>', 'force official build settings')
.option('--brave_google_api_key <brave_google_api_key>')
.option('--brave_google_api_endpoint <brave_google_api_endpoint>')
.option('--no_branding_update', 'don\'t copy BRANDING to the chrome theme dir') .option('--no_branding_update', 'don\'t copy BRANDING to the chrome theme dir')
.option('--channel <target_chanel>', 'target channel to build', /^(beta|canary|dev|release)$/i, 'release') .option('--channel <target_chanel>', 'target channel to build', /^(beta|canary|dev|release)$/i, 'release')
.arguments('[build_config]')
.action(createDist) .action(createDist)
program program

View File

@ -9,12 +9,14 @@ const projectNames = config.projectNames.filter((project) => config.projects[pro
program program
.version(process.env.npm_package_version) .version(process.env.npm_package_version)
.option('--gclient_file <file>', 'gclient config file location') .option('--gclient_file <file>', 'gclient config file location')
.option('--gclient_verbose', 'verbose output for gclient')
.option('--run_hooks', 'run gclient hooks') .option('--run_hooks', 'run gclient hooks')
.option('--run_sync', 'run gclient sync') .option('--run_sync', 'run gclient sync')
.option('--submodule_sync', 'run submodule sync') .option('--submodule_sync', 'run submodule sync')
.option('--init', 'initialize all dependencies') .option('--init', 'initialize all dependencies')
.option('--all', 'update all projects') .option('--all', 'update all projects')
projectNames.forEach((project) => { projectNames.forEach((project) => {
project = project.replace('-', '_')
program.option('--' + project + '_ref <ref>', project + ' ref to checkout') program.option('--' + project + '_ref <ref>', project + ' ref to checkout')
}) })
@ -22,30 +24,30 @@ program.parse(process.argv)
config.update(program) config.update(program)
if (program.init || program.submodule_sync) { if (program.init || program.submodule_sync) {
util.submoduleSync() util.submoduleSync({verbose: config.gClientVerbose})
} }
if (program.init) { if (program.init) {
util.buildGClientConfig() util.buildGClientConfig({verbose: config.gClientVerbose})
} }
if (program.init) { if (program.init) {
util.gclientSync() util.gclientSync({verbose: config.gClientVerbose})
} }
let updatedVersion = false let updatedVersion = false
projectNames.forEach((project) => { projectNames.forEach((project) => {
if (program.init || program.all || program[project + '_ref']) { if (program.init || program.all || program[project.replace('-', '_') + '_ref']) {
updatedVersion = true updatedVersion = true
util.setDepVersion(config.projects[project].dir, config.projects[project].ref) util.setDepVersion(config.projects[project].dir, config.projects[project].ref)
} }
}) })
if (updatedVersion || program.init || program.run_sync) { if (updatedVersion || program.init || program.run_sync) {
util.gclientSync() util.gclientSync({verbose: config.gClientVerbose})
} }
if (updatedVersion || program.init || program.run_hooks) { if (updatedVersion || program.init || program.run_hooks) {
util.gclientRunhooks() util.gclientRunhooks({verbose: config.gClientVerbose})
} }

1
src/.gitkeep Normal file
View File

@ -0,0 +1 @@
gitkeep