Add --gn and --ninja to npm run build
Use --gn to pass through ad-hoc gn args. --gn=is_component_build:true translates to is_component_build=true. Use --ninja to add command line options for Ninja. --ninja=j:48 translates to -j 48.
This commit is contained in:
parent
9880c52d97
commit
e378bfbc4b
@ -16,6 +16,19 @@ const getNPMConfig = (path) => {
|
||||
process.env[package_prefix + key]
|
||||
}
|
||||
|
||||
const parseExtraInputs = (inputs, accumulator, callback) => {
|
||||
for (let input of inputs) {
|
||||
let separatorIndex = input.indexOf(':')
|
||||
if (separatorIndex < 0) {
|
||||
separatorIndex = input.length
|
||||
}
|
||||
|
||||
const key = input.substring(0, separatorIndex);
|
||||
const value = input.substring(separatorIndex + 1);
|
||||
callback(accumulator, key, value)
|
||||
}
|
||||
}
|
||||
|
||||
const Config = function () {
|
||||
this.defaultBuildConfig = 'Debug'
|
||||
this.buildConfig = this.defaultBuildConfig
|
||||
@ -60,6 +73,8 @@ const Config = function () {
|
||||
this.sign_widevine_key = process.env.SIGN_WIDEVINE_KEY || ''
|
||||
this.sign_widevine_passwd = process.env.SIGN_WIDEVINE_PASSPHRASE || ''
|
||||
this.signature_generator = path.join(this.srcDir, 'third_party', 'widevine', 'scripts', 'signature_generator.py') || ''
|
||||
this.extraGnArgs = {}
|
||||
this.extraNinjaOpts = []
|
||||
}
|
||||
|
||||
Config.prototype.buildArgs = function () {
|
||||
@ -102,6 +117,7 @@ Config.prototype.buildArgs = function () {
|
||||
brave_referrals_api_key: this.braveReferralsApiKey,
|
||||
enable_hangout_services_extension: this.enable_hangout_services_extension,
|
||||
enable_cdm_host_verification: this.brave_enable_cdm_host_verification,
|
||||
...this.extraGnArgs,
|
||||
}
|
||||
|
||||
if (process.platform === 'darwin' && this.targetOS !== 'ios') {
|
||||
@ -402,6 +418,24 @@ Config.prototype.update = function (options) {
|
||||
}
|
||||
}
|
||||
|
||||
if (options.gn) {
|
||||
parseExtraInputs(options.gn, this.extraGnArgs, (args, key, value) => {
|
||||
try {
|
||||
value = JSON.parse(value)
|
||||
} catch (e) {
|
||||
// On parse error, leave value as string.
|
||||
}
|
||||
args[key] = value
|
||||
})
|
||||
}
|
||||
|
||||
if (options.ninja) {
|
||||
parseExtraInputs(options.ninja, this.extraNinjaOpts, (opts, key, value) => {
|
||||
opts.push(`-${key}`)
|
||||
opts.push(value)
|
||||
})
|
||||
}
|
||||
|
||||
this.projectNames.forEach((projectName) => {
|
||||
// don't update refs for projects that have them
|
||||
let project = this.projects[projectName]
|
||||
|
@ -362,7 +362,13 @@ const util = {
|
||||
|
||||
const args = util.buildArgsToString(config.buildArgs())
|
||||
util.run('gn', ['gen', config.outputDir, '--args="' + args + '"'], options)
|
||||
util.run('ninja', ['-C', config.outputDir, config.buildTarget, '-k', num_compile_failure], options)
|
||||
|
||||
let ninjaOpts = [
|
||||
'-C', config.outputDir, config.buildTarget,
|
||||
'-k', num_compile_failure,
|
||||
...config.extraNinjaOpts
|
||||
]
|
||||
util.run('ninja', ninjaOpts, options)
|
||||
},
|
||||
|
||||
generateXcodeWorkspace: (options = config.defaultOptions) => {
|
||||
|
@ -18,6 +18,11 @@ const createDist = require('../lib/createDist')
|
||||
const upload = require('../lib/upload')
|
||||
const test = require('../lib/test')
|
||||
|
||||
const collect = (value, accumulator) => {
|
||||
accumulator.push(value)
|
||||
return accumulator
|
||||
}
|
||||
|
||||
const parsedArgs = program.parseOptions(process.argv)
|
||||
|
||||
program
|
||||
@ -43,6 +48,8 @@ program
|
||||
.option('--ignore_compile_failure', 'Keep compiling regardless of error')
|
||||
.option('--skip_signing', 'skip signing binaries')
|
||||
.option('--xcode_gen <target>', 'Generate an Xcode workspace ("ios" or a list of semi-colon separated label patterns, run `gn help label_pattern` for more info.')
|
||||
.option('--gn <arg>', 'Additional gn args, in the form <key>:<value>', collect, [])
|
||||
.option('--ninja <opt>', 'Additional Ninja command-line options, in the form <key>:<value>', collect, [])
|
||||
.arguments('[build_config]')
|
||||
.action(build)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user