From dd599c9203f875cbc6b184514fa1f92fbd6e09c8 Mon Sep 17 00:00:00 2001 From: Brian Johnson <34129+bridiver@users.noreply.github.com> Date: Tue, 22 Jul 2025 12:10:13 -0600 Subject: [PATCH] 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 --- .gitignore | 3 ++ build/commands/lib/build.js | 2 +- build/commands/lib/config.js | 58 ++++++++++++++++++++++++++++-- build/commands/scripts/commands.js | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6beef156700..f4bcbc9dce6 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,6 @@ xcuserdata # buffer exclusion file generated locally during sync build/config/unsafe_buffers_paths.txt + +# Claude LLM settings +.claude diff --git a/build/commands/lib/build.js b/build/commands/lib/build.js index e56a28af336..9b6107d1159 100644 --- a/build/commands/lib/build.js +++ b/build/commands/lib/build.js @@ -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() diff --git a/build/commands/lib/config.js b/build/commands/lib/config.js index 5c92adb9605..ec2af4ac2ef 100644 --- a/build/commands/lib/config.js +++ b/build/commands/lib/config.js @@ -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) { diff --git a/build/commands/scripts/commands.js b/build/commands/scripts/commands.js index e81a33a7178..7dbd8c87af8 100644 --- a/build/commands/scripts/commands.js +++ b/build/commands/scripts/commands.js @@ -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 ', '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. '