Skip to content

Commit 8df8866

Browse files
authored
make.bat: improve diagnostics, do not add V to PATH automatically (#5789)
1 parent 7d6ba2d commit 8df8866

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ jobs:
265265
- name: Build
266266
run: |
267267
gcc --version
268-
.\make.bat -gcc -skip-path
268+
.\make.bat -gcc
269269
- name: Test new v.c
270270
run: .\v.exe -o v.c cmd/v && gcc -municode -w v.c
271271
- name: Install dependencies
@@ -300,7 +300,7 @@ jobs:
300300
run: |
301301
echo %VFLAGS%
302302
echo $VFLAGS
303-
.\make.bat -msvc -skip-path
303+
.\make.bat -msvc
304304
- name: Install dependencies
305305
run: |
306306
.\v.exe setup-freetype
@@ -331,12 +331,12 @@ jobs:
331331
# with:
332332
# node-version: 12.x
333333
- name: Build
334-
# We need to move gcc and msvc, so that V doesn't find a C compiler
334+
# We need to move gcc and msvc, so that V can't find an existing C compiler and downloads tcc
335335
run: |
336336
'for /f "usebackq tokens=*" %i in (`where gcc.exe`) do move /Y "%i" "%i.old"' | cmd
337337
'for /f "usebackq tokens=*" %i in (`where vswhere.exe`) do move /Y "%i" "%i.old"' | cmd
338338
move "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe.old"
339-
.\make.bat -skip-path
339+
.\make.bat
340340
- name: Test new v.c
341341
run: .\v.exe -o v.c cmd/v && .\thirdparty\tcc\tcc.exe -w -ladvapi32 -bt10 v.c
342342
- name: Install dependencies

make.bat

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
echo Building V
44

5+
set log_file=%TEMP%\v_make.bat.log
56
set tcc_path=%~dp0thirdparty\tcc\
67
pushd %~dp0
78

@@ -19,10 +20,6 @@ if exist "vc" (
1920
)
2021

2122
:compile
22-
REM option to disable adding V to PATH
23-
if "%~1"=="-skip-path" set skip_path=1
24-
if "%~2"=="-skip-path" set skip_path=1
25-
2623
REM option to force msvc, gcc or tcc
2724
if "%~1"=="-gcc" set force_gcc=1 & goto :gcc_strap
2825
if "%~2"=="-gcc" set force_gcc=1 & goto :gcc_strap
@@ -42,10 +39,14 @@ if %ERRORLEVEL% NEQ 0 (
4239
goto :msvc_strap
4340
)
4441

45-
gcc -std=c99 -municode -w -o v.exe vc\v_win.c
46-
if %ERRORLEVEL% NEQ 0 goto :compile_error
42+
gcc -std=c99 -municode -w -o v.exe vc\v_win.c>>%log_file% 2>>&1
43+
if %ERRORLEVEL% NEQ 0 (
44+
rem In most cases, compile errors happen because the version of GCC installed is too old
45+
gcc --version>>%log_file% 2>>&1
46+
goto :compile_error
47+
)
4748

48-
v.exe self > NUL
49+
v.exe self>>%log_file% 2>>&1
4950
if %ERRORLEVEL% NEQ 0 goto :compile_error
5051
goto :success
5152

@@ -78,10 +79,10 @@ if exist "%InstallDir%\Common7\Tools\vsdevcmd.bat" (
7879

7980
set ObjFile=.v.c.obj
8081

81-
cl.exe /nologo /w /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 > NUL
82+
cl.exe /nologo /w /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% 2>>&1
8283
if %ERRORLEVEL% NEQ 0 goto :compile_error
8384

84-
v.exe -cc msvc self
85+
v.exe -cc msvc self>>%log_file% 2>>&1
8586
del %ObjFile%
8687
if %ERRORLEVEL% NEQ 0 goto :compile_error
8788
goto :success
@@ -115,19 +116,24 @@ if exist "%tcc_path%" (
115116
if "%cloned_tcc%"=="" (
116117
echo ^> Updating prebuilt TCC...
117118
pushd "%tcc_path%"
118-
git pull -q > NUL
119+
git pull -q
119120
popd
120121
)
121122
)
122123
call "%tcc_exe%" -std=c99 -municode -lws2_32 -lshell32 -ladvapi32 -bt10 -w -o v.exe vc\v_win.c
123124
if %ERRORLEVEL% NEQ 0 goto :compile_error
124125

125-
v.exe -cc "%tcc_exe%" self > NUL
126+
v.exe -cc "%tcc_exe%" self>>%log_file% 2>>&1
126127
if %ERRORLEVEL% NEQ 0 goto :compile_error
127128
goto :success
128129

129130
:compile_error
130-
echo Failed to compile - Create an issue at 'https://github.com/vlang'
131+
echo.
132+
echo.
133+
echo Failed to compile - Create an issue at 'https://github.com/vlang' with the following info:
134+
echo.
135+
type %log_file%
136+
del %log_file%
131137
goto :error
132138

133139
:error
@@ -138,26 +144,9 @@ exit /b 1
138144

139145
:success
140146
echo ^> V built successfully!
147+
echo ^> To add V to your PATH, run `.\v symlink`.
141148
del v_old.exe
142-
143-
:path
144-
if "%skip_path%" NEQ "" goto :version
145-
echo.
146-
echo Adding V to PATH...
147-
v.exe symlink > NUL
148-
if %ERRORLEVEL% NEQ 0 (
149-
echo ^> Could not add V to %%PATH%%, try rebuilding as admin.
150-
goto :error
151-
)
152-
echo ^> V added to %%PATH%%
153-
154-
if "%cloned_tcc%" NEQ "" (
155-
echo @echo off> "%~dp0.bin\tcc.bat"
156-
echo %tcc_path%tcc %%^*>> "%~dp0.bin\tcc.bat"
157-
echo ^> TCC added to %%PATH%%
158-
)
159-
160-
echo ^> Restart your shell/IDE to reload it
149+
del %log_file%
161150

162151
:version
163152
echo.

0 commit comments

Comments
 (0)