You definitely can't use Arduino CLI for this purpose.
It is possible to read it from a VS Code extension installed in Arduino IDE 2.x. The data is provided by this extension, which is bundled with the Arduino IDE installation:
The Arduino boards platform framework doesn't provide the capability to determine which option is selected for each custom board option menu. However, it does allow you to use the values of the properties that are set via that option.
For example, if the user has selected from the Arduino IDE menus:
Tools > Board > esp32 > ESP32 Dev Module
Tools > Partition Scheme > RainMaker 8MB
Then according to the configuration of that custom board option:
The build.partitions property will be set to the value rainmaker_8MB
The upload.maximum_size property will be set to the value 4116480
You can reference those properties in platform.txt using this syntax:
{build.partitions}
{upload.maximum_size}
You can pass those values to an arbitrary external command, application, or script. You will find the "Pre and post build hooks" feature useful for that purpose:
I think there is a good chance that this will allow you to accomplish the equivalent of your stated goal:
You are welcome to add additional arbitrary properties to the custom board options if the existing properties are insufficient. For example, if I added this line to boards.txt:
esp32.menu.PartitionScheme.rainmaker_8MB.foo=bar
Then the foo property will be set to the value bar when compiling or uploading while Tools > Partition Scheme > RainMaker 8MB is selected from the Arduino IDE menus.
If you are patching the "esp32" boards platform installation (as opposed to submitting your changes to be distributed to the users in the platform), then you will find it convenient to make your patches via the platform.local.txt and boards.local.txt files instead of modifying the platform.txt and boards.txt files:
Thank you for linking the docs to this! I tried creating my own platform.local.txt and the script is executed (for testing purposes only Windows for Partition Scheme: "Custom").
platform.local.txt
tools.cust_app_partsize.cmd.windows="{runtime.platform.path}\tools\cust_app_partsize.bat"
recipe.hooks.prebuild.8.pattern.windows=cmd /c if exist "{build.source.path}\partitions.csv" {tools.cust_app_partsize.cmd} "{build.source.path}\partitions.csv" "{build.partitions}" "{build.fqbn}"
cust_app_partsize.bat
@echo off
setlocal enabledelayedexpansion
set "parent_dir=%~dp0"
if "%~3"=="" (
echo Error: %~nx0: usage: partitions.csv {build.partitions} {build.fqbn}
goto :EOF
)
rem todo: arguments are somehow not processed correctly
set "csv_file=%~1"
set "build.partitions=%~2"
set "build.fqbn=%~3"
for /f "usebackq tokens=1-6 delims=," %%a in ("%csv_file%") do (
rem todo: for some reason regex won't work inside batch file
rem echo %%a | findstr /r /c:"\<app\>" > nul
echo %%a | findstr /c:"app" > nul
if !errorlevel! == 0 (
set hex_value=%%e
set /a upload.maximum_size=!hex_value!
goto :mod
)
)
goto :EOF
:mod
for %%i in ("%parent_dir:~0,-1%") do set "runtime.platform.path=%%~dpi"
for /f "tokens=3 delims=:" %%a in ("%build.fqbn%") do (
for /f "tokens=1 delims=:" %%b in ("%%a") do (
set "build.variant=%%b"
)
)
rem todo: update file instead of deleting boards.local.txt
if "%build.partitions%" == "custom" (
echo %~nx0: upload.maximum_size=!upload.maximum_size! %csv_file%
echo %build.variant%.upload.maximum_size=!upload.maximum_size!> "%runtime.platform.path%\boards.local.txt"
echo %build.variant%.menu.PartitionScheme.%build.partitions%=%build.partitions%>> "%runtime.platform.path%\boards.local.txt"
echo %build.variant%.menu.PartitionScheme.%build.partitions%.build.partitions=%build.partitions%>> "%runtime.platform.path%\boards.local.txt"
echo %build.variant%.menu.PartitionScheme.%build.partitions%.upload.maximum_size=!upload.maximum_size!>> "%runtime.platform.path%\boards.local.txt"
)
I can confirm the boards.local.txt is created from script.
There is a known bug in IDE 2.x; any change to platform.txt (even the normal one) is not picked up on the fly; will probably apply to the other text files as well.
Which version of Arduino IDE are you using? A feature was added in Arduino IDE 2.3.3 that should communicate to you when changes have been made to the platform configuration files, but not loaded by Arduino IDE.
I'm not aware of a specific way to do this. It is theoretically possible that you could somehow trigger an Init request from Arduino CLI via its gRPC interface. Or perhaps make a custom VS Code extension that will trigger an initialization via Arduino IDE.
However, I think a better approach would be to create a custom sketch size tool (which can be a batch file if you like):
The only changes you would make to the platform is configuring platform.txt/platform.local.txt to use the custom size tool via recipe.advanced_size.pattern. Then you would do everything else in the tool.
That is the solution I am looking for. Not what I have asked in the question but way better approach. I have successfully tested and created a batch file that outputs the JSON structure, it works as described in documents.
Now all that's left is, find a platform developer who will add this to the platform.txt soon.
I will prepare the windows batch file and some linux shell script as proof of concept and open new issue on the espressif arduino-esp32 core.