Supporting multiple boards
This commit is contained in:
@@ -6,20 +6,21 @@ setlocal enabledelayedexpansion
|
||||
:: Reads all settings from .anvil.toml. No Anvil binary required.
|
||||
::
|
||||
:: Usage:
|
||||
:: build.bat Compile (verify only)
|
||||
:: build.bat --clean Delete build cache first
|
||||
:: build.bat --verbose Show full compiler output
|
||||
:: build.bat Compile (verify only)
|
||||
:: build.bat --board mega Use a named board
|
||||
:: build.bat --clean Delete build cache first
|
||||
:: build.bat --verbose Show full compiler output
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "CONFIG=%SCRIPT_DIR%.anvil.toml"
|
||||
set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
||||
set "CONFIG=%SCRIPT_DIR%\.anvil.toml"
|
||||
|
||||
if not exist "%CONFIG%" (
|
||||
echo FAIL: No .anvil.toml found in %SCRIPT_DIR%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: -- Parse .anvil.toml ----------------------------------------------------
|
||||
:: Read file directly, skip comments and section headers
|
||||
:: -- Parse .anvil.toml (flat keys) ----------------------------------------
|
||||
for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
||||
set "_K=%%a"
|
||||
if not "!_K:~0,1!"=="#" if not "!_K:~0,1!"=="[" (
|
||||
@@ -30,7 +31,7 @@ for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
||||
set "_V=!_V:"=!"
|
||||
)
|
||||
if "!_K!"=="name" set "SKETCH_NAME=!_V!"
|
||||
if "!_K!"=="fqbn" set "FQBN=!_V!"
|
||||
if "!_K!"=="default" set "DEFAULT_BOARD=!_V!"
|
||||
if "!_K!"=="warnings" set "WARNINGS=!_V!"
|
||||
)
|
||||
)
|
||||
@@ -40,15 +41,17 @@ if "%SKETCH_NAME%"=="" (
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "SKETCH_DIR=%SCRIPT_DIR%%SKETCH_NAME%"
|
||||
set "BUILD_DIR=%SCRIPT_DIR%.build"
|
||||
set "SKETCH_DIR=%SCRIPT_DIR%\%SKETCH_NAME%"
|
||||
set "BUILD_DIR=%SCRIPT_DIR%\.build"
|
||||
|
||||
:: -- Parse arguments ------------------------------------------------------
|
||||
set "DO_CLEAN=0"
|
||||
set "VERBOSE="
|
||||
set "BOARD_NAME="
|
||||
|
||||
:parse_args
|
||||
if "%~1"=="" goto done_args
|
||||
if "%~1"=="--board" set "BOARD_NAME=%~2" & shift & shift & goto parse_args
|
||||
if "%~1"=="--clean" set "DO_CLEAN=1" & shift & goto parse_args
|
||||
if "%~1"=="--verbose" set "VERBOSE=--verbose" & shift & goto parse_args
|
||||
if "%~1"=="--help" goto show_help
|
||||
@@ -57,12 +60,51 @@ echo FAIL: Unknown option: %~1
|
||||
exit /b 1
|
||||
|
||||
:show_help
|
||||
echo Usage: build.bat [--clean] [--verbose]
|
||||
echo Usage: build.bat [--board NAME] [--clean] [--verbose]
|
||||
echo Compiles the sketch. Settings from .anvil.toml.
|
||||
echo --board NAME selects a board from [boards.NAME].
|
||||
exit /b 0
|
||||
|
||||
:done_args
|
||||
|
||||
:: -- Resolve board --------------------------------------------------------
|
||||
if "%BOARD_NAME%"=="" set "BOARD_NAME=%DEFAULT_BOARD%"
|
||||
|
||||
set "BOARD_SECTION=[boards.%BOARD_NAME%]"
|
||||
set "IN_SECTION=0"
|
||||
set "FQBN="
|
||||
for /f "usebackq tokens=*" %%L in ("%CONFIG%") do (
|
||||
set "_LINE=%%L"
|
||||
if "!_LINE!"=="!BOARD_SECTION!" (
|
||||
set "IN_SECTION=1"
|
||||
) else if "!IN_SECTION!"=="1" (
|
||||
if "!_LINE:~0,1!"=="[" (
|
||||
set "IN_SECTION=0"
|
||||
) else if not "!_LINE:~0,1!"=="#" (
|
||||
for /f "tokens=1,* delims==" %%a in ("!_LINE!") do (
|
||||
set "_BK=%%a"
|
||||
set "_BK=!_BK: =!"
|
||||
set "_BV=%%b"
|
||||
if defined _BV (
|
||||
set "_BV=!_BV: =!"
|
||||
set "_BV=!_BV:"=!"
|
||||
)
|
||||
if "!_BK!"=="fqbn" set "FQBN=!_BV!"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if "!FQBN!"=="" (
|
||||
echo FAIL: No board '%BOARD_NAME%' in .anvil.toml.
|
||||
echo Add it: anvil board --add %BOARD_NAME%
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
if not "%BOARD_NAME%"=="%DEFAULT_BOARD%" (
|
||||
echo ok Using board: %BOARD_NAME% -- %FQBN%
|
||||
)
|
||||
|
||||
:: -- Preflight ------------------------------------------------------------
|
||||
where arduino-cli >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
@@ -86,8 +128,8 @@ if "%DO_CLEAN%"=="1" (
|
||||
:: -- Build include flags --------------------------------------------------
|
||||
set "BUILD_FLAGS="
|
||||
for %%d in (lib\hal lib\app) do (
|
||||
if exist "%SCRIPT_DIR%%%d" (
|
||||
set "BUILD_FLAGS=!BUILD_FLAGS! -I%SCRIPT_DIR%%%d"
|
||||
if exist "%SCRIPT_DIR%\%%d" (
|
||||
set "BUILD_FLAGS=!BUILD_FLAGS! -I%SCRIPT_DIR%\%%d"
|
||||
)
|
||||
)
|
||||
set "BUILD_FLAGS=!BUILD_FLAGS! -Werror"
|
||||
@@ -100,7 +142,7 @@ echo.
|
||||
|
||||
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
|
||||
|
||||
arduino-cli compile --fqbn %FQBN% --build-path "%BUILD_DIR%" --warnings %WARNINGS% --build-property "build.extra_flags=%BUILD_FLAGS%" %VERBOSE% "%SKETCH_DIR%"
|
||||
arduino-cli compile --fqbn %FQBN% --build-path "%BUILD_DIR%" --warnings %WARNINGS% --build-property "compiler.cpp.extra_flags=%BUILD_FLAGS%" --build-property "compiler.c.extra_flags=%BUILD_FLAGS%" %VERBOSE% "%SKETCH_DIR%"
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo FAIL: Compilation failed.
|
||||
|
||||
Reference in New Issue
Block a user