Merge pull request #4253 from jamesqo/faulty-trues
[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 =========================================================================================
39 REM ===
40 REM === Check if dotnet CLI and necessary directories exist
41 REM ===
42 REM =========================================================================================
43
44 set __DotNetToolDir=%__ThisScriptPath%..\Tools
45 set __DotNetCmd=%__DotNetToolDir%\dotnetcli\dotnet.exe 
46 set __PackageDir=%__ThisScriptPath%..\Packages
47 set __TmpDir=%Temp%\coreclr_gcstress_%RANDOM%
48
49 REM Check if donet cli exists
50 if not exist "%__DotNetToolDir%" (
51     echo Directory containing dotnet CLI does not exist: %__DotNetToolDir%
52     goto Fail
53 )
54 if not exist "%__DotNetCmd%" (
55     echo dotnet.exe does not exist: %__DotNetCmd%
56     goto Fail
57 )
58
59 REM Create directories needed
60 if not exist "%__PackageDir%" md "%__PackageDir%"
61 if not exist "%__OutputDir%" md "%__OutputDir%"
62
63 REM Check and create a temp directory
64 if exist "%__TmpDir%" (
65     rmdir /S /Q %__TmpDir%
66 )
67 mkdir %__TmpDir%
68
69 REM Project.json path
70 set __JasonFilePath=%__TmpDir%\project.json
71
72 REM =========================================================================================
73 REM ===
74 REM === Download packages
75 REM ===
76 REM =========================================================================================
77
78 REM Write dependency information to project.json
79 echo { ^
80     "dependencies": { ^
81     "runtime.win7-%__Arch%.Microsoft.NETCore.CoreDisTools": "1.0.1-prerelease-00001" ^
82     }, ^
83     "frameworks": { "dnxcore50": { } } ^
84     } > "%__JasonFilePath%"
85
86 echo Jason file: %__JasonFilePath%
87 type "%__JasonFilePath%"
88
89 REM Download the package
90 echo Downloading CoreDisTools package
91 set DOTNETCMD="%__DotNetCmd%" restore "%__JasonFilePath%" --source https://dotnet.myget.org/F/dotnet-core/ --packages "%__PackageDir%"
92 echo %DOTNETCMD%
93 call %DOTNETCMD%
94 if errorlevel 1 goto Fail
95
96 REM Get downloaded dll path
97 echo Locating coredistools.dll
98 FOR /F "delims=" %%i IN ('dir %__PackageDir%\coredistools.dll /b/s ^| findstr /R "runtime.win[0-9]*-%__Arch%"') DO set __LibPath=%%i
99 echo CoreDisTools library path: %__LibPath%
100 if not exist "%__LibPath%" (
101     echo Failed to locate the downloaded library: %__LibPath%
102     goto Fail
103 )
104
105 REM Copy library to output directory
106 echo Copy library: %__LibPath% to %__OutputDir%
107 copy /y "%__LibPath%" "%__OutputDir%"
108
109 REM Delete temporary files
110 if exist "%__TmpDir%" (
111     rmdir /S /Q "%__TmpDir%"
112 )
113
114 exit /b 0
115
116 :Fail
117 if exist "%__TmpDir%" (
118     rmdir /S /Q "%__TmpDir%"
119 )
120 exit /b 1
121
122 REM =========================================================================================
123 REM ===
124 REM === Helper routines
125 REM ===
126 REM =========================================================================================
127
128 :Usage
129 echo.
130 echo Download coredistool for GC stress testing
131 echo.
132 echo Usage:
133 echo     %__ThisScriptShort% /arch ^<TargetArch^> /outputdir ^<coredistools_lib_install_path^>
134 echo.
135 exit /b 1