summaryrefslogtreecommitdiffstats
path: root/build/windows
diff options
context:
space:
mode:
authorJosep Maria AntolĂ­n Segura <josepma@gmail.com>2020-01-01 19:37:37 +0100
committerGitHub <noreply@github.com>2020-01-01 19:37:37 +0100
commit2c9528ddedbe944023ab733178af8b11238f1480 (patch)
tree3a45a8f29575161f2b37a2c8d3f97c6cf8601d5d /build/windows
parent8a0dad4da6c5318cf620bb2aa2c7f0ef118e16a3 (diff)
Use powershell only if it will work
Reworked the script so that it detects the version of powershell and knows if it can use it as a true fallback of curl and 7zip for download and extract. Truth is: Windows 8/powershell 3 is required for download fallback and windows 10/powershell 5 is required for unzip fallback. So, in the end, plain Windows 7 still requires manual download and unzip.
Diffstat (limited to 'build/windows')
-rw-r--r--build/windows/install_buildenv.bat102
1 files changed, 65 insertions, 37 deletions
diff --git a/build/windows/install_buildenv.bat b/build/windows/install_buildenv.bat
index 8ceefc64b5..a797e88c82 100644
--- a/build/windows/install_buildenv.bat
+++ b/build/windows/install_buildenv.bat
@@ -10,55 +10,83 @@ SET WINLIB_NAME=%2
REM The local directory to cache build environments in.
SET WINLIBS_PATH=%3
-IF NOT EXIST "%WINLIBS_PATH%\%WINLIB_NAME%" (
+IF EXIST "%WINLIBS_PATH%\%WINLIB_NAME%" (
+ echo %WINLIB_NAME% already exists at %WINLIBS_PATH%
+ REM TODO(XXX) check fingerprint on build environment?
+ ENDLOCAL && EXIT /B 0
+)
+
- REM Install build env base dir
- IF NOT EXIST "%WINLIBS_PATH%" MKDIR "%WINLIBS_PATH%"
+REM Install build env base dir
+IF NOT EXIST "%WINLIBS_PATH%" MKDIR "%WINLIBS_PATH%"
- where /q 7za
+where /q 7za
+IF ERRORLEVEL 1 (
+ where /q 7z
IF ERRORLEVEL 1 (
- where /q 7z
- if ERRORLEVEL 1 (
- where /q powershell
- if ERRORLEVEL 1 (
- echo Could not find 7z or 7za on the path, and powershell is not available.
- echo Either install http://7-zip.org and retry
- echo or download %BASEURL%/%WINLIB_NAME%.zip
- echo yourself and unzip it at %WINLIBS_PATH%
- ENDLOCAL && EXIT /b 1
- ) else (
- set POWERSHELL=powershell
- )
+ REM In case it is not present in PATH
+ IF EXIST "%PROGRAMFILES%\7-zip\7z.exe" (
+ set "ZIP=%PROGRAMFILES%\7-zip\7z.exe"
) else (
- set ZIP=7z
+ call :get_powershell_version
+ IF !POWERSHELL! LSS 5 (
+ echo Could not find 7z or 7za on the path, and cannot use powershell ^(version !POWERSHELL!^)
+ echo Either install http://7-zip.org ^(and add it to the PATH^) and retry
+ echo or download %BASEURL%/%WINLIB_NAME%.zip
+ echo yourself and unzip it at %WINLIBS_PATH%
+ ENDLOCAL && EXIT /b 1
+ )
)
) else (
- set ZIP=7za
+ set ZIP=7z
)
+) else (
+ set ZIP=7za
+)
- echo Installing winlib %WINLIB_NAME%.
- CD "%WINLIBS_PATH%"
- echo ..Downloading %WINLIB_NAME%.zip
- where /q curl
- IF ERRORLEVEL 1 (
- echo curl not found. Please download %WINLIB_NAME%.zip from %BASEURL%/ and unzip it yourself at %WINLIBS_PATH%
+echo Installing winlib %WINLIB_NAME%.
+CD "%WINLIBS_PATH%"
+echo ..Downloading %WINLIB_NAME%.zip
+where /q curl
+IF ERRORLEVEL 1 (
+ call :get_powershell_version
+ IF !POWERSHELL! LSS 3 (
+ echo curl not found and cannot use powershell ^(version !POWERSHELL!^)
+ echo Please download %WINLIB_NAME%.zip
+ echo from %BASEURL%/
+ echo and unzip it yourself at %WINLIBS_PATH%
ENDLOCAL && EXIT /b 1
- )
- curl -fsS -L -o %WINLIB_NAME%.zip %BASEURL%/%WINLIB_NAME%.zip
- IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
- REM TODO(XXX) check fingerprint on zip file.
- echo ..unzipping %WINLIB_NAME%.zip
- IF "!POWERSHELL!" == "powershell" (
- powershell -Command "& {Expand-Archive \"%WINLIBS_PATH%/%WINLIB_NAME%.zip\" \"%WINLIBS_PATH%\\\"}"
- IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
- ) ELSE (
- !ZIP! x %WINLIB_NAME%.zip
+ ) else (
+ powershell -Command "& {Invoke-WebRequest -Uri %BASEURL%/%WINLIB_NAME%.zip -OutFile \"%WINLIBS_PATH%/%WINLIB_NAME%.zip\"}"
IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
)
- DEL %WINLIB_NAME%.zip
) else (
- echo %WINLIB_NAME% already exists at %WINLIBS_PATH%
- REM TODO(XXX) check fingerprint on build environment?
+ curl -fsS -L -o %WINLIB_NAME%.zip %BASEURL%/%WINLIB_NAME%.zip
+ IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
)
+REM TODO(XXX) check fingerprint on zip file.
+
+
+echo ..unzipping %WINLIB_NAME%.zip
+IF "!ZIP!" NEQ "" (
+ "!ZIP!" x %WINLIB_NAME%.zip
+ IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
+) ELSE (
+ powershell -Command "& {Expand-Archive \"%WINLIBS_PATH%/%WINLIB_NAME%.zip\" \"%WINLIBS_PATH%\\\"}"
+ IF ERRORLEVEL 1 ENDLOCAL && EXIT /b 1
+)
+DEL %WINLIB_NAME%.zip
ENDLOCAL
+EXIT /B 0
+
+
+:get_powershell_version
+ where /q powershell
+ if ERRORLEVEL 1 (
+ set POWERSHELL=0
+ ) else (
+ REM DETECT powershell major version
+ FOR /F "tokens=* USEBACKQ" %%F IN (`powershell -Command "& {$PSVersionTable.PSVersion.Major}"`) DO ( set POWERSHELL=%%F )
+ )
+EXIT /B 1