|
| 1 | +@echo off |
| 2 | +REM Neo build script with plugin integration v1.1.0 |
| 3 | +REM This script builds Neo.CLI and all plugins, organizing them in framework-specific directories |
| 4 | + |
| 5 | +setlocal enabledelayedexpansion |
| 6 | + |
| 7 | +REM Start time measurement |
| 8 | +for /f "tokens=1-4 delims=:.," %%a in ("%time%") do ( |
| 9 | + set /A "start=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" |
| 10 | +) |
| 11 | + |
| 12 | +echo Neo Build Script with Plugin Integration |
| 13 | +echo. |
| 14 | + |
| 15 | +REM Set the directory variables |
| 16 | +set "SCRIPT_DIR=%~dp0" |
| 17 | +set "ROOT_DIR=%SCRIPT_DIR%.." |
| 18 | +set "BUILD_CONFIG=Release" |
| 19 | +set "OUTPUT_DIR=%ROOT_DIR%\bin" |
| 20 | +set "CLI_PROJECT=%ROOT_DIR%\src\Neo.CLI\Neo.CLI.csproj" |
| 21 | +set "NEO_SOLUTION=%ROOT_DIR%\neo.sln" |
| 22 | +set "PLUGINS_FOUND=0" |
| 23 | +set "PLUGINS_PROCESSED=0" |
| 24 | + |
| 25 | +REM Log file setup |
| 26 | +set "LOG_FILE=%ROOT_DIR%\build.log" |
| 27 | +echo Build started at %date% %time% > "%LOG_FILE%" |
| 28 | + |
| 29 | +REM Extract target framework from Neo.CLI.csproj |
| 30 | +echo Detecting .NET version from Neo.CLI project... |
| 31 | +echo Detecting .NET version from Neo.CLI project... >> "%LOG_FILE%" |
| 32 | + |
| 33 | +if not exist "%CLI_PROJECT%" ( |
| 34 | + echo Error: Could not find Neo.CLI project at %CLI_PROJECT% |
| 35 | + echo Error: Could not find Neo.CLI project at %CLI_PROJECT% >> "%LOG_FILE%" |
| 36 | + exit /b 1 |
| 37 | +) |
| 38 | + |
| 39 | +REM Find the TargetFramework in the project file |
| 40 | +for /f "tokens=2 delims=<>" %%a in ('findstr /C:"<TargetFramework>" "%CLI_PROJECT%"') do ( |
| 41 | + set "TARGET_FRAMEWORK=%%a" |
| 42 | +) |
| 43 | + |
| 44 | +if not defined TARGET_FRAMEWORK ( |
| 45 | + echo Error: Could not detect target framework from Neo.CLI project |
| 46 | + echo Falling back to default: net7.0 |
| 47 | + echo Warning: Could not detect target framework, falling back to net7.0 >> "%LOG_FILE%" |
| 48 | + set "TARGET_FRAMEWORK=net7.0" |
| 49 | +) else ( |
| 50 | + echo Detected target framework: %TARGET_FRAMEWORK% |
| 51 | + echo Detected target framework: %TARGET_FRAMEWORK% >> "%LOG_FILE%" |
| 52 | +) |
| 53 | + |
| 54 | +echo Root directory: %ROOT_DIR% |
| 55 | +echo Output directory: %OUTPUT_DIR% |
| 56 | +echo Target framework: %TARGET_FRAMEWORK% |
| 57 | +echo. |
| 58 | + |
| 59 | +REM Verify .NET SDK is installed |
| 60 | +echo Verifying .NET SDK installation... |
| 61 | +echo Verifying .NET SDK installation... >> "%LOG_FILE%" |
| 62 | +where dotnet >nul 2>nul |
| 63 | +if %ERRORLEVEL% neq 0 ( |
| 64 | + echo Error: .NET SDK is not installed or not in PATH |
| 65 | + echo Error: .NET SDK is not installed or not in PATH >> "%LOG_FILE%" |
| 66 | + exit /b 1 |
| 67 | +) |
| 68 | + |
| 69 | +for /f "tokens=*" %%v in ('dotnet --version') do set "DOTNET_VERSION=%%v" |
| 70 | +echo Found .NET SDK version: %DOTNET_VERSION% |
| 71 | +echo Found .NET SDK version: %DOTNET_VERSION% >> "%LOG_FILE%" |
| 72 | +echo. |
| 73 | + |
| 74 | +REM Clean up old build artifacts |
| 75 | +echo Cleaning previous build artifacts... |
| 76 | +echo Cleaning previous build artifacts... >> "%LOG_FILE%" |
| 77 | +if exist "%OUTPUT_DIR%" rmdir /s /q "%OUTPUT_DIR%" |
| 78 | +mkdir "%OUTPUT_DIR%" 2>nul |
| 79 | +echo Clean complete |
| 80 | +echo Clean complete >> "%LOG_FILE%" |
| 81 | +echo. |
| 82 | + |
| 83 | +REM First build the entire solution to ensure dependencies are built |
| 84 | +if exist "%NEO_SOLUTION%" ( |
| 85 | + echo Building entire Neo solution first to resolve dependencies... |
| 86 | + echo Building entire Neo solution first to resolve dependencies... >> "%LOG_FILE%" |
| 87 | + dotnet build "%NEO_SOLUTION%" -c %BUILD_CONFIG% |
| 88 | + if %ERRORLEVEL% neq 0 ( |
| 89 | + echo Failed to build Neo solution |
| 90 | + echo Failed to build Neo solution >> "%LOG_FILE%" |
| 91 | + exit /b 1 |
| 92 | + ) |
| 93 | + echo Successfully built Neo solution |
| 94 | + echo Successfully built Neo solution >> "%LOG_FILE%" |
| 95 | + echo. |
| 96 | +) else ( |
| 97 | + echo Neo solution file not found. Will attempt to build Neo.CLI directly. |
| 98 | + echo Neo solution file not found. Will attempt to build Neo.CLI directly. >> "%LOG_FILE%" |
| 99 | +) |
| 100 | + |
| 101 | +REM Build Neo.CLI |
| 102 | +echo Building project: Neo.CLI |
| 103 | +echo Building project: Neo.CLI >> "%LOG_FILE%" |
| 104 | +dotnet build "%CLI_PROJECT%" -c %BUILD_CONFIG% |
| 105 | +if %ERRORLEVEL% neq 0 ( |
| 106 | + echo Failed to build Neo.CLI |
| 107 | + echo Failed to build Neo.CLI >> "%LOG_FILE%" |
| 108 | + exit /b 1 |
| 109 | +) |
| 110 | +echo Successfully built Neo.CLI |
| 111 | +echo Successfully built Neo.CLI >> "%LOG_FILE%" |
| 112 | +echo. |
| 113 | + |
| 114 | +REM Copy Neo.CLI output to bin directory |
| 115 | +echo Copying Neo.CLI output to bin directory... |
| 116 | +echo Copying Neo.CLI output to bin directory... >> "%LOG_FILE%" |
| 117 | + |
| 118 | +REM Find the Neo.CLI DLL |
| 119 | +call :FindDll "neo-cli.dll" |
| 120 | +set "CLI_DLL=%FOUND_DLL%" |
| 121 | + |
| 122 | +if defined CLI_DLL if exist "!CLI_DLL!" ( |
| 123 | + for %%F in ("!CLI_DLL!") do set "CLI_DIR=%%~dpF" |
| 124 | + echo Found neo-cli.dll at: !CLI_DIR! |
| 125 | + echo Found neo-cli.dll at: !CLI_DIR! >> "%LOG_FILE%" |
| 126 | + xcopy /E /Y "!CLI_DIR!*" "%OUTPUT_DIR%\" |
| 127 | + echo Neo.CLI copied to output directory |
| 128 | + echo Neo.CLI copied to output directory >> "%LOG_FILE%" |
| 129 | +) else ( |
| 130 | + echo Error: Could not find neo-cli.dll |
| 131 | + echo Trying to find any DLLs in the output directories... |
| 132 | + echo Warning: Could not find neo-cli.dll, searching for any DLLs >> "%LOG_FILE%" |
| 133 | + |
| 134 | + REM Try to find any DLL in the build output directories |
| 135 | + for /r "%ROOT_DIR%" %%F in (*.dll) do ( |
| 136 | + set "ANY_DLL=%%F" |
| 137 | + if "!ANY_DLL!" neq "" ( |
| 138 | + for %%G in ("!ANY_DLL!") do set "ANY_DIR=%%~dpG" |
| 139 | + echo Found DLLs at: !ANY_DIR! |
| 140 | + echo Found DLLs at: !ANY_DIR! >> "%LOG_FILE%" |
| 141 | + xcopy /E /Y "!ANY_DIR!*" "%OUTPUT_DIR%\" |
| 142 | + echo Neo.CLI copied from found directory |
| 143 | + echo Neo.CLI copied from found directory >> "%LOG_FILE%" |
| 144 | + goto :CliCopyDone |
| 145 | + ) |
| 146 | + ) |
| 147 | + |
| 148 | + echo Failed to locate any build output. Make sure the build succeeded. |
| 149 | + echo Error: Failed to locate any build output >> "%LOG_FILE%" |
| 150 | + exit /b 1 |
| 151 | +) |
| 152 | + |
| 153 | +:CliCopyDone |
| 154 | +echo. |
| 155 | + |
| 156 | +REM Create plugins directory in the Neo.CLI output directory |
| 157 | +echo Setting up plugins directory... |
| 158 | +echo Setting up plugins directory... >> "%LOG_FILE%" |
| 159 | + |
| 160 | +REM Create the specific Neo.CLI output directory structure |
| 161 | +set "CLI_PLUGINS_DIR=%OUTPUT_DIR%\Neo.CLI\%TARGET_FRAMEWORK%\Plugins" |
| 162 | +mkdir "%CLI_PLUGINS_DIR%" 2>nul |
| 163 | + |
| 164 | +echo Plugins directory created at: %CLI_PLUGINS_DIR% |
| 165 | +echo Plugins directory created at: %CLI_PLUGINS_DIR% >> "%LOG_FILE%" |
| 166 | +echo. |
| 167 | + |
| 168 | +REM Build and copy all plugins |
| 169 | +echo Building and installing plugins... |
| 170 | +echo Building and installing plugins... >> "%LOG_FILE%" |
| 171 | +echo. |
| 172 | + |
| 173 | +REM Find all plugin directories |
| 174 | +for /d %%D in ("%ROOT_DIR%\src\Plugins\*") do ( |
| 175 | + set "PLUGIN_DIR=%%D" |
| 176 | + set "PLUGIN_DIR_NAME=%%~nxD" |
| 177 | + |
| 178 | + REM Skip obj directory |
| 179 | + if "!PLUGIN_DIR_NAME!" == "obj" ( |
| 180 | + echo Skipping !PLUGIN_DIR_NAME! - not a plugin directory |
| 181 | + echo Skipping !PLUGIN_DIR_NAME! - not a plugin directory >> "%LOG_FILE%" |
| 182 | + ) else ( |
| 183 | + call :ProcessPluginDirectory "!PLUGIN_DIR!" |
| 184 | + ) |
| 185 | +) |
| 186 | + |
| 187 | +echo All plugins have been built and installed |
| 188 | +echo Found %PLUGINS_FOUND% plugin directories, processed %PLUGINS_PROCESSED% plugin projects |
| 189 | +echo All plugins have been built and installed >> "%LOG_FILE%" |
| 190 | +echo Found %PLUGINS_FOUND% plugin directories, processed %PLUGINS_PROCESSED% plugin projects >> "%LOG_FILE%" |
| 191 | +echo. |
| 192 | + |
| 193 | +REM Calculate build time |
| 194 | +for /f "tokens=1-4 delims=:.," %%a in ("%time%") do ( |
| 195 | + set /A "end=(((%%a*60)+1%%b %% 100)*60+1%%c %% 100)*100+1%%d %% 100" |
| 196 | +) |
| 197 | +set /A elapsed=end-start |
| 198 | +set /A hh=elapsed/(60*60*100), rest=elapsed%%(60*60*100), mm=rest/(60*100), rest%%=60*100, ss=rest/100, cc=rest%%100 |
| 199 | +if %hh% lss 10 set hh=0%hh% |
| 200 | +if %mm% lss 10 set mm=0%mm% |
| 201 | +if %ss% lss 10 set ss=0%ss% |
| 202 | +if %cc% lss 10 set cc=0%cc% |
| 203 | +set DURATION=%hh%:%mm%:%ss%.%cc% |
| 204 | + |
| 205 | +echo Build completed successfully in %DURATION%! |
| 206 | +echo Build completed successfully in %DURATION%! >> "%LOG_FILE%" |
| 207 | +echo. |
| 208 | + |
| 209 | +echo Build completed successfully! |
| 210 | +echo The Neo node with plugins is available at: %OUTPUT_DIR%\Neo.CLI\%TARGET_FRAMEWORK% |
| 211 | +echo You can run it using: cd %OUTPUT_DIR%\Neo.CLI\%TARGET_FRAMEWORK% ^&^& dotnet neo-cli.dll |
| 212 | + |
| 213 | +REM Verify essential plugins were installed |
| 214 | +set "ESSENTIAL_PLUGINS=DBFTPlugin ApplicationLogs RpcServer" |
| 215 | +for %%P in (%ESSENTIAL_PLUGINS%) do ( |
| 216 | + if not exist "%CLI_PLUGINS_DIR%\%%P\%%P.dll" ( |
| 217 | + echo Warning: Essential plugin %%P is missing |
| 218 | + echo Warning: Essential plugin %%P is missing >> "%LOG_FILE%" |
| 219 | + ) |
| 220 | +) |
| 221 | + |
| 222 | +exit /b 0 |
| 223 | + |
| 224 | +:FindDll |
| 225 | +setlocal |
| 226 | +set "DLL_NAME=%~1" |
| 227 | + |
| 228 | +REM First check if the DLL is already in the main bin directory |
| 229 | +if exist "%OUTPUT_DIR%\%DLL_NAME%" ( |
| 230 | + endlocal & set "FOUND_DLL=%OUTPUT_DIR%\%DLL_NAME%" |
| 231 | + exit /b 0 |
| 232 | +) |
| 233 | + |
| 234 | +REM Check in direct project folders under bin |
| 235 | +for /d %%D in ("%OUTPUT_DIR%\*") do ( |
| 236 | + set "PROJECT_DIR=%%D" |
| 237 | + set "PROJECT_DIR_NAME=%%~nxD" |
| 238 | + |
| 239 | + if exist "!PROJECT_DIR!\%DLL_NAME%" ( |
| 240 | + endlocal & set "FOUND_DLL=!PROJECT_DIR!\%DLL_NAME%" |
| 241 | + exit /b 0 |
| 242 | + ) |
| 243 | + |
| 244 | + REM Also check for nested target framework folders |
| 245 | + for /d %%F in ("!PROJECT_DIR!\*") do ( |
| 246 | + if exist "%%F\%DLL_NAME%" ( |
| 247 | + endlocal & set "FOUND_DLL=%%F\%DLL_NAME%" |
| 248 | + exit /b 0 |
| 249 | + ) |
| 250 | + ) |
| 251 | +) |
| 252 | + |
| 253 | +REM Common locations to check in the src directory |
| 254 | +set "SRC_DIR=%ROOT_DIR%\src" |
| 255 | +set "PATTERNS=*\bin\%BUILD_CONFIG%\%TARGET_FRAMEWORK%\%DLL_NAME% *\bin\%BUILD_CONFIG%\%DLL_NAME% *\*\bin\%BUILD_CONFIG%\%TARGET_FRAMEWORK%\%DLL_NAME% *\*\bin\%BUILD_CONFIG%\%DLL_NAME%" |
| 256 | + |
| 257 | +REM Check each pattern |
| 258 | +for %%P in (%PATTERNS%) do ( |
| 259 | + for /r "%SRC_DIR%" %%F in (%%P) do ( |
| 260 | + if exist "%%F" ( |
| 261 | + endlocal & set "FOUND_DLL=%%F" |
| 262 | + exit /b 0 |
| 263 | + ) |
| 264 | + ) |
| 265 | +) |
| 266 | + |
| 267 | +REM As a last resort, search the entire src directory |
| 268 | +echo Searching for %DLL_NAME% in src directory... |
| 269 | +for /r "%SRC_DIR%" %%F in (%DLL_NAME%) do ( |
| 270 | + if exist "%%F" ( |
| 271 | + endlocal & set "FOUND_DLL=%%F" |
| 272 | + exit /b 0 |
| 273 | + ) |
| 274 | +) |
| 275 | + |
| 276 | +endlocal & set "FOUND_DLL=" |
| 277 | +exit /b 0 |
| 278 | + |
| 279 | +:ProcessPluginDirectory |
| 280 | +setlocal EnableDelayedExpansion |
| 281 | +set "PLUGIN_DIR=%~1" |
| 282 | +set /a PLUGINS_FOUND+=1 |
| 283 | + |
| 284 | +REM Find all .csproj files in the directory |
| 285 | +set "FOUND_PROJECTS=0" |
| 286 | +for %%P in ("%PLUGIN_DIR%\*.csproj") do ( |
| 287 | + set "PROJECT_FILE=%%P" |
| 288 | + set "PROJECT_NAME=%%~nP" |
| 289 | + |
| 290 | + REM Build the plugin |
| 291 | + echo Building project: !PROJECT_NAME! |
| 292 | + echo Building project: !PROJECT_NAME! >> "%LOG_FILE%" |
| 293 | + dotnet build "!PROJECT_FILE!" -c %BUILD_CONFIG% |
| 294 | + if %ERRORLEVEL% neq 0 ( |
| 295 | + echo Failed to build !PROJECT_NAME! |
| 296 | + echo Failed to build !PROJECT_NAME! >> "%LOG_FILE%" |
| 297 | + exit /b 1 |
| 298 | + ) |
| 299 | + echo Successfully built !PROJECT_NAME! |
| 300 | + echo Successfully built !PROJECT_NAME! >> "%LOG_FILE%" |
| 301 | + |
| 302 | + REM Find the DLL file |
| 303 | + call :FindDll "!PROJECT_NAME!.dll" |
| 304 | + set "PLUGIN_DLL=%FOUND_DLL%" |
| 305 | + |
| 306 | + REM Create a plugin-specific folder in the Neo.CLI's plugins directory |
| 307 | + set "PLUGIN_SPECIFIC_DIR=%CLI_PLUGINS_DIR%\!PROJECT_NAME!" |
| 308 | + mkdir "%PLUGIN_SPECIFIC_DIR%" 2>nul |
| 309 | + |
| 310 | + REM Copy the plugin DLL to its specific directory |
| 311 | + if defined PLUGIN_DLL if exist "!PLUGIN_DLL!" ( |
| 312 | + echo Copying !PROJECT_NAME!.dll to %PLUGIN_SPECIFIC_DIR%\ from !PLUGIN_DLL! |
| 313 | + echo Copying !PROJECT_NAME!.dll to %PLUGIN_SPECIFIC_DIR%\ from !PLUGIN_DLL! >> "%LOG_FILE%" |
| 314 | + copy /Y "!PLUGIN_DLL!" "%PLUGIN_SPECIFIC_DIR%\" |
| 315 | + |
| 316 | + REM Verify the copy was successful |
| 317 | + if not exist "%PLUGIN_SPECIFIC_DIR%\!PROJECT_NAME!.dll" ( |
| 318 | + echo Error: Failed to copy !PROJECT_NAME!.dll to %PLUGIN_SPECIFIC_DIR% |
| 319 | + echo Error: Failed to copy !PROJECT_NAME!.dll to %PLUGIN_SPECIFIC_DIR% >> "%LOG_FILE%" |
| 320 | + exit /b 1 |
| 321 | + ) |
| 322 | + ) else ( |
| 323 | + echo Warning: Could not find DLL for !PROJECT_NAME! |
| 324 | + echo Warning: Could not find DLL for !PROJECT_NAME! >> "%LOG_FILE%" |
| 325 | + ) |
| 326 | + |
| 327 | + REM Look for the config file in multiple locations |
| 328 | + set "PLUGIN_CONFIG=%PLUGIN_DIR%\!PROJECT_NAME!.json" |
| 329 | + if not exist "!PLUGIN_CONFIG!" ( |
| 330 | + REM Try to find the config elsewhere |
| 331 | + for /r "%PLUGIN_DIR%" %%F in (!PROJECT_NAME!.json) do ( |
| 332 | + set "PLUGIN_CONFIG=%%F" |
| 333 | + goto :FoundConfig |
| 334 | + ) |
| 335 | + ) |
| 336 | + |
| 337 | + :FoundConfig |
| 338 | + REM Copy the plugin config if it exists |
| 339 | + if exist "!PLUGIN_CONFIG!" ( |
| 340 | + echo Copying !PROJECT_NAME!.json to %PLUGIN_SPECIFIC_DIR%\ from !PLUGIN_CONFIG! |
| 341 | + echo Copying !PROJECT_NAME!.json to %PLUGIN_SPECIFIC_DIR%\ from !PLUGIN_CONFIG! >> "%LOG_FILE%" |
| 342 | + copy /Y "!PLUGIN_CONFIG!" "%PLUGIN_SPECIFIC_DIR%\" |
| 343 | + |
| 344 | + REM Verify the copy was successful |
| 345 | + if not exist "%PLUGIN_SPECIFIC_DIR%\!PROJECT_NAME!.json" ( |
| 346 | + echo Error: Failed to copy !PROJECT_NAME!.json to %PLUGIN_SPECIFIC_DIR% |
| 347 | + echo Error: Failed to copy !PROJECT_NAME!.json to %PLUGIN_SPECIFIC_DIR% >> "%LOG_FILE%" |
| 348 | + exit /b 1 |
| 349 | + ) |
| 350 | + ) else ( |
| 351 | + echo No config file found for !PROJECT_NAME!, skipping config copy |
| 352 | + echo No config file found for !PROJECT_NAME!, skipping config copy >> "%LOG_FILE%" |
| 353 | + ) |
| 354 | + |
| 355 | + echo Plugin !PROJECT_NAME! installed |
| 356 | + echo Plugin !PROJECT_NAME! installed >> "%LOG_FILE%" |
| 357 | + echo. |
| 358 | + |
| 359 | + set /a FOUND_PROJECTS+=1 |
| 360 | + set /a PLUGINS_PROCESSED+=1 |
| 361 | +) |
| 362 | + |
| 363 | +if !FOUND_PROJECTS! equ 0 ( |
| 364 | + echo No project files found in !PLUGIN_DIR!, skipping |
| 365 | + echo No project files found in !PLUGIN_DIR!, skipping >> "%LOG_FILE%" |
| 366 | +) |
| 367 | + |
| 368 | +endlocal & set /a PLUGINS_PROCESSED=%PLUGINS_PROCESSED% & set /a PLUGINS_FOUND=%PLUGINS_FOUND% |
| 369 | +exit /b 0 |
0 commit comments