[Tizen] Add method to write coredump of .NET process (#317)
[platform/upstream/coreclr.git] / init-tools.cmd
index 305fe49..b483d72 100644 (file)
@@ -1,10 +1,14 @@
 @if not defined _echo @echo off
 setlocal
 
+:: Clear the 'Platform' environment variable for this session
+:: This avoids overriding the default value from BuildTools projects used for initialization
+set Platform=
+
 set INIT_TOOLS_LOG=%~dp0init-tools.log
-if [%PACKAGES_DIR%]==[] set PACKAGES_DIR=%~dp0packages
+if [%PACKAGES_DIR%]==[] set PACKAGES_DIR=%~dp0.packages
 if [%TOOLRUNTIME_DIR%]==[] set TOOLRUNTIME_DIR=%~dp0Tools
-set DOTNET_PATH=%TOOLRUNTIME_DIR%\dotnetcli\
+set DOTNET_PATH=%~dp0.dotnet\
 if [%DOTNET_CMD%]==[] set DOTNET_CMD=%DOTNET_PATH%dotnet.exe
 if [%BUILDTOOLS_SOURCE%]==[] set BUILDTOOLS_SOURCE=https://dotnet.myget.org/F/dotnet-buildtools/api/v3/index.json
 set /P BUILDTOOLS_VERSION=< "%~dp0BuildToolsVersion.txt"
@@ -47,20 +51,49 @@ echo Running %0 > "%INIT_TOOLS_LOG%"
 set /p DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"
 if exist "%DOTNET_CMD%" goto :afterdotnetrestore
 
-echo Installing dotnet cli...
-if NOT exist "%DOTNET_PATH%" mkdir "%DOTNET_PATH%"
-set DOTNET_ZIP_NAME=dotnet-sdk-%DOTNET_VERSION%-win-x64.zip
-set DOTNET_REMOTE_PATH=https://dotnetcli.azureedge.net/dotnet/Sdk/%DOTNET_VERSION%/%DOTNET_ZIP_NAME%
-set DOTNET_LOCAL_PATH=%DOTNET_PATH%%DOTNET_ZIP_NAME%
-echo Installing '%DOTNET_REMOTE_PATH%' to '%DOTNET_LOCAL_PATH%' >> "%INIT_TOOLS_LOG%"
-powershell -NoProfile -ExecutionPolicy unrestricted -Command "$retryCount = 0; $success = $false; $proxyCredentialsRequired = $false; do { try { $wc = New-Object Net.WebClient; if ($proxyCredentialsRequired) { [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials; } $wc.DownloadFile('%DOTNET_REMOTE_PATH%', '%DOTNET_LOCAL_PATH%'); $success = $true; } catch { if ($retryCount -ge 6) { throw; } else { $we = $_.Exception.InnerException -as [Net.WebException]; $proxyCredentialsRequired = ($we -ne $null -and ([Net.HttpWebResponse]$we.Response).StatusCode -eq [Net.HttpStatusCode]::ProxyAuthenticationRequired); Start-Sleep -Seconds (5 * $retryCount); $retryCount++; } } } while ($success -eq $false); 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%"
-if NOT exist "%DOTNET_LOCAL_PATH%" (
-  echo ERROR: Could not install dotnet cli correctly. 1>&2
-  goto :error
+REM Use x86 tools on arm64 and x86.
+REM arm32 host is not currently supported, please crossbuild.
+if /i "%PROCESSOR_ARCHITECTURE%" == "arm" (
+  echo "Error, arm32 arch not supported for build tools."
+  exit /b 1
+)
+
+if /i "%PROCESSOR_ARCHITECTURE%" == "amd64" (
+  set _Arch=x64
+  goto ArchSet
+)
+
+REM If this is not amd64 and not arm, then we should be running on arm64 or x86
+REM either way we can (and should) use the x86 dotnet cli
+REM
+REM TODO: consume native arm64 toolset, blocked by official arm64 windows cli
+REM     : release. See https://github.com/dotnet/coreclr/issues/19614 for more
+REM     : information
+set _Arch=x86
+
+echo "init-tools.cmd: Setting arch to %_Arch% for build tools"
+
+:ArchSet
+
+if NOT exist "%DOTNET_CMD%" (
+  call %~dp0init-dotnet.cmd
+  if NOT exist "%DOTNET_CMD%" (
+    echo ERROR: Could not install dotnet cli correctly. 1>&2
+    goto :error
+  )
 )
 
 :afterdotnetrestore
 
+REM We do not need the build tools for arm64/x86
+if /i "%PROCESSOR_ARCHITEW6432%" == "arm64" (
+  goto :EOF
+)
+
+if /i "%PROCESSOR_ARCHITECTURE%" == "arm64" (
+  goto :EOF
+)
+
 if exist "%BUILD_TOOLS_PATH%" goto :afterbuildtoolsrestore
 echo Restoring BuildTools version %BUILDTOOLS_VERSION%...
 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%"
@@ -72,9 +105,6 @@ if NOT exist "%BUILD_TOOLS_PATH%\init-tools.cmd" (
 
 :afterbuildtoolsrestore
 
-:: Ask init-tools to also restore ILAsm
-set /p ILASMCOMPILER_VERSION=< "%~dp0ILAsmVersion.txt"
-
 echo Initializing BuildTools...
 echo Running: "%BUILD_TOOLS_PATH%\init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" >> "%INIT_TOOLS_LOG%"
 call "%BUILD_TOOLS_PATH%\init-tools.cmd" "%~dp0" "%DOTNET_CMD%" "%TOOLRUNTIME_DIR%" "%PACKAGES_DIR%" >> "%INIT_TOOLS_LOG%"
@@ -84,6 +114,12 @@ if not [%INIT_TOOLS_ERRORLEVEL%]==[0] (
   goto :error
 )
 
+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.
+set /p ILASM_VERSION=< "%~dp0ILAsmVersion.txt"
+if [%NATIVE_TOOLS_RID%] == [] set NATIVE_TOOLS_RID=win-x64
+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%"
+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"
+
 :: Create semaphore file
 echo Done initializing tools.
 if NOT exist "%BUILD_TOOLS_SEMAPHORE_DIR%" mkdir "%BUILD_TOOLS_SEMAPHORE_DIR%"