Merge pull request #6791 from dagood/upgrade-xunit-runner
[platform/upstream/coreclr.git] / tests / setup-runtime-dependencies.cmd
1 @if not defined __echo @echo off
2 setlocal
3
4 set __ThisScriptShort=%0
5 set __ThisScriptFull=%~f0
6 set __ThisScriptPath=%~dp0
7
8 REM =========================================================================================
9 REM ===
10 REM === Parse arguments
11 REM ===
12 REM =========================================================================================
13
14 set __OutputDir=
15 set __Arch= 
16
17 :Arg_Loop
18 if "%1" == "" goto ArgsDone
19
20 if /i "%1" == "/?"    goto Usage
21 if /i "%1" == "-?"    goto Usage
22 if /i "%1" == "/h"    goto Usage
23 if /i "%1" == "-h"    goto Usage
24 if /i "%1" == "/help" goto Usage
25 if /i "%1" == "-help" goto Usage
26
27 if /i "%1" == "/arch"             (set __Arch=%2&shift&shift&goto Arg_Loop) 
28 if /i "%1" == "/outputdir"        (set __OutputDir=%2&shift&shift&goto Arg_Loop)
29
30 echo Invalid command-line argument: %1
31 goto Usage
32
33 :ArgsDone
34
35 if not defined __OutputDir goto Usage
36 if not defined __Arch goto Usage 
37
38 REM Check if the platform is supported
39 if /i %__Arch% == "arm" (
40     echo No runtime dependencies for Arm32.
41     exit /b 0
42     )
43
44 REM =========================================================================================
45 REM ===
46 REM === Check if dotnet CLI and necessary directories exist
47 REM ===
48 REM =========================================================================================
49
50 set __DotNetToolDir=%__ThisScriptPath%..\Tools
51 set __DotNetCmd=%__DotNetToolDir%\dotnetcli\dotnet.exe 
52 set __PackageDir=%__ThisScriptPath%..\Packages
53 set __TmpDir=%Temp%\coreclr_gcstress_%RANDOM%
54
55 REM Check if dotnet cli exists
56 if not exist "%__DotNetToolDir%" (
57     echo Directory containing dotnet CLI does not exist: %__DotNetToolDir%
58     goto Fail
59 )
60 if not exist "%__DotNetCmd%" (
61     echo dotnet.exe does not exist: %__DotNetCmd%
62     goto Fail
63 )
64
65 REM Create directories needed
66 if not exist "%__PackageDir%" md "%__PackageDir%"
67 if not exist "%__OutputDir%" md "%__OutputDir%"
68
69 REM Check and create a temp directory
70 if exist "%__TmpDir%" (
71     rmdir /S /Q %__TmpDir%
72 )
73 mkdir %__TmpDir%
74
75 REM Project.json path
76 set __JsonFilePath=%__TmpDir%\project.json
77
78 REM =========================================================================================
79 REM ===
80 REM === Download packages
81 REM ===
82 REM =========================================================================================
83
84 REM Write dependency information to project.json
85 echo { ^
86     "dependencies": { ^
87     "runtime.win7-%__Arch%.Microsoft.NETCore.CoreDisTools": "1.0.1-prerelease-*" ^
88     }, ^
89     "frameworks": { "dnxcore50": { } } ^
90     } > "%__JsonFilePath%"
91
92 echo JSON file: %__JsonFilePath%
93 type "%__JsonFilePath%"
94
95 REM Download the package
96 echo Downloading CoreDisTools package
97 set DOTNETCMD="%__DotNetCmd%" restore "%__JsonFilePath%" --source https://dotnet.myget.org/F/dotnet-core/ --packages "%__PackageDir%"
98 echo %DOTNETCMD%
99 call %DOTNETCMD%
100 if errorlevel 1 goto Fail
101
102 REM Get downloaded dll path
103 echo Locating coredistools.dll
104 FOR /F "delims=" %%i IN ('dir %__PackageDir%\coredistools.dll /b/s ^| findstr /R "runtime.win[0-9]*-%__Arch%"') DO set __LibPath=%%i
105 echo CoreDisTools library path: %__LibPath%
106 if not exist "%__LibPath%" (
107     echo Failed to locate the downloaded library: %__LibPath%
108     goto Fail
109 )
110
111 REM Copy library to output directory
112 echo Copy library: %__LibPath% to %__OutputDir%
113 copy /y "%__LibPath%" "%__OutputDir%"
114 if errorlevel 1 (
115     echo Failed to copy %__LibPath% to %__OutputDir%
116     goto Fail
117 )
118
119 REM Delete temporary files
120 if exist "%__TmpDir%" (
121     rmdir /S /Q "%__TmpDir%"
122 )
123
124 exit /b 0
125
126 :Fail
127 if exist "%__TmpDir%" (
128     rmdir /S /Q "%__TmpDir%"
129 )
130 exit /b 1
131
132 REM =========================================================================================
133 REM ===
134 REM === Helper routines
135 REM ===
136 REM =========================================================================================
137
138 :Usage
139 echo.
140 echo Download coredistools for GC stress testing
141 echo.
142 echo Usage:
143 echo     %__ThisScriptShort% /arch ^<TargetArch^> /outputdir ^<coredistools_lib_install_path^>
144 echo.
145 exit /b 1