From 6c86a03f925eebd4b38fc316d8f35609bcbee645 Mon Sep 17 00:00:00 2001 From: Aleksey Khoroshilov Date: Thu, 21 Dec 2023 13:55:39 +0700 Subject: [PATCH] Fix presubmit format check and always use UTF-8 in Python on Windows. --- PRESUBMIT.py | 6 ++++++ build/commands/lib/config.js | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index c78954577f3..eed7c19cc6e 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -79,6 +79,12 @@ def CheckPatchFormatted(input_api, output_api): # Run git cl format and get return code. git_cl_format_code, _ = git_cl.RunGitWithCode(git_cl_format_cmd) + if git_cl_format_code not in (0, 2): + return [ + output_api.PresubmitError( + f'Presubmit format check has failed, return code: {git_cl_format_code}' + ) + ] is_format_required = git_cl_format_code == 2 diff --git a/build/commands/lib/config.js b/build/commands/lib/config.js index f72f298bafb..fe4d2d51671 100644 --- a/build/commands/lib/config.js +++ b/build/commands/lib/config.js @@ -1196,6 +1196,13 @@ Object.defineProperty(Config.prototype, 'defaultOptions', { env = this.addPythonPathToEnv(env, path.join(this.srcDir, ...p)) }) env.PYTHONUNBUFFERED = '1' + if (process.platform === 'win32') { + // UTF-8 is default on Linux/Mac, but on Windows CP1252 is used in most + // cases. This var makes Python use UTF-8 if encoding is not set + // explicitly in calls such as `open()`. + // https://peps.python.org/pep-0540/ + env.PYTHONUTF8 = '1' + } env.TARGET_ARCH = this.gypTargetArch // for brave scripts env.RUSTUP_HOME = path.join(this.srcDir, 'third_party', 'rust-toolchain') // Fix `gclient runhooks` - broken since depot_tools a7b20b34f85432b5958963b75edcedfef9cf01fd