ci: simplify make.bat, make it verbose to fix errors easier

pull/12012/head
Delyan Angelov 2021-09-28 13:00:27 +03:00
parent d07a96ede8
commit c8f1e6b5b6
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 25 additions and 135 deletions

160
make.bat
View File

@ -4,10 +4,8 @@ setlocal EnableDelayedExpansion EnableExtensions
REM Option flags REM Option flags
set /a shift_counter=0 set /a shift_counter=0
set /a flag_local=0 set /a flag_local=0
set /a flag_verbose=0
REM Option variables REM Option variables
set "log_file=%TEMP%\v_make.log"
set compiler= set compiler=
set subcmd= set subcmd=
set target=build set target=build
@ -51,16 +49,6 @@ for %%g in (-gcc -msvc -tcc -tcc32 -clang) do (
) )
REM Standard options REM Standard options
if "%~1" == "--verbose" (
if !flag_verbose! NEQ 0 (
echo The flag %~1 has already been specified. 1>&2
exit /b 2
)
set /a flag_verbose=1
set /a shift_counter+=1
shift
goto :verifyopt
)
if "%~1" == "--local" ( if "%~1" == "--local" (
if !flag_local! NEQ 0 ( if !flag_local! NEQ 0 (
echo The flag %~1 has already been specified. 1>&2 echo The flag %~1 has already been specified. 1>&2
@ -71,22 +59,6 @@ if "%~1" == "--local" (
shift shift
goto :verifyopt goto :verifyopt
) )
if "%~1" == "--logfile" (
if ["%~2"] == [""] (
echo Log file is not specified for -logfile parameter. 1>&2
exit /b 2
)
pushd "%~dp2" || (
echo The log file specified for -logfile parameter does not exist. 1>&2
exit /b 2
)
popd
set "log_file=%~sf2"
set /a shift_counter+=2
shift
shift
goto :verifyopt
)
echo Undefined option: %~1 echo Undefined option: %~1
exit /b 2 exit /b 2
@ -100,33 +72,18 @@ if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL%
echo. echo.
echo Cleanup vc echo Cleanup vc
echo ^> Purge TCC binaries echo ^> Purge TCC binaries
if !flag_verbose! EQU 1 ( rmdir /s /q "%tcc_dir%"
echo [Debug] rmdir /s /q "%tcc_dir%">>"!log_file!"
echo rmdir /s /q "%tcc_dir%"
)
rmdir /s /q "%tcc_dir%">>"!log_file!"
echo ^> Purge vc repository echo ^> Purge vc repository
if !flag_verbose! EQU 1 ( rmdir /s /q "%vc_dir%"
echo [Debug] rmdir /s /q "%vc_dir%">>"!log_file!"
echo rmdir /s /q "%vc_dir%"
)
rmdir /s /q "%vc_dir%">>"!log_file!"
exit /b 0 exit /b 0
:clean :clean
echo Cleanup build artifacts echo Cleanup build artifacts
echo ^> Purge debug symbols echo ^> Purge debug symbols
if !flag_verbose! EQU 1 ( del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so
echo [Debug] del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so>>"!log_file!"
echo del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so
)
del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so>>"!log_file!"
echo ^> Delete old V executable echo ^> Delete old V executable
if !flag_verbose! EQU 1 ( del v_old.exe v*.exe
echo [Debug] del v_old.exe v*.exe>>"!log_file!"
echo del v_old.exe v*.exe
)
del v_old.exe v*.exe>>"!log_file!"
exit /b 0 exit /b 0
:help :help
@ -142,25 +99,12 @@ exit /b %ERRORLEVEL%
if !flag_local! NEQ 1 ( if !flag_local! NEQ 1 (
call :download_tcc call :download_tcc
if %ERRORLEVEL% NEQ 0 goto :error if %ERRORLEVEL% NEQ 0 goto :error
del "!log_file!"
pushd "%vc_dir%" && ( pushd "%vc_dir%" && (
echo Updating vc... echo Updating vc...
echo ^> Sync with remote !vc_url! echo ^> Sync with remote !vc_url!
if !flag_verbose! EQU 1 ( cd "%vc_dir%"
echo [Debug] cd "%vc_dir%">>"!log_file!" git pull --quiet
echo cd "%vc_dir%" cd ..
cd "%vc_dir%">>"!log_file!"
echo [Debug] git pull --quiet>>"!log_file!"
echo git pull --quiet
git pull --quiet>>"!log_file!"
echo [Debug] cd ..>>"!log_file!"
echo cd ..
cd ..>>"!log_file!"
) else (
cd "%vc_dir%">>"!log_file!"
git pull --quiet>>"!log_file!"
cd ..>>"!log_file!"
)
popd popd
) || call :cloning_vc ) || call :cloning_vc
echo. echo.
@ -174,19 +118,11 @@ REM By default, use tcc, since we have it prebuilt:
:tcc_strap :tcc_strap
:tcc32_strap :tcc32_strap
echo ^> Attempting to build v_win.c with TCC echo ^> Attempting to build v_win.c with TCC
if !flag_verbose! EQU 1 ( "!tcc_exe!" -Ithirdparty/stdatomic/win -bt10 -w -o v.exe vc\v_win.c -ladvapi32
echo [Debug] "!tcc_exe!" -ladvapi32 -I .\thirdparty\stdatomic\win -bt10 -w -o v.exe vc\v_win.c>>"!log_file!"
echo "!tcc_exe!" -ladvapi32 -I .\thirdparty\stdatomic\win -bt10 -w -o v.exe vc\v_win.c
)
"!tcc_exe!" -ladvapi32 -I .\thirdparty\stdatomic\win -bt10 -w -o v.exe vc\v_win.c>>"!log_file!"
if %ERRORLEVEL% NEQ 0 goto :compile_error if %ERRORLEVEL% NEQ 0 goto :compile_error
echo ^> Compiling with .\v.exe self echo ^> Compiling with .\v.exe self
if !flag_verbose! EQU 1 ( v.exe -cc "!tcc_exe!" self
echo [Debug] v.exe -cc "!tcc_exe!" self>>"!log_file!"
echo v.exe -cc "!tcc_exe!" self
)
v.exe -cc "!tcc_exe!" self>>"!log_file!"
if %ERRORLEVEL% NEQ 0 goto :clang_strap if %ERRORLEVEL% NEQ 0 goto :clang_strap
goto :success goto :success
@ -201,23 +137,15 @@ if %ERRORLEVEL% NEQ 0 (
) )
echo ^> Attempting to build v_win.c with Clang echo ^> Attempting to build v_win.c with Clang
if !flag_verbose! EQU 1 ( clang -std=c99 -Ithirdparty/stdatomic/win -municode -w -o v.exe .\vc\v_win.c
echo [Debug] clang -std=c99 -municode -I .\thirdparty\stdatomic\win -w -o v.exe .\vc\v_win.c>>"!log_File!"
echo clang -std=c99 -municode -I .\thirdparty\stdatomic\win -w -o v.exe .\vc\v_win.c
)
clang -std=c99 -municode -w -o v.exe .\vc\v_win.c>>"!log_file!"
if %ERRORLEVEL% NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
REM In most cases, compile errors happen because the version of Clang installed is too old REM In most cases, compile errors happen because the version of Clang installed is too old
clang --version>>"!log_file!" clang --version
goto :compile_error goto :compile_error
) )
echo ^> Compiling with .\v.exe self echo ^> Compiling with .\v.exe self
if !flag_verbose! EQU 1 ( v.exe -cc clang self
echo [Debug] v.exe -cc clang self>>"!log_file!"
echo v.exe -cc clang self
)
v.exe -cc clang self>>"!log_file!"
if %ERRORLEVEL% NEQ 0 goto :compile_error if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success goto :success
@ -230,23 +158,15 @@ if %ERRORLEVEL% NEQ 0 (
) )
echo ^> Attempting to build v_win.c with GCC echo ^> Attempting to build v_win.c with GCC
if !flag_verbose! EQU 1 ( gcc -std=c99 -municode -Ithirdparty/stdatomic/win -w -o v.exe .\vc\v_win.c
echo [Debug] gcc -std=c99 -municode -I .\thirdparty\stdatomic\win -w -o v.exe .\vc\v_win.c>>"!log_File!"
echo gcc -std=c99 -municode -I .\thirdparty\stdatomic\win -w -o v.exe .\vc\v_win.c
)
gcc -std=c99 -municode -I .\thirdparty\stdatomic\win -w -o v.exe .\vc\v_win.c>>"!log_File!"
if %ERRORLEVEL% NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
REM In most cases, compile errors happen because the version of GCC installed is too old REM In most cases, compile errors happen because the version of GCC installed is too old
gcc --version>>"!log_File!" gcc --version
goto :compile_error goto :compile_error
) )
echo ^> Compiling with .\v.exe self echo ^> Compiling with .\v.exe self
if !flag_verbose! EQU 1 ( v.exe -cc gcc self
echo [Debug] v.exe -cc gcc self>>"!log_file!"
echo v.exe -cc gcc self
)
v.exe -cc gcc self>>"!log_file!"
if %ERRORLEVEL% NEQ 0 goto :compile_error if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success goto :success
@ -278,24 +198,16 @@ if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
set ObjFile=.v.c.obj set ObjFile=.v.c.obj
echo ^> Attempting to build v_win.c with MSVC echo ^> Attempting to build v_win.c with MSVC
if !flag_verbose! EQU 1 ( cl.exe /volatile:ms /I thirdparty\stdatomic\win /Fo%ObjFile% /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /nologo /out:v.exe /incremental:no
echo [Debug] cl.exe /volatile:ms /Fo%ObjFile% /I .\thirdparty\stdatomic\win /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /nologo /out:v.exe /incremental:no>>"!log_file!"
echo cl.exe /volatile:ms /Fo%ObjFile% /I .\thirdparty\stdatomic\win /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /nologo /out:v.exe /incremental:no
)
cl.exe /volatile:ms /Fo%ObjFile% /O2 /MD /D_VBOOTSTRAP vc\v_win.c user32.lib kernel32.lib advapi32.lib shell32.lib /link /nologo /out:v.exe /incremental:no>>"!log_file!"
if %ERRORLEVEL% NEQ 0 ( if %ERRORLEVEL% NEQ 0 (
REM In some cases, compile errors happen because of the MSVC compiler version REM In some cases, compile errors happen because of the MSVC compiler version
cl.exe 2>"!log_file!" cl.exe
goto :compile_error goto :compile_error
) )
echo ^> Compiling with .\v.exe self echo ^> Compiling with .\v.exe self
if !flag_verbose! EQU 1 ( v.exe -cc msvc self
echo [Debug] v.exe -cc msvc self>>"!log_file!" del %ObjFile%
echo v.exe -cc msvc self
)
v.exe -cc msvc self>>"!log_file!"
del %ObjFile%>>"!log_file!" 2>>&1
if %ERRORLEVEL% NEQ 0 goto :compile_error if %ERRORLEVEL% NEQ 0 goto :compile_error
goto :success goto :success
@ -303,11 +215,7 @@ goto :success
pushd %tcc_dir% && ( pushd %tcc_dir% && (
echo Updating TCC echo Updating TCC
echo ^> Syncing TCC from !tcc_url! echo ^> Syncing TCC from !tcc_url!
if !flag_verbose! EQU 1 ( git pull --quiet
echo [Debug] git pull --quiet>>"!log_file!"
echo git pull --quiet
)
git pull --quiet>>"!log_file!"
popd popd
) || call :bootstrap_tcc ) || call :bootstrap_tcc
@ -322,13 +230,12 @@ exit /b 0
:compile_error :compile_error
echo. echo.
type "!log_file!" echo Backend compiler error
goto :error goto :error
:error :error
echo. echo.
echo Exiting from error echo Exiting from error
type "!log_file!"
echo ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows echo ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows
exit /b 1 exit /b 1
@ -357,7 +264,7 @@ echo help Display usage help for the given targ
echo. echo.
echo Examples: echo Examples:
echo make.bat -msvc echo make.bat -msvc
echo make.bat -gcc --local --logpath output.log echo make.bat -gcc --local
echo make.bat build -tcc --local echo make.bat build -tcc --local
echo make.bat -tcc32 echo make.bat -tcc32
echo make.bat help clean echo make.bat help clean
@ -379,18 +286,12 @@ exit /b 0
echo Usage: echo Usage:
echo make.bat clean echo make.bat clean
echo. echo.
echo Options:
echo --logfile PATH Use the specified PATH as the log
echo --verbose Output compilation commands to stdout
exit /b 0 exit /b 0
:help_cleanall :help_cleanall
echo Usage: echo Usage:
echo make.bat cleanall echo make.bat cleanall
echo. echo.
echo Options:
echo --logfile PATH Use the specified PATH as the log
echo --verbose Output compilation commands to stdout
exit /b 0 exit /b 0
:help_build :help_build
@ -403,30 +304,19 @@ echo.
echo Options: echo Options:
echo --local Use the local vc repository without echo --local Use the local vc repository without
echo syncing with remote echo syncing with remote
echo --logfile PATH Use the specified PATH as the log
echo file
echo --verbose Output compilation commands to stdout
exit /b 0 exit /b 0
:bootstrap_tcc :bootstrap_tcc
echo Bootstraping TCC... echo Bootstraping TCC...
echo ^> TCC not found echo ^> TCC not found
if "!tcc_branch!" == "thirdparty-windows-i386" ( echo ^> Downloading TCC32 from !tcc_url! ) else ( echo ^> Downloading TCC64 from !tcc_url! ) if "!tcc_branch!" == "thirdparty-windows-i386" ( echo ^> Downloading TCC32 from !tcc_url! ) else ( echo ^> Downloading TCC64 from !tcc_url! )
if !flag_verbose! EQU 1 ( git clone --depth 1 --quiet --single-branch --branch !tcc_branch! !tcc_url! "%tcc_dir%"
echo [Debug] git clone --depth 1 --quiet --single-branch --branch !tcc_branch! !tcc_url! "%tcc_dir%">>"!log_file!"
echo git clone --depth 1 --quiet --single-branch --branch !tcc_branch! !tcc_url! "%tcc_dir%"
)
git clone --depth 1 --quiet --single-branch --branch !tcc_branch! !tcc_url! "%tcc_dir%">>"!log_file!"
exit /b 0 exit /b 0
:cloning_vc :cloning_vc
echo Cloning vc... echo Cloning vc...
echo ^> Cloning from remote !vc_url! echo ^> Cloning from remote !vc_url!
if !flag_verbose! EQU 1 ( git clone --depth 1 --quiet %vc_url%
echo [Debug] git clone --depth 1 --quiet %vc_url%>>"!log_file!"
echo git clone --depth 1 --quiet %vc_url%
)
git clone --depth 1 --quiet %vc_url%>>"!log_file!"
exit /b 0 exit /b 0
:eof :eof