1- @ ECHO OFF
2- SETLOCAL EnableDelayedExpansion
3-
4- SET UPSTREAMURL = https://github.com/ShiftMediaProject
5- SET DEPENDENCIES = ( ^
6- libgcrypt, ^
7- zlib ^
8- )
9-
10- REM Get passed in list of dependencies to skip
11- SET PASSDEPENDENCIES = %~1
12-
13- REM Check if git is installed and available
14- git status > NUL 2 >& 1
15- IF %ERRORLEVEL% NEQ 0 (
16- ECHO A working copy of git was not found. To use this script you must first install git for windows.
17- EXIT /B 1
18- )
19-
20- SET CURRDIR = %~dp1
21-
22- cd ..\..
23- FOR %%I IN %DEPENDENCIES% DO (
24- ECHO !PASSDEPENDENCIES! | FINDSTR /C:" %%I " > NUL 2 >& 1 || (
25- CALL :cloneOrUpdateRepo " %%I " )
26- )
27- cd %CURRDIR% > NUL
28- GOTO exit
29-
30- REM Function to clone or update a repo
31- REM cloneOrUpdateRepo: RepoName
32- REM RepoName = Name of the repository
33- :cloneOrUpdateRepo
34- SET REPONAME = %~1
35- REM Check if the repo folder already exists
36- IF EXIST " %REPONAME% " (
37- ECHO %REPONAME% : Existing folder found. Checking for updates...
38- cd %REPONAME%
39- REM Check if any updates are available
40- FOR /f %%J IN ('git rev-parse HEAD') do set CURRHEAD = %%J
41- FOR /f %%J IN ('git ls-remote origin HEAD') do set ORIGHEAD = %%J
42- IF " !CURRHEAD! " == " !ORIGHEAD! " (
43- ECHO %REPONAME% : Repository up to date.
44- ) ELSE (
45- REM Stash any uncommited changes then update from origin
46- ECHO %REPONAME% : Updates available. Updating repository...
47- git checkout master --quiet
48- git stash --quiet
49- git pull origin master --quiet -ff
50- git stash pop --quiet
51- )
52- cd ..\
53- ) ELSE (
54- ECHO %REPONAME% : Existing folder not found. Cloning repository...
55- REM Clone from the origin repo
56- SET REPOURL = %UPSTREAMURL% /%REPONAME% .git
57- git clone !REPOURL! --quiet
58- REM Initialise autocrlf options to fix cross platform interoperation
59- REM Once updated the repo needs to be reset to correct the local line endings
60- cd %REPONAME%
61- git config --local core.autocrlf false
62- git rm --cached -r . --quiet
63- git reset --hard --quiet
64- cd ..\
65- )
66- REM Add current repo to list of already passed dependencies
67- SET PASSDEPENDENCIES = %PASSDEPENDENCIES% %REPONAME%
68- REM Check if the repo itself has required dependencies
69- IF EXIST " %REPONAME% \SMP\project_get_dependencies.bat" (
70- ECHO %REPONAME% : Found additional dependencies...
71- ECHO .
72- cd %REPONAME% \SMP
73- project_get_dependencies.bat " !PASSDEPENDENCIES! " || GOTO exitOnError
74- cd ..\..
75- )
76- ECHO .
77- EXIT /B %ERRORLEVEL%
78-
79- :exitOnError
80- cd %CURRDIR%
81-
82- :exit
83- REM Return the passed dependency list
84- (
85- ENDLOCAL
86- SET PASSDEPENDENCIES = %PASSDEPENDENCIES%
87- )
88-
89- REM Check if this was laucnhed from an existing terminal or directly from .bat
90- REM If launched by executing the .bat then pause on completion
91- ECHO %CMDCMDLINE% | FINDSTR /L %COMSPEC% > NUL 2 >& 1
92- IF %ERRORLEVEL% == 0 IF " %~1 " == " " PAUSE
93-
1+ @ ECHO OFF
2+ SETLOCAL EnableDelayedExpansion
3+
4+ SET UPSTREAMURL = https://github.com/ShiftMediaProject
5+ SET DEPENDENCIES = ( ^
6+ libgcrypt, ^
7+ zlib ^
8+ )
9+
10+ REM Get passed in list of dependencies to skip
11+ SET PASSDEPENDENCIES = %~1
12+
13+ REM Check if git is installed and available
14+ IF " %MSVC_VER% " == " " (
15+ git status > NUL 2 >& 1
16+ IF %ERRORLEVEL% NEQ 0 (
17+ ECHO A working copy of git was not found. To use this script you must first install git for windows.
18+ EXIT /B 1
19+ )
20+ )
21+
22+ REM Store current directory and ensure working directory is the location of current .bat
23+ SET CURRDIR = %CD%
24+ cd %~dp0
25+
26+ cd ..\..
27+ FOR %%I IN %DEPENDENCIES% DO (
28+ ECHO !PASSDEPENDENCIES! | FINDSTR /C:" %%I " > NUL 2 >& 1 || (
29+ REM Check if MSVC_VER environment variable is set
30+ IF " %MSVC_VER% " == " " (
31+ CALL :cloneOrUpdateRepo " %%I "
32+ ) ELSE (
33+ CALL :downloadLibs " %%I "
34+ )
35+ )
36+ )
37+ cd %CURRDIR% > NUL
38+ GOTO exit
39+
40+ REM Function to clone or update a repo
41+ REM cloneOrUpdateRepo: RepoName
42+ REM RepoName = Name of the repository
43+ :cloneOrUpdateRepo
44+ SET REPONAME = %~1
45+ REM Check if the repo folder already exists
46+ IF EXIST " %REPONAME% " (
47+ ECHO %REPONAME% : Existing folder found. Checking for updates...
48+ cd %REPONAME%
49+ REM Check if any updates are available
50+ FOR /f %%J IN ('git rev-parse HEAD') do set CURRHEAD = %%J
51+ FOR /f %%J IN ('git ls-remote origin HEAD') do set ORIGHEAD = %%J
52+ IF " !CURRHEAD! " == " !ORIGHEAD! " (
53+ ECHO %REPONAME% : Repository up to date.
54+ ) ELSE (
55+ REM Stash any uncommited changes then update from origin
56+ ECHO %REPONAME% : Updates available. Updating repository...
57+ git checkout master --quiet
58+ git stash --quiet
59+ git pull origin master --quiet -ff
60+ git stash pop --quiet
61+ )
62+ cd ..\
63+ ) ELSE (
64+ ECHO %REPONAME% : Existing folder not found. Cloning repository...
65+ REM Clone from the origin repo
66+ SET REPOURL = %UPSTREAMURL% /%REPONAME% .git
67+ git clone !REPOURL! --quiet
68+ REM Initialise autocrlf options to fix cross platform interoperation
69+ REM Once updated the repo needs to be reset to correct the local line endings
70+ cd %REPONAME%
71+ git config --local core.autocrlf false
72+ git rm --cached -r . --quiet
73+ git reset --hard --quiet
74+ cd ..\
75+ )
76+ REM Add current repo to list of already passed dependencies
77+ SET PASSDEPENDENCIES = %PASSDEPENDENCIES% %REPONAME%
78+ REM Check if the repo itself has required dependencies
79+ IF EXIST " %REPONAME% \SMP\project_get_dependencies.bat" (
80+ ECHO %REPONAME% : Found additional dependencies...
81+ ECHO .
82+ cd %REPONAME% \SMP
83+ project_get_dependencies.bat " !PASSDEPENDENCIES! " || GOTO exitOnError
84+ cd ..\..
85+ )
86+ ECHO .
87+ EXIT /B %ERRORLEVEL%
88+
89+ REM Function to download existing prebuilt libraries
90+ REM downloadLibs: RepoName
91+ REM RepoName = Name of the repository
92+ :downloadLibs
93+ SET REPONAME = %~1
94+ REM Get latest release
95+ SET UPSTREAMAPIURL = %UPSTREAMURL:github.com =api.github.com/repos %
96+ powershell -nologo -noprofile -command " try { Invoke-RestMethod -Uri %UPSTREAMAPIURL% /%REPONAME% /releases/latest > latest.json } catch {exit 1}"
97+ IF NOT %ERRORLEVEL% == 0 ( ECHO Failed getting latest %REPONAME% release & GOTO exitOnError )
98+ REM Get tag for latest release
99+ FOR /F " tokens=* USEBACKQ" %%F IN (`TYPE latest.json ^ | FINDSTR /B " tag_name" `) DO SET TAG = %%F
100+ FOR /F " tokens=2 delims=: " %%F in (" %TAG% " ) DO SET TAG = %%F
101+ IF " %TAG% " == " " ( ECHO Failed getting latest %REPONAME% release tag information & GOTO exitOnError )
102+ REM Get download name of latest release
103+ FOR /F " tokens=* USEBACKQ" %%F IN (`TYPE latest.json ^ | FINDSTR " name=" `) DO SET LIBNAME = %%F
104+ SET LIBNAME = %LIBNAME:*name =%
105+ FOR /F " tokens=1 delims=_" %%F in (" %LIBNAME:~1 % " ) DO SET LIBNAME = %%F
106+ IF " %LIBNAME% " == " " ( ECHO Failed getting latest %REPONAME% release name information & GOTO exitOnError )
107+ DEL /F /Q latest.json
108+ REM Get the download location for the required tag
109+ SET DLURL = %UPSTREAMURL% /%REPONAME% /releases/download/%TAG% /%LIBNAME% _%TAG% _msvc%MSVC_VER% .zip
110+ REM Download a pre-built archive and extract
111+ SET PREBUILTDIR = prebuilt
112+ MKDIR %PREBUILTDIR% > NUL 2 >& 1
113+ powershell -nologo -noprofile -command " try { (New-Object Net.WebClient).DownloadFile('%DLURL% ', '%PREBUILTDIR% \temp.zip') } catch {exit 1}"
114+ IF NOT %ERRORLEVEL% == 0 ( ECHO Failed downloading %DLURL% & GOTO exitOnError )
115+ powershell -nologo -noprofile -command " try { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%PREBUILTDIR% \temp.zip', '%PREBUILTDIR% '); } catch [System.IO.IOException] {exit 0} catch {exit 1}"
116+ IF NOT %ERRORLEVEL% == 0 ( ECHO Failed extracting downloaded archive & GOTO exitOnError )
117+ DEL /F /Q %PREBUILTDIR% \\temp.zip
118+ EXIT /B %ERRORLEVEL%
119+
120+ :exitOnError
121+ cd %CURRDIR%
122+
123+ :exit
124+ REM Directly exit if an AppVeyor build
125+ IF NOT " %APPVEYOR% " == " " (
126+ GOTO return
127+ )
128+ REM Return the passed dependency list
129+ (
130+ ENDLOCAL
131+ SET PASSDEPENDENCIES = %PASSDEPENDENCIES%
132+ )
133+
134+ REM Check if this was launched from an existing terminal or directly from .bat
135+ REM If launched by executing the .bat then pause on completion
136+ ECHO %CMDCMDLINE% | FINDSTR /L %COMSPEC% > NUL 2 >& 1
137+ IF %ERRORLEVEL% == 0 IF " %~1 " == " " PAUSE
138+
139+ :return
94140EXIT /B 0
0 commit comments