Skip to content

Commit 19bc66f

Browse files
committed
Update install script to match recent changes in VSNASM.
Supports vswhere, multiple installation detection and VS2019 support. closes #3 #2
1 parent 860e567 commit 19bc66f

File tree

1 file changed

+203
-62
lines changed

1 file changed

+203
-62
lines changed

install_script.bat

Lines changed: 203 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
@echo OFF
2-
setlocal enabledelayedexpansion
2+
setlocal
33

44
REM Defined cript variables
55
set YASMDL=http://www.tortall.net/projects/yasm/releases
66
set YASMVERSION=1.3.0
7+
set VSWHEREDL=https://github.com/Microsoft/vswhere/releases/download
8+
set VSWHEREVERSION=2.5.9
79

810
REM Store current directory and ensure working directory is the location of current .bat
911
set CALLDIR=%CD%
1012
set SCRIPTDIR=%~dp0
1113

1214
REM Initialise error check value
13-
SET ERROR=0
15+
set ERROR=0
16+
REM Check if being called from another instance
17+
if not "%~1"=="" (
18+
set MSVC_VER=%~1
19+
set VSINSTANCEDIR=%2
20+
set ISINSTANCE=1
21+
goto MSVCCALL
22+
)
1423

1524
REM Check what architecture we are installing on
1625
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
@@ -33,7 +42,10 @@ REM Check if already running in an environment with VS setup
3342
if defined VCINSTALLDIR (
3443
if defined VisualStudioVersion (
3544
echo Existing Visual Studio environment detected...
36-
if "%VisualStudioVersion%"=="15.0" (
45+
if "%VisualStudioVersion%"=="16.0" (
46+
set MSVC_VER=16
47+
goto MSVCVarsDone
48+
) else if "%VisualStudioVersion%"=="15.0" (
3749
set MSVC_VER=15
3850
goto MSVCVarsDone
3951
) else if "%VisualStudioVersion%"=="14.0" (
@@ -48,61 +60,185 @@ if defined VCINSTALLDIR (
4860
)
4961
)
5062

63+
REM Get vswhere to detect VS installs
64+
if exist "%SCRIPTDIR%\vswhere.exe" (
65+
echo Using existing vswhere binary...
66+
goto VSwhereDetection
67+
)
68+
set VSWHEREDOWNLOAD=%VSWHEREDL%/%VSWHEREVERSION%/vswhere.exe
69+
echo Downloading required vswhere release binary...
70+
powershell.exe -Command (New-Object Net.WebClient).DownloadFile('%VSWHEREDOWNLOAD%', '%SCRIPTDIR%\vswhere.exe') >nul 2>&1
71+
if not exist "%SCRIPTDIR%\vswhere.exe" (
72+
echo Error: Failed to download required vswhere binary!
73+
echo The following link could not be resolved "%VSWHEREDOWNLOAD%"
74+
echo Now trying fallback detection..."
75+
goto MSVCRegDetection
76+
)
77+
78+
:VSwhereDetection
79+
REM Use vswhere to list detected installs
80+
for /f "usebackq tokens=1* delims=: " %%i in (`"%SCRIPTDIR%\vswhere.exe" -prerelease -requires Microsoft.Component.MSBuild`) do (
81+
if /i "%%i"=="installationPath" (
82+
for /f "delims=" %%a in ('echo %%j ^| find "2019"') do (
83+
if not "%%a"=="" (
84+
echo Visual Studio 2019 environment detected...
85+
call "%~0" "16" "%%j"
86+
if not ERRORLEVEL 1 (
87+
set MSVC16=1
88+
set MSVCFOUND=1
89+
)
90+
)
91+
)
92+
for /f "delims=" %%a in ('echo %%j ^| find "2017"') do (
93+
if not "%%a"=="" (
94+
echo Visual Studio 2017 environment detected...
95+
call "%~0" "15" "%%j"
96+
if not ERRORLEVEL 1 (
97+
set MSVC15=1
98+
set MSVCFOUND=1
99+
)
100+
)
101+
)
102+
)
103+
)
104+
105+
REM Try and use vswhere to detect legacy installs
106+
for /f "usebackq tokens=1* delims=: " %%i in (`"%SCRIPTDIR%\vswhere.exe" -legacy`) do (
107+
if /i "%%i"=="installationPath" (
108+
for /f "delims=" %%a in ('echo %%j ^| find "2015"') do (
109+
if not "%%a"=="" (
110+
echo Visual Studio 2015 environment detected...
111+
call "%~0" "13" "%%j"
112+
if not ERRORLEVEL 1 (
113+
set MSVC13=1
114+
set MSVCFOUND=1
115+
)
116+
)
117+
)
118+
for /f "delims=" %%a in ('echo %%j ^| find "2013"') do (
119+
if not "%%a"=="" (
120+
echo Visual Studio 2013 environment detected...
121+
call "%~0" "12" "%%j"
122+
if not ERRORLEVEL 1 (
123+
set MSVC12=1
124+
set MSVCFOUND=1
125+
)
126+
)
127+
)
128+
)
129+
)
130+
if not defined MSVCFOUND (
131+
echo Error: Failed to detect VS installations using vswhere!
132+
echo Now trying fallback detection...
133+
) else (
134+
goto Exit
135+
)
136+
137+
:MSVCRegDetection
138+
if "%SYSARCH%"=="32" (
139+
set MSVCVARSDIR=
140+
set WOWNODE=
141+
) else if "%SYSARCH%"=="64" (
142+
set MSVCVARSDIR=\amd64
143+
set WOWNODE=\WOW6432Node
144+
) else (
145+
goto Terminate
146+
)
51147
REM First check for a environment variable to help locate the VS installation
52148
if defined VS140COMNTOOLS (
53-
if exist "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" (
149+
if exist "%VS140COMNTOOLS%\..\..\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat" (
54150
echo Visual Studio 2015 environment detected...
55-
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" >nul 2>&1
56-
set MSVC_VER=14
57-
goto MSVCVarsDone
151+
call "%~0" "14" "%VS140COMNTOOLS%\..\..\"
152+
if not ERRORLEVEL 1 (
153+
set MSVC14=1
154+
set MSVCFOUND=1
155+
)
58156
)
59157
)
60158
if defined VS120COMNTOOLS (
61-
if exist "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" (
159+
if exist "%VS120COMNTOOLS%\..\..\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat" (
62160
echo Visual Studio 2013 environment detected...
63-
call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" >nul 2>&1
64-
set MSVC_VER=12
65-
goto MSVCVarsDone
161+
call "%~0" "12" "%VS120COMNTOOLS%\..\..\"
162+
if not ERRORLEVEL 1 (
163+
set MSVC12=1
164+
set MSVCFOUND=1
165+
)
66166
)
67167
)
68168

69169
REM Check for default install locations based on current system architecture
170+
if not defined MSVC15 (
171+
reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0 >nul 2>&1
172+
if not ERRORLEVEL 1 (
173+
echo Visual Studio 2017 installation detected...
174+
for /f "skip=2 tokens=2,*" %%i in ('reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0') do (
175+
call "%~0" "15" "%%j"
176+
if not ERRORLEVEL 1 (
177+
set MSVC15=1
178+
set MSVCFOUND=1
179+
)
180+
)
181+
)
182+
)
183+
if not defined MSVC14 (
184+
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir" >nul 2>&1
185+
if not ERRORLEVEL 1 (
186+
echo Visual Studio 2015 installation detected...
187+
for /f "skip=2 tokens=2,*" %%i in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir"') do (
188+
call "%~0" "14" "%%j"
189+
if not ERRORLEVEL 1 (
190+
set MSVC14=1
191+
set MSVCFOUND=1
192+
)
193+
)
194+
)
195+
)
196+
if not defined MSVC12 (
197+
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir" >nul 2>&1
198+
if not ERRORLEVEL 1 (
199+
echo Visual Studio 2013 installation detected...
200+
for /f "skip=2 tokens=2,*" %%i in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir"') do (
201+
call "%~0" "12" "%%j"
202+
if not ERRORLEVEL 1 (
203+
set MSVC12=1
204+
set MSVCFOUND=1
205+
)
206+
)
207+
)
208+
)
209+
if not defined MSVCFOUND (
210+
echo Error: Could not find valid Visual Studio installation!
211+
goto Terminate
212+
)
213+
goto Exit
214+
215+
:MSVCCALL
70216
if "%SYSARCH%"=="32" (
71217
set MSVCVARSDIR=
72-
set WOWNODE=
73218
) else if "%SYSARCH%"=="64" (
74219
set MSVCVARSDIR=\amd64
75-
set WOWNODE=\WOW6432Node
76220
) else (
77221
goto Terminate
78222
)
79-
80-
reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0 >nul 2>&1
81-
if not ERRORLEVEL 1 (
82-
echo Visual Studio 2017 installation detected...
83-
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0') do (set VSINSTALLDIR=%%b)
84-
call "!VSINSTALLDIR!VC\Auxiliary\Build\vcvars%SYSARCH%.bat" >nul 2>&1
85-
set MSVC_VER=15
86-
goto MSVCVarsDone
87-
)
88-
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir" >nul 2>&1
89-
if not ERRORLEVEL 1 (
90-
echo Visual Studio 2015 installation detected...
91-
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir"') do (set VSINSTALLDIR=%%b)
92-
call "!VSINSTALLDIR!\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat" >nul 2>&1
93-
set MSVC_VER=14
94-
goto MSVCVarsDone
223+
REM Call the required vcvars file in order to setup up build locations
224+
if "%MSVC_VER%"=="16" (
225+
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
226+
) else if "%MSVC_VER%"=="15" (
227+
set VCVARS=%VSINSTANCEDIR%\VC\Auxiliary\Build\vcvars%SYSARCH%.bat
228+
) else if "%MSVC_VER%"=="14" (
229+
set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
230+
) else if "%MSVC_VER%"=="12" (
231+
set VCVARS=%VSINSTANCEDIR%\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat
232+
) else (
233+
echo Error: Invalid MSVC version!
234+
goto Terminate
95235
)
96-
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir" >nul 2>&1
97-
if not ERRORLEVEL 1 (
98-
echo Visual Studio 2013 installation detected...
99-
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir"') do (set VSINSTALLDIR=%%b)
100-
call "!VSINSTALLDIR!\VC\bin%MSVCVARSDIR%\vcvars%SYSARCH%.bat" >nul 2>&1
101-
set MSVC_VER=12
102-
goto MSVCVarsDone
236+
if exist %VCVARS% (
237+
call %VCVARS% >nul 2>&1
238+
) else (
239+
echo Error: Invalid VS install location detected!
240+
goto Terminate
103241
)
104-
echo Error: Could not find valid Visual Studio installation!
105-
goto Terminate
106242

107243
:MSVCVarsDone
108244
REM Get the location of the current msbuild
@@ -115,13 +251,15 @@ if not ERRORLEVEL 1 (
115251
)
116252
set /p MSBUILDDIR=<"%SCRIPTDIR%\msbuild.txt"
117253
del /F /Q "%SCRIPTDIR%\msbuild.txt" >nul 2>&1
118-
if "%MSVC_VER%"=="15" (
119-
set VCTargetsPath="..\..\..\Common7\IDE\VC\VCTargets"
254+
if "%MSVC_VER%"=="16" (
255+
set VCTargetsPath="..\..\Microsoft\VC\v160\BuildCustomizations"
256+
) else if "%MSVC_VER%"=="15" (
257+
set VCTargetsPath="..\..\..\Common7\IDE\VC\VCTargets\BuildCustomizations"
120258
) else (
121259
if "%MSBUILDDIR%"=="%MSBUILDDIR:amd64=%" (
122-
set VCTargetsPath="..\..\Microsoft.Cpp\v4.0\V%MSVC_VER%0"
260+
set VCTargetsPath="..\..\Microsoft.Cpp\v4.0\V%MSVC_VER%0\BuildCustomizations"
123261
) else (
124-
set VCTargetsPath="..\..\..\Microsoft.Cpp\v4.0\V%MSVC_VER%0"
262+
set VCTargetsPath="..\..\..\Microsoft.Cpp\v4.0\V%MSVC_VER%0\BuildCustomizations"
125263
)
126264
)
127265

@@ -139,23 +277,35 @@ if not "%CURRDIR%"=="%CD%" (
139277

140278
REM copy the BuildCustomizations to VCTargets folder
141279
echo Installing build customisations...
142-
del /F /Q "%VCTargetsPath%\BuildCustomizations\yasm.*" >nul 2>&1
143-
copy /B /Y /V "%SCRIPTDIR%\yasm.*" "%VCTargetsPath%\BuildCustomizations\" >nul 2>&1
280+
del /F /Q "%VCTargetsPath%\yasm.*" >nul 2>&1
281+
copy /B /Y /V "%SCRIPTDIR%\yasm.*" "%VCTargetsPath%\" >nul 2>&1
144282
if %ERRORLEVEL% neq 0 (
145283
echo Error: Failed to copy build customisations!
146284
echo Ensure that this script is run in a shell with the necessary write privileges
147285
goto Terminate
148286
)
149287

150288
REM Check if a yasm binary was bundled
151-
if not exist "%SCRIPTDIR%\yasm\" (
152-
REM Download the latest yasm binary for windows goto Terminate
153-
call :DownloadYasm
154-
) else (
289+
if exist "%SCRIPTDIR%\yasm\" (
155290
REM Use the bundled binaries
156291
copy /B /Y /V "%SCRIPTDIR%\yasm\yasm-%SYSARCH%.exe" "%SCRIPTDIR%\yasm.exe" >nul 2>&1
292+
goto InstallYASM
293+
) else if exist "%SCRIPTDIR%\yasm_%YASMVERSION%.zip" (
294+
echo Using existing NASM binary...
295+
goto InstallNASM
296+
)
297+
298+
REM Download the latest yasm binary for windows goto Terminate
299+
echo Downloading required YASM release binary...
300+
set YASMDOWNLOAD=%YASMDL%/yasm-%YASMVERSION%-win%SYSARCH%.exe
301+
powershell.exe -Command (New-Object Net.WebClient).DownloadFile('%YASMDOWNLOAD%', '%SCRIPTDIR%\yasm_%YASMVERSION%.exe') >nul 2>&1
302+
if not exist "%SCRIPTDIR%\yasm_%YASMVERSION%.exe" (
303+
echo Error: Failed to download required YASM binary!
304+
echo The following link could not be resolved "%YASMDOWNLOAD%"
305+
goto Terminate
157306
)
158307

308+
:InstallYASM
159309
REM copy yasm executable to VC installation folder
160310
echo Installing required YASM release binary...
161311
del /F /Q "%VCINSTALLDIR%\yasm.exe" >nul 2>&1
@@ -175,18 +325,9 @@ SET ERROR=1
175325

176326
:Exit
177327
cd %CALLDIR%
178-
IF "%APPVEYOR%"=="" (
179-
pause
180-
)
181-
exit /b %ERROR%
182-
183-
:DownloadYasm
184-
echo Downloading required YASM release binary...
185-
set YASMDOWNLOAD=%YASMDL%/yasm-%YASMVERSION%-win%SYSARCH%.exe
186-
powershell.exe -Command (New-Object Net.WebClient).DownloadFile('%YASMDOWNLOAD%', '%SCRIPTDIR%\yasm.exe') >nul 2>&1
187-
if not exist "%SCRIPTDIR%\yasm.exe" (
188-
echo Error: Failed to download required YASM binary!
189-
echo The following link could not be resolved "%YASMDOWNLOAD%"
190-
goto Terminate
328+
if "%APPVEYOR%"=="" (
329+
if not defined ISINSTANCE (
330+
pause
331+
)
191332
)
192-
goto :eof
333+
endlocal & exit /b %ERROR%

0 commit comments

Comments
 (0)