run_build_tool.cmd
1 @echo off 2 setlocal 3 4 setlocal ENABLEDELAYEDEXPANSION 5 6 SET BASEDIR=%~dp0 7 8 if not exist "%CARGOKIT_TOOL_TEMP_DIR%" ( 9 mkdir "%CARGOKIT_TOOL_TEMP_DIR%" 10 ) 11 cd /D "%CARGOKIT_TOOL_TEMP_DIR%" 12 13 SET BUILD_TOOL_PKG_DIR=%BASEDIR%build_tool 14 SET DART=%FLUTTER_ROOT%\bin\cache\dart-sdk\bin\dart 15 16 set BUILD_TOOL_PKG_DIR_POSIX=%BUILD_TOOL_PKG_DIR:\=/% 17 18 ( 19 echo name: build_tool_runner 20 echo version: 1.0.0 21 echo publish_to: none 22 echo. 23 echo environment: 24 echo sdk: '^>=3.0.0 ^<4.0.0' 25 echo. 26 echo dependencies: 27 echo build_tool: 28 echo path: %BUILD_TOOL_PKG_DIR_POSIX% 29 ) >pubspec.yaml 30 31 if not exist bin ( 32 mkdir bin 33 ) 34 35 ( 36 echo import 'package:build_tool/build_tool.dart' as build_tool; 37 echo void main^(List^<String^> args^) ^{ 38 echo build_tool.runMain^(args^); 39 echo ^} 40 ) >bin\build_tool_runner.dart 41 42 SET PRECOMPILED=bin\build_tool_runner.dill 43 44 REM To detect changes in package we compare output of DIR /s (recursive) 45 set PREV_PACKAGE_INFO=.dart_tool\package_info.prev 46 set CUR_PACKAGE_INFO=.dart_tool\package_info.cur 47 48 DIR "%BUILD_TOOL_PKG_DIR%" /s > "%CUR_PACKAGE_INFO%_orig" 49 50 REM Last line in dir output is free space on harddrive. That is bound to 51 REM change between invocation so we need to remove it 52 ( 53 Set "Line=" 54 For /F "UseBackQ Delims=" %%A In ("%CUR_PACKAGE_INFO%_orig") Do ( 55 SetLocal EnableDelayedExpansion 56 If Defined Line Echo !Line! 57 EndLocal 58 Set "Line=%%A") 59 ) >"%CUR_PACKAGE_INFO%" 60 DEL "%CUR_PACKAGE_INFO%_orig" 61 62 REM Compare current directory listing with previous 63 FC /B "%CUR_PACKAGE_INFO%" "%PREV_PACKAGE_INFO%" > nul 2>&1 64 65 If %ERRORLEVEL% neq 0 ( 66 REM Changed - copy current to previous and remove precompiled kernel 67 if exist "%PREV_PACKAGE_INFO%" ( 68 DEL "%PREV_PACKAGE_INFO%" 69 ) 70 MOVE /Y "%CUR_PACKAGE_INFO%" "%PREV_PACKAGE_INFO%" 71 if exist "%PRECOMPILED%" ( 72 DEL "%PRECOMPILED%" 73 ) 74 ) 75 76 REM There is no CUR_PACKAGE_INFO it was renamed in previous step to %PREV_PACKAGE_INFO% 77 REM which means we need to do pub get and precompile 78 if not exist "%PRECOMPILED%" ( 79 echo Running pub get in "%cd%" 80 "%DART%" pub get --no-precompile 81 "%DART%" compile kernel bin/build_tool_runner.dart 82 ) 83 84 "%DART%" "%PRECOMPILED%" %* 85 86 REM 253 means invalid snapshot version. 87 If %ERRORLEVEL% equ 253 ( 88 "%DART%" pub get --no-precompile 89 "%DART%" compile kernel bin/build_tool_runner.dart 90 "%DART%" "%PRECOMPILED%" %* 91 )