1 @if not defined _echo @echo off
4 :: Clear the 'Platform' environment variable for this session
5 :: This avoids overriding the default value from BuildTools projects used for initialization
8 set INIT_TOOLS_LOG=%~dp0init-tools.log
9 if [%PACKAGES_DIR%]==[] set PACKAGES_DIR=%~dp0.packages
10 if [%TOOLRUNTIME_DIR%]==[] set TOOLRUNTIME_DIR=%~dp0Tools
11 set DOTNET_PATH=%~dp0.dotnet\
12 if [%DOTNET_CMD%]==[] set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
13 if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json
14 set /P BUILDTOOLS_VERSION=< "%~dp0BuildToolsVersion.txt"
15 set BUILD_TOOLS_PATH=%PACKAGES_DIR%\Microsoft.DotNet.BuildTools\%BUILDTOOLS_VERSION%\lib
16 set INIT_TOOLS_RESTORE_PROJECT=%~dp0init-tools.msbuild
17 set BUILD_TOOLS_SEMAPHORE_DIR=%TOOLRUNTIME_DIR%\%BUILDTOOLS_VERSION%
18 set BUILD_TOOLS_SEMAPHORE=%BUILD_TOOLS_SEMAPHORE_DIR%\init-tools.completed
20 :: if force option is specified then clean the tool runtime and build tools package directory to force it to get recreated
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"
26 :: If semaphore exists do nothing
27 if exist "%BUILD_TOOLS_SEMAPHORE%" (
28 echo Tools are already initialized.
32 if exist "%TOOLRUNTIME_DIR%" rmdir /S /Q "%TOOLRUNTIME_DIR%"
34 if exist "%DotNetBuildToolsDir%" (
35 echo Using tools from '%DotNetBuildToolsDir%'.
36 mklink /j "%TOOLRUNTIME_DIR%" "%DotNetBuildToolsDir%"
38 if not exist "%DOTNET_CMD%" (
39 echo ERROR: Ensure that '%DotNetBuildToolsDir%' contains the .NET Core SDK at '%DOTNET_PATH%'
43 echo Done initializing tools.
44 if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
45 echo Using tools from '%DotNetBuildToolsDir%'. > "%BUILD_TOOLS_SEMAPHORE%"
49 echo Running %0 > "%INIT_TOOLS_LOG%"
51 set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
52 if exist "%DOTNET_CMD%" goto :afterdotnetrestore
54 REM Use x86 tools on arm64 and x86.
55 REM arm32 host is not currently supported, please crossbuild.
56 if /i "%PROCESSOR_ARCHITECTURE%" == "arm" (
57 echo "Error, arm32 arch not supported for build tools."
61 if /i "%PROCESSOR_ARCHITECTURE%" == "amd64" (
66 REM If this is not amd64 and not arm, then we should be running on arm64 or x86
67 REM either way we can (and should) use the x86 dotnet cli
69 REM TODO: consume native arm64 toolset, blocked by official arm64 windows cli
70 REM : release. See https://github.com/dotnet/coreclr/issues/19614 for more
74 echo "init-tools.cmd: Setting arch to %_Arch% for build tools"
78 if NOT exist "%DOTNET_CMD%" (
79 call %~dp0init-dotnet.cmd
80 if NOT exist "%DOTNET_CMD%" (
81 echo ERROR: Could not install dotnet cli correctly. 1>&2
88 REM We do not need the build tools for arm64/x86
89 if /i "%PROCESSOR_ARCHITEW6432%" == "arm64" (
93 if /i "%PROCESSOR_ARCHITECTURE%" == "arm64" (
97 if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
98 echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
99 echo Running: "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages "%PACKAGES_DIR%" --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
100 call "%DOTNET_CMD%" restore "%INIT_TOOLS_RESTORE_PROJECT%" --no-cache --packages "%PACKAGES_DIR%" --source "%BUILDTOOLS_SOURCE%" /p:BuildToolsPackageVersion=%BUILDTOOLS_VERSION% /p:ToolsDir=%TOOLRUNTIME_DIR% >> "%INIT_TOOLS_LOG%"
101 if NOT exist "%BUILD_TOOLS_PATH%\init-tools.cmd" (
102 echo ERROR: Could not restore build tools correctly. 1>&2
106 :afterbuildtoolsrestore
108 echo Initializing BuildTools...
109 echo Running: "%BUILD_TOOLS_PATH%\init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
110 call "%BUILD_TOOLS_PATH%\init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" "%PACKAGES_DIR%" >> "%INIT_TOOLS_LOG%"
111 set INIT_TOOLS_ERRORLEVEL=%ERRORLEVEL%
112 if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
113 echo ERROR: An error occured when trying to initialize the tools. 1>&2
117 REM ILasm/ILDasm used to be restored by buildtools. The reference there was a netocreapp2.0, which was prior to our support of linux-musl. We initialize it locally as a 3.0 with the new SDK.
118 set /p ILASM_VERSION=< "%~dp0ILAsmVersion.txt"
119 if [%NATIVE_TOOLS_RID%] == [] set NATIVE_TOOLS_RID=win-x64
120 echo Running: call "%DOTNET_CMD%" build "%~dp0tests\ilasm-restore\ilasm.depproj" --no-cache --packages "%PACKAGES_DIR%" -r "%NATIVE_TOOLS_RID%" /p:ILAsmPackageVersion="%ILASM_VERSION%" /p:ExpectedILAsmPath="%TOOLRUNTIME_DIR%\ilasm" >> "%INIT_TOOLS_LOG%"
121 call "%DOTNET_CMD%" build "%~dp0tests\ilasm-restore\ilasm.depproj" --no-cache --packages "%PACKAGES_DIR%" -r "%NATIVE_TOOLS_RID%" /p:ILAsmPackageVersion="%ILASM_VERSION%" /p:ExpectedILAsmPath="%TOOLRUNTIME_DIR%\ilasm"
123 :: Create semaphore file
124 echo Done initializing tools.
125 if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"
126 echo Init-Tools.cmd completed for BuildTools Version: %BUILDTOOLS_VERSION% > "%BUILD_TOOLS_SEMAPHORE%"
130 echo Please check the detailed log that follows. 1>&2
131 type "%INIT_TOOLS_LOG%" 1>&2