Merge pull request #3960 from sejongoh/check_runtime_to_pull_coredistools
[platform/upstream/coreclr.git] / init-tools.cmd
1 @echo off
2 setlocal
3
4 REM Workaround https://github.com/dotnet/coreclr/issues/2153
5 set ComPlus_ReadyToRun=0
6
7 set INIT_TOOLS_LOG=%~dp0init-tools.log
8 set PACKAGES_DIR=%~dp0packages\
9 set TOOLRUNTIME_DIR=%~dp0Tools
10 set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
11 set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
12 if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://www.myget.org/F/dotnet-buildtools/
13 set /P BUILDTOOLS_VERSION=< %~dp0BuildToolsVersion.txt
14 set BUILD_TOOLS_PATH=%PACKAGES_DIR%Microsoft.DotNet.BuildTools\%BUILDTOOLS_VERSION%\lib\
15 set PROJECT_JSON_PATH=%TOOLRUNTIME_DIR%\%BUILDTOOLS_VERSION%
16 set PROJECT_JSON_FILE=%PROJECT_JSON_PATH%\project.json
17 set PROJECT_JSON_CONTENTS={ "dependencies": { "Microsoft.DotNet.BuildTools": "%BUILDTOOLS_VERSION%" , "Microsoft.DotNet.BuildTools.Coreclr": "1.0.4-prerelease"}, "frameworks": { "dnxcore50": { } } }
18 set BUILD_TOOLS_SEMAPHORE=%PROJECT_JSON_PATH%\init-tools.completed
19
20 :: if force option is specified then clean the tool runtime and build tools package directory to force it to get recreated
21 if [%1]==[force] (
22   if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
23   if exist "%PACKAGES_DIR%Microsoft.DotNet.BuildTools" rmdir /S /Q "%PACKAGES_DIR%Microsoft.DotNet.BuildTools"
24 )
25
26 :: If sempahore exists do nothing
27 if exist "%BUILD_TOOLS_SEMAPHORE%" (
28   echo Tools are already initialized.
29   goto :EOF
30 )
31
32 if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
33
34 :: Download Nuget.exe
35 if NOT exist "%PACKAGES_DIR%NuGet.exe" (
36   if NOT exist "%PACKAGES_DIR%" mkdir "%PACKAGES_DIR%"
37   powershell -NoProfile -ExecutionPolicy unrestricted -Command "(New-Object Net.WebClient).DownloadFile('https://www.nuget.org/nuget.exe', '%PACKAGES_DIR%NuGet.exe')
38 )
39
40 if NOT exist "%PROJECT_JSON_PATH%" mkdir "%PROJECT_JSON_PATH%"
41 echo %PROJECT_JSON_CONTENTS% > %PROJECT_JSON_FILE%
42 echo Running %0 > %INIT_TOOLS_LOG%
43
44 if exist "%DOTNET_CMD%" goto :afterdotnetrestore
45
46 echo Installing dotnet cli...
47 if NOT exist "%DOTNET_PATH%" mkdir "%DOTNET_PATH%"
48 set /p DOTNET_VERSION=< %~dp0DotnetCLIVersion.txt
49 set DOTNET_ZIP_NAME=dotnet-dev-win-x64.%DOTNET_VERSION%.zip
50 set DOTNET_REMOTE_PATH=https://dotnetcli.blob.core.windows.net/dotnet/beta/Binaries/%DOTNET_VERSION%/%DOTNET_ZIP_NAME%
51 set DOTNET_LOCAL_PATH=%DOTNET_PATH%%DOTNET_ZIP_NAME%
52 echo Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> %INIT_TOOLS_LOG%
53 powershell -NoProfile -ExecutionPolicy unrestricted -Command "(New-Object Net.WebClient).DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); Add-Type -Assembly 'System.IO.Compression.FileSystem' -ErrorVariable AddTypeErrors; if ($AddTypeErrors.Count -eq 0) { [System.IO.Compression.ZipFile]::ExtractToDirectory('%DOTNET_LOCAL_PATH%', '%DOTNET_PATH%') } else { (New-Object -com shell.application).namespace('%DOTNET_PATH%').CopyHere((new-object -com shell.application).namespace('%DOTNET_LOCAL_PATH%').Items(),16) }" >> %INIT_TOOLS_LOG%
54 if NOT exist "%DOTNET_LOCAL_PATH%" (
55   echo ERROR: Could not install dotnet cli correctly. See '%INIT_TOOLS_LOG%' for more details.
56   goto :EOF
57 )
58
59 :afterdotnetrestore
60
61 if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
62 echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
63 echo Running: "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" >> %INIT_TOOLS_LOG%
64 call "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages %PACKAGES_DIR% --source "%BUILDTOOLS_SOURCE%" >> %INIT_TOOLS_LOG%
65 if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
66   echo ERROR: Could not restore build tools correctly. See '%INIT_TOOLS_LOG%' for more details.
67   goto :EOF
68 )
69
70 :afterbuildtoolsrestore
71
72 echo Initializing BuildTools ...
73 echo Running: "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> %INIT_TOOLS_LOG%
74 call "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> %INIT_TOOLS_LOG%
75
76 :: Create sempahore file
77 echo Done initializing tools.
78 echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"