Merge pull request #10799 from sdmaclea/PR-Fix-lvRegister-assert
[platform/upstream/coreclr.git] / init-tools.cmd
1 @if not defined _echo @echo off
2 setlocal
3
4 set INIT_TOOLS_LOG=%~dp0init-tools.log
5 set PACKAGES_DIR=%~dp0packages\
6 set TOOLRUNTIME_DIR=%~dp0Tools
7 :: This is an isolated script that handles the download of dotnet binaries and shall be removed after bootstrap.ps1/sh refactor (dotnet/corefx#15427)
8 set DOTNET_DOWNLOAD_PATH=%~dp0dotnet-download.ps1
9 set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
10 set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
11 if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json
12 set /P BUILDTOOLS_VERSION=< "%~dp0BuildToolsVersion.txt"
13 set BUILD_TOOLS_PATH=%PACKAGES_DIR%Microsoft.DotNet.BuildTools\%BUILDTOOLS_VERSION%\lib\
14 set PROJECT_JSON_PATH=%TOOLRUNTIME_DIR%\%BUILDTOOLS_VERSION%
15 set PROJECT_JSON_FILE=%PROJECT_JSON_PATH%\project.json
16 set PROJECT_JSON_CONTENTS={ "dependencies": { "Microsoft.DotNet.BuildTools": "%BUILDTOOLS_VERSION%" , "Microsoft.DotNet.BuildTools.Coreclr": "1.0.4-prerelease"}, "frameworks": { "dnxcore50": { } } }
17 set BUILD_TOOLS_SEMAPHORE=%PROJECT_JSON_PATH%\init-tools.completed0
18 set TOOLS_INIT_RETURN_CODE=0
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 :DONE
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 set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
45 if exist "%DOTNET_CMD%" goto :afterdotnetrestore
46
47 echo Installing dotnet cli...
48 if NOT exist "%DOTNET_PATH%" mkdir "%DOTNET_PATH%"
49 if [%PROCESSOR_ARCHITECTURE%]==[x86] (set DOTNET_ZIP_NAME=dotnet-dev-win-x86.%DOTNET_VERSION%.zip) else (set DOTNET_ZIP_NAME=dotnet-dev-win-x64.%DOTNET_VERSION%.zip)
50 set DOTNET_REMOTE_PATH=https://dotnetcli.blob.core.windows.net/dotnet/preview/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 -File %DOTNET_DOWNLOAD_PATH% -DotnetRemotePath %DOTNET_REMOTE_PATH% -DotnetLocalPath %DOTNET_LOCAL_PATH% -DotnetPath %DOTNET_PATH% >> "%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   set TOOLS_INIT_RETURN_CODE=1
57   goto :DONE
58 )
59
60 :afterdotnetrestore
61
62 if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
63 echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
64 echo Running: "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages "%PACKAGES_DIR% " --source "%BUILDTOOLS_SOURCE%" >> "%INIT_TOOLS_LOG%"
65 call "%DOTNET_CMD%" restore "%PROJECT_JSON_FILE%" --packages "%PACKAGES_DIR% " --source "%BUILDTOOLS_SOURCE%" >> "%INIT_TOOLS_LOG%"
66 if NOT exist "%BUILD_TOOLS_PATH%init-tools.cmd" (
67   echo ERROR: Could not restore build tools correctly. See '%INIT_TOOLS_LOG%' for more details.
68   set TOOLS_INIT_RETURN_CODE=1
69   goto :DONE
70 )
71
72 :afterbuildtoolsrestore
73
74 echo Initializing BuildTools ...
75 echo Running: "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
76 call "%BUILD_TOOLS_PATH%init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
77
78 echo Updating CLI NuGet Frameworks map...
79 robocopy "%TOOLRUNTIME_DIR%" "%TOOLRUNTIME_DIR%\dotnetcli\sdk\%DOTNET_VERSION%" NuGet.Frameworks.dll /XO >> "%INIT_TOOLS_LOG%"
80 set UPDATE_CLI_ERRORLEVEL=%ERRORLEVEL%
81 if %UPDATE_CLI_ERRORLEVEL% GTR 1 (
82   echo ERROR: Failed to update Nuget for CLI {Error level %UPDATE_CLI_ERRORLEVEL%}. Please check '%INIT_TOOLS_LOG%' for more details. 1>&2
83   exit /b %UPDATE_CLI_ERRORLEVEL%
84 )
85
86 :: Create sempahore file
87 echo Done initializing tools.
88 echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
89
90 :DONE
91
92 exit /b %TOOLS_INIT_RETURN_CODE%