Skip to content

Commit 7a251c5

Browse files
Use delayed variable expansion in setup.bat (#1168)
* Rename variable 7ZIP to SEVENZIP Currently this script fails, as %7ZIP% is interpreted as "ZIP", because %7 is treated as the 7th positional argument in bash scripts. Alternatively you could use !7ZIP! as this uses the already enabled DelayedExpansion. * Update setup.bat to use delayed variable expansion
1 parent 134d433 commit 7a251c5

1 file changed

Lines changed: 65 additions & 65 deletions

File tree

dev/windows/setup.bat

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ REM Run once to install all build dependencies
55
setlocal EnableDelayedExpansion
66
call "%~dp0common.bat"
77

8-
set "7ZIP=C:\Program Files\7-Zip\7z.exe"
9-
if not exist "%7ZIP%" (
8+
set "SEVENZIP=C:\Program Files\7-Zip\7z.exe"
9+
if not exist "!SEVENZIP!" (
1010
for /f "delims=" %%i in ('where 7z.exe 2^>nul') do (
11-
set "7ZIP=%%i"
11+
set "SEVENZIP=%%i"
1212
goto :found7zip
1313
)
1414
)
1515
:found7zip
1616

17-
if not exist "%DEPS_DIR%" mkdir "%DEPS_DIR%"
17+
if not exist "!DEPS_DIR!" mkdir "!DEPS_DIR!"
1818

1919
echo [1/14] Installing CMake...
2020
winget install --id Kitware.CMake --accept-package-agreements --accept-source-agreements --silent
@@ -50,49 +50,49 @@ echo [7/14] Installing Inno Setup...
5050
winget install --id JRSoftware.InnoSetup --accept-package-agreements --accept-source-agreements --silent
5151
if errorlevel 1 echo Warning: Inno Setup may already be installed
5252

53-
echo [8/14] Installing Qt %QT_VERSION%...
54-
if not exist "%DEPS_DIR%\qt\%QT_VERSION%\msvc2022_64" (
55-
pushd "%DEPS_DIR%"
56-
aqt install-qt windows desktop %QT_VERSION% win64_msvc2022_64 -m qtwebengine qtwebchannel qtpositioning -O "qt"
53+
echo [8/14] Installing Qt !QT_VERSION!...
54+
if not exist "!DEPS_DIR!\qt\!QT_VERSION!\msvc2022_64" (
55+
pushd "!DEPS_DIR!"
56+
aqt install-qt windows desktop !QT_VERSION! win64_msvc2022_64 -m qtwebengine qtwebchannel qtpositioning -O "qt"
5757
popd
5858
) else (
5959
echo Qt already installed, skipping
6060
)
6161

6262
echo [9/14] Downloading libmpv AVX2...
63-
if not exist "%DEPS_DIR%\mpv\libmpv-2.dll" (
63+
if not exist "!DEPS_DIR!\mpv\libmpv-2.dll" (
6464
echo Downloading libmpv...
65-
if exist "%DEPS_DIR%\mpv" rmdir /s /q "%DEPS_DIR%\mpv"
66-
if exist "%DEPS_DIR%\mpv_tmp" rmdir /s /q "%DEPS_DIR%\mpv_tmp"
67-
curl -L "https://github.com/shinchiro/mpv-winbuild-cmake/releases/download/%MPV_RELEASE%/mpv-dev-x86_64-v3-%MPV_VERSION%.7z" -o "%DEPS_DIR%\mpv.7z"
65+
if exist "!DEPS_DIR!\mpv" rmdir /s /q "!DEPS_DIR!\mpv"
66+
if exist "!DEPS_DIR!\mpv_tmp" rmdir /s /q "!DEPS_DIR!\mpv_tmp"
67+
curl -L "https://github.com/shinchiro/mpv-winbuild-cmake/releases/download/!MPV_RELEASE!/mpv-dev-x86_64-v3-!MPV_VERSION!.7z" -o "!DEPS_DIR!\mpv.7z"
6868
if errorlevel 1 (
6969
echo ERROR: Failed to download libmpv
7070
) else (
71-
if not exist "%7ZIP%" (
71+
if not exist "!SEVENZIP!" (
7272
echo ERROR: 7-Zip not found. Please install 7-Zip and re-run setup.
7373
) else (
74-
"%7ZIP%" x "%DEPS_DIR%\mpv.7z" -o"%DEPS_DIR%\mpv_tmp" -y
74+
"!SEVENZIP!" x "!DEPS_DIR!\mpv.7z" -o"!DEPS_DIR!\mpv_tmp" -y
7575
if errorlevel 1 (
7676
echo ERROR: Failed to extract libmpv archive
7777
) else (
78-
set "MPV_SRC=%DEPS_DIR%\mpv_tmp"
79-
if not exist "%MPV_SRC%\libmpv-2.dll" (
80-
for /d %%D in ("%DEPS_DIR%\mpv_tmp\*") do (
78+
set "MPV_SRC=!DEPS_DIR!\mpv_tmp"
79+
if not exist "!MPV_SRC!\libmpv-2.dll" (
80+
for /d %%D in ("!DEPS_DIR!\mpv_tmp\*") do (
8181
if exist "%%~fD\libmpv-2.dll" set "MPV_SRC=%%~fD"
8282
)
8383
)
84-
if exist "%MPV_SRC%\libmpv-2.dll" (
85-
mkdir "%DEPS_DIR%\mpv"
86-
if exist "%MPV_SRC%\include" xcopy /e /i /y "%MPV_SRC%\include" "%DEPS_DIR%\mpv\include\" >nul
87-
move /y "%MPV_SRC%\libmpv-2.dll" "%DEPS_DIR%\mpv\" >nul
88-
if exist "%MPV_SRC%\libmpv.dll.a" move /y "%MPV_SRC%\libmpv.dll.a" "%DEPS_DIR%\mpv\" >nul
89-
if exist "%MPV_SRC%\libmpv-2.dll.lib" move /y "%MPV_SRC%\libmpv-2.dll.lib" "%DEPS_DIR%\mpv\" >nul
84+
if exist "!MPV_SRC!\libmpv-2.dll" (
85+
mkdir "!DEPS_DIR!\mpv"
86+
if exist "!MPV_SRC!\include" xcopy /e /i /y "!MPV_SRC!\include" "!DEPS_DIR!\mpv\include\" >nul
87+
move /y "!MPV_SRC!\libmpv-2.dll" "!DEPS_DIR!\mpv\" >nul
88+
if exist "!MPV_SRC!\libmpv.dll.a" move /y "!MPV_SRC!\libmpv.dll.a" "!DEPS_DIR!\mpv\" >nul
89+
if exist "!MPV_SRC!\libmpv-2.dll.lib" move /y "!MPV_SRC!\libmpv-2.dll.lib" "!DEPS_DIR!\mpv\" >nul
9090
) else (
9191
echo ERROR: libmpv-2.dll not found in extracted archive
9292
)
93-
rmdir /s /q "%DEPS_DIR%\mpv_tmp"
94-
del "%DEPS_DIR%\mpv.7z"
95-
echo libmpv extracted to %DEPS_DIR%\mpv
93+
rmdir /s /q "!DEPS_DIR!\mpv_tmp"
94+
del "!DEPS_DIR!\mpv.7z"
95+
echo libmpv extracted to !DEPS_DIR!\mpv
9696
)
9797
)
9898
)
@@ -101,35 +101,35 @@ if not exist "%DEPS_DIR%\mpv\libmpv-2.dll" (
101101
)
102102

103103
echo [10/14] Downloading libmpv fallback (non-AVX2)...
104-
if not exist "%DEPS_DIR%\mpv-fallback\libmpv-2.dll" (
105-
if exist "%DEPS_DIR%\mpv-fallback-tmp" rmdir /s /q "%DEPS_DIR%\mpv-fallback-tmp"
106-
curl -L "https://github.com/shinchiro/mpv-winbuild-cmake/releases/download/%MPV_RELEASE%/mpv-dev-x86_64-%MPV_VERSION%.7z" -o "%DEPS_DIR%\mpv-fallback.7z"
104+
if not exist "!DEPS_DIR!\mpv-fallback\libmpv-2.dll" (
105+
if exist "!DEPS_DIR!\mpv-fallback-tmp" rmdir /s /q "!DEPS_DIR!\mpv-fallback-tmp"
106+
curl -L "https://github.com/shinchiro/mpv-winbuild-cmake/releases/download/!MPV_RELEASE!/mpv-dev-x86_64-!MPV_VERSION!.7z" -o "!DEPS_DIR!\mpv-fallback.7z"
107107
if errorlevel 1 (
108108
echo ERROR: Failed to download libmpv fallback
109109
) else (
110-
if not exist "%7ZIP%" (
110+
if not exist "!SEVENZIP!" (
111111
echo ERROR: 7-Zip not found. Please install 7-Zip and re-run setup.
112112
) else (
113-
"%7ZIP%" x "%DEPS_DIR%\mpv-fallback.7z" -o"%DEPS_DIR%\mpv-fallback-tmp" -y
113+
"!SEVENZIP!" x "!DEPS_DIR!\mpv-fallback.7z" -o"!DEPS_DIR!\mpv-fallback-tmp" -y
114114
if errorlevel 1 (
115115
echo ERROR: Failed to extract libmpv fallback archive
116116
) else (
117-
set "MPV_FALLBACK_SRC=%DEPS_DIR%\mpv-fallback-tmp"
118-
if not exist "%MPV_FALLBACK_SRC%\libmpv-2.dll" (
119-
for /d %%D in ("%DEPS_DIR%\mpv-fallback-tmp\*") do (
117+
set "MPV_FALLBACK_SRC=!DEPS_DIR!\mpv-fallback-tmp"
118+
if not exist "!MPV_FALLBACK_SRC!\libmpv-2.dll" (
119+
for /d %%D in ("!DEPS_DIR!\mpv-fallback-tmp\*") do (
120120
if exist "%%~fD\libmpv-2.dll" set "MPV_FALLBACK_SRC=%%~fD"
121121
)
122122
)
123-
mkdir "%DEPS_DIR%\mpv-fallback"
124-
if exist "%MPV_FALLBACK_SRC%\libmpv-2.dll" (
125-
move /y "%MPV_FALLBACK_SRC%\libmpv-2.dll" "%DEPS_DIR%\mpv-fallback\" >nul
126-
if exist "%MPV_FALLBACK_SRC%\libmpv.dll.a" move /y "%MPV_FALLBACK_SRC%\libmpv.dll.a" "%DEPS_DIR%\mpv-fallback\" >nul
123+
mkdir "!DEPS_DIR!\mpv-fallback"
124+
if exist "!MPV_FALLBACK_SRC!\libmpv-2.dll" (
125+
move /y "!MPV_FALLBACK_SRC!\libmpv-2.dll" "!DEPS_DIR!\mpv-fallback\" >nul
126+
if exist "!MPV_FALLBACK_SRC!\libmpv.dll.a" move /y "!MPV_FALLBACK_SRC!\libmpv.dll.a" "!DEPS_DIR!\mpv-fallback\" >nul
127127
) else (
128128
echo ERROR: libmpv-2.dll not found in fallback archive
129129
)
130-
rmdir /s /q "%DEPS_DIR%\mpv-fallback-tmp"
131-
del "%DEPS_DIR%\mpv-fallback.7z"
132-
echo libmpv fallback extracted to %DEPS_DIR%\mpv-fallback
130+
rmdir /s /q "!DEPS_DIR!\mpv-fallback-tmp"
131+
del "!DEPS_DIR!\mpv-fallback.7z"
132+
echo libmpv fallback extracted to !DEPS_DIR!\mpv-fallback
133133
)
134134
)
135135
)
@@ -138,38 +138,38 @@ if not exist "%DEPS_DIR%\mpv-fallback\libmpv-2.dll" (
138138
)
139139

140140
echo [11/14] Downloading VCRedist and WiX tools...
141-
if not exist "%DEPS_DIR%\vc_redist.x64.exe" (
141+
if not exist "!DEPS_DIR!\vc_redist.x64.exe" (
142142
echo Downloading vc_redist.x64.exe...
143-
curl -L -o "%DEPS_DIR%\vc_redist.x64.exe" https://aka.ms/vs/17/release/vc_redist.x64.exe
143+
curl -L -o "!DEPS_DIR!\vc_redist.x64.exe" https://aka.ms/vs/17/release/vc_redist.x64.exe
144144
)
145-
if not exist "%DEPS_DIR%\wix" (
145+
if not exist "!DEPS_DIR!\wix" (
146146
echo Downloading WiX tools...
147-
curl -L -o "%DEPS_DIR%\wix.zip" https://github.com/wixtoolset/wix3/releases/download/wix3111rtm/wix311-binaries.zip
148-
mkdir "%DEPS_DIR%\wix"
149-
%7ZIP% x -y "%DEPS_DIR%\wix.zip" -o"%DEPS_DIR%\wix"
150-
del "%DEPS_DIR%\wix.zip"
147+
curl -L -o "!DEPS_DIR!\wix.zip" https://github.com/wixtoolset/wix3/releases/download/wix3111rtm/wix311-binaries.zip
148+
mkdir "!DEPS_DIR!\wix"
149+
!SEVENZIP! x -y "!DEPS_DIR!\wix.zip" -o"!DEPS_DIR!\wix"
150+
del "!DEPS_DIR!\wix.zip"
151151
)
152152

153153
echo [12/14] Extracting VC runtime DLLs...
154-
if not exist "%DEPS_DIR%\vcruntime" (
154+
if not exist "!DEPS_DIR!\vcruntime" (
155155
echo Extracting VCRedist with dark.exe...
156-
mkdir "%DEPS_DIR%\vcruntime"
157-
"%DEPS_DIR%\wix\dark.exe" -nologo "%DEPS_DIR%\vc_redist.x64.exe" -x "%DEPS_DIR%\vcredist_tmp"
156+
mkdir "!DEPS_DIR!\vcruntime"
157+
"!DEPS_DIR!\wix\dark.exe" -nologo "!DEPS_DIR!\vc_redist.x64.exe" -x "!DEPS_DIR!\vcredist_tmp"
158158
echo Extracting runtime CABs...
159-
expand.exe -F:* "%DEPS_DIR%\vcredist_tmp\AttachedContainer\packages\vcRuntimeMinimum_amd64\cab1.cab" "%DEPS_DIR%\vcruntime"
160-
expand.exe -F:* "%DEPS_DIR%\vcredist_tmp\AttachedContainer\packages\vcRuntimeAdditional_amd64\cab1.cab" "%DEPS_DIR%\vcruntime"
159+
expand.exe -F:* "!DEPS_DIR!\vcredist_tmp\AttachedContainer\packages\vcRuntimeMinimum_amd64\cab1.cab" "!DEPS_DIR!\vcruntime"
160+
expand.exe -F:* "!DEPS_DIR!\vcredist_tmp\AttachedContainer\packages\vcRuntimeAdditional_amd64\cab1.cab" "!DEPS_DIR!\vcruntime"
161161
REM Rename files from *_amd64 to *.dll
162-
for %%f in ("%DEPS_DIR%\vcruntime\*_amd64") do (
162+
for %%f in ("!DEPS_DIR!\vcruntime\*_amd64") do (
163163
set "name=%%~nf"
164164
ren "%%f" "!name:_amd64=!.dll"
165165
)
166-
rd /s /q "%DEPS_DIR%\vcredist_tmp"
167-
echo VC runtime DLLs extracted to %DEPS_DIR%\vcruntime
166+
rd /s /q "!DEPS_DIR!\vcredist_tmp"
167+
echo VC runtime DLLs extracted to !DEPS_DIR!\vcruntime
168168
)
169169

170170
echo [13/14] Generating mpv import library...
171-
if exist "%DEPS_DIR%\mpv\libmpv-2.dll" (
172-
if not exist "%DEPS_DIR%\mpv\libmpv-2.dll.lib" (
171+
if exist "!DEPS_DIR!\mpv\libmpv-2.dll" (
172+
if not exist "!DEPS_DIR!\mpv\libmpv-2.dll.lib" (
173173
REM Find Visual Studio
174174
set "VCVARS="
175175
for %%v in (
@@ -184,13 +184,13 @@ if exist "%DEPS_DIR%\mpv\libmpv-2.dll" (
184184
echo Using Visual Studio: !VCVARS!
185185
call "!VCVARS!" >nul 2>&1
186186
echo Generating import library...
187-
echo LIBRARY libmpv-2.dll > "%DEPS_DIR%\mpv\mpv.def"
188-
echo EXPORTS >> "%DEPS_DIR%\mpv\mpv.def"
189-
for /f "skip=19 tokens=4" %%a in ('dumpbin /exports "%DEPS_DIR%\mpv\libmpv-2.dll"') do (
190-
if not "%%a"=="" echo %%a >> "%DEPS_DIR%\mpv\mpv.def"
187+
echo LIBRARY libmpv-2.dll > "!DEPS_DIR!\mpv\mpv.def"
188+
echo EXPORTS >> "!DEPS_DIR!\mpv\mpv.def"
189+
for /f "skip=19 tokens=4" %%a in ('dumpbin /exports "!DEPS_DIR!\mpv\libmpv-2.dll"') do (
190+
if not "%%a"=="" echo %%a >> "!DEPS_DIR!\mpv\mpv.def"
191191
)
192-
lib /def:"%DEPS_DIR%\mpv\mpv.def" /out:"%DEPS_DIR%\mpv\libmpv-2.dll.lib" /MACHINE:X64
193-
echo Import library created: %DEPS_DIR%\mpv\libmpv-2.dll.lib
192+
lib /def:"!DEPS_DIR!\mpv\mpv.def" /out:"!DEPS_DIR!\mpv\libmpv-2.dll.lib" /MACHINE:X64
193+
echo Import library created: !DEPS_DIR!\mpv\libmpv-2.dll.lib
194194
) else (
195195
echo WARNING: Visual Studio not found. Import library will be generated during build.
196196
)
@@ -200,7 +200,7 @@ if exist "%DEPS_DIR%\mpv\libmpv-2.dll" (
200200
)
201201

202202
echo [14/14] Generating CMakePresets.json...
203-
powershell -Command "(Get-Content '%SCRIPT_DIR%..\CMakePresets.json.in' -Raw) -replace '@QT_VERSION@','%QT_VERSION%' -replace '@BREW_PREFIX@','' | Set-Content '%PROJECT_ROOT%\CMakePresets.json' -NoNewline"
203+
powershell -Command "(Get-Content '!SCRIPT_DIR!..\CMakePresets.json.in' -Raw) -replace '@QT_VERSION@','!QT_VERSION!' -replace '@BREW_PREFIX@','' | Set-Content '!PROJECT_ROOT!\CMakePresets.json' -NoNewline"
204204

205205
echo.
206206
echo Setup complete. Restart terminal to refresh PATH, then run build.bat

0 commit comments

Comments
 (0)