Load previously generated args for config with --no_gn_gen and apply args that match command line params (#29993)

When using `--no_gn_gen`, your existing args.gn/generated_args.gni will be read and any properties that match command line options (like target_cpu, target_os, etc...) will be applied to Config.js
This commit is contained in:
Brian Johnson
2025-07-22 11:10:13 -07:00
committed by GitHub
parent 6ed3822029
commit dd599c9203
4 changed files with 61 additions and 3 deletions
+3
View File
@@ -84,3 +84,6 @@ xcuserdata
# buffer exclusion file generated locally during sync
build/config/unsafe_buffers_paths.txt
# Claude LLM settings
.claude
+1 -1
View File
@@ -48,7 +48,7 @@ const build = async (buildConfig = config.defaultBuildConfig, options = {}) => {
if (config.xcode_gen_target) {
util.generateXcodeWorkspace()
} else {
if (options.no_gn_gen === undefined) {
if (options.no_gn_gen == null) {
await util.generateNinjaFiles()
}
await util.buildTargets()
+56 -2
View File
@@ -44,6 +44,29 @@ const packageConfig = function (key, sourceDir = braveCoreDir) {
return obj
}
const readArgsGn = (srcDir, outputDir) => {
const util = require('./util')
const gnHelpersPath = path.join(srcDir, 'build', 'gn_helpers.py')
const script = `
import sys
import os
sys.path.insert(0, '${path.dirname(gnHelpersPath)}')
import gn_helpers
result = gn_helpers.ReadArgsGN('${outputDir}')
import json
print(json.dumps(result))
`
const result = util.run('python3', ['-'], {
skipLogging: true,
input: script,
encoding: 'utf8',
})
return JSON.parse(result.stdout.toString().trim())
}
const getEnvConfig = (key, defaultValue = undefined) => {
if (!envConfig) {
envConfig = {}
@@ -947,7 +970,7 @@ Config.prototype.getProjectRef = function (
return defaultValue
}
Config.prototype.update = function (options) {
Config.prototype.updateInternal = function (options) {
if (options.sardine_client_secret) {
this.sardineClientSecret = options.sardine_client_secret
}
@@ -961,6 +984,10 @@ Config.prototype.update = function (options) {
this.isUniversalBinary = true
}
if (options.target_cpu) {
options.target_arch = options.target_cpu
}
if (options.target_arch === 'x86') {
this.targetArch = options.target_arch
this.gypTargetArch = 'ia32'
@@ -1147,6 +1174,29 @@ Config.prototype.update = function (options) {
}
}
Config.prototype.fromGnArgs = function (options) {
if (options.C === undefined) {
Log.error(`You must specify output directory with -C to use --no_gn_gen`)
process.exit(1)
}
const gnArgs = readArgsGn(this.srcDir, options.C)
Object.assign({}, gnArgs, { 'C': options.C })
Log.warn(
'--no-gn-gen is experimental and only gn args that match command '
+ 'line options will be processed',
)
this.updateInternal(gnArgs)
assert(!this.isCI)
}
Config.prototype.update = function (options) {
if (options.no_gn_gen == null) {
this.updateInternal(options)
} else {
this.fromGnArgs(options)
}
}
Object.defineProperty(Config.prototype, 'targetOS', {
get: function () {
if (this._targetOS) {
@@ -1348,7 +1398,11 @@ Object.defineProperty(Config.prototype, 'outputDir', {
if (this.targetOS && this.targetOS !== this.hostOS) {
buildConfigDir = this.targetOS + '_' + buildConfigDir
}
if (this.targetEnvironment && this.targetEnvironment !== 'device') {
if (
this.targetOS === 'ios'
&& this.targetEnvironment
&& this.targetEnvironment !== 'device'
) {
buildConfigDir = buildConfigDir + '_' + this.targetEnvironment
}
if (this.isChromium) {
+1
View File
@@ -357,6 +357,7 @@ program
.option('--v [log_level]', 'set log level to [log_level]', parseInteger, '0')
.option('--vmodule [modules]', 'verbose log from specific modules')
.option('--filter <filter>', 'set test filter')
.option('--no_gn_gen', 'Use args.gn as default values')
.option(
'--output_xml',
'indicates if test results xml output file(s) should be generated. '