Fix macOS locale env for adafruit-nrfutil invocations

Arduino IDE v2 invokes tools in an environment where `LANG=""` and `LC_ALL=`
are not set to a specific encoding, as described in:

https://github.com/arduino/arduino-ide/issues/1513#issuecomment-1293383639

The bundled adafruit-nrfutil binary is a PyInstaller-frozen app using Click,
which expects the encoding to be set to UTF-8, and throws the following error
on macOS:

    Traceback (most recent call last):
      File "__main__.py", line 317, in <module>
      File "click/core.py", line 1134, in __call__
      File "click/core.py", line 1040, in main
      File "click/_unicodefun.py", line 100, in _verify_python_env

    RuntimeError: Click will abort further execution because Python was
    configured to use ASCII as encoding for the environment.
    Consult https://click.palletsprojects.com/unicode-support/ for
    mitigation steps.

    This system supports the C.UTF-8 locale which is recommended.
    You might be able to resolve your issue by exporting the following
    environment variables:

        export LC_ALL=C.UTF-8
        export LANG=C.UTF-8

So, prepends `env LANG=C.UTF-8 LC_ALL=C.UTF-8` to each invokation in macOS,
via a `.macosx` override, to force a valid locale.
To avoid duplication, the tool arguments have been moved into a `.args`
variable that is included in the normal call and the `.macosx` override.
This commit is contained in:
Carlos Pereira Atencio committed 2026-03-17 23:55:44 +01:00
1 parent 4a2d8dd5be
commit 7ce71f4c8d
2 files changed
+9 -3

No files matched your search

+3 -1
View File
@@ -31,7 +31,9 @@ nrfutil_boot.program.cmd.windows={runtime.platform.path}/tools/adafruit-nrfutil/
nrfutil_boot.program.cmd.macosx={runtime.platform.path}/tools/adafruit-nrfutil/macos/adafruit-nrfutil
# Burn bootloader pattern
nrfutil_boot.program.burn_pattern="{program.cmd}" --verbose dfu serial -pkg "{bootloader.file}.zip" -p {serial.port} -b 115200 --touch 1200
nrfutil_boot.program.burn_pattern.args=--verbose dfu serial -pkg "{bootloader.file}.zip" -p {serial.port} -b 115200 --touch 1200
nrfutil_boot.program.burn_pattern="{program.cmd}" {nrfutil_boot.program.burn_pattern.args}
nrfutil_boot.program.burn_pattern.macosx=env LANG=C.UTF-8 LC_ALL=C.UTF-8 "{program.cmd}" {nrfutil_boot.program.burn_pattern.args}
# Remind user to select Jlink when used to upload sketch
nrfutil_boot.program.params.quiet=