Use preinstalled system dotnet if its version matches (dotnet/coreclr#27705)
authorTomáš Rylek <trylek@microsoft.com>
Thu, 7 Nov 2019 09:10:46 +0000 (01:10 -0800)
committerViktor Hofer <viktor.hofer@microsoft.com>
Thu, 7 Nov 2019 09:10:46 +0000 (10:10 +0100)
* Use preinstalled system dotnet if its version matches

According to standard Arcade logic, CoreCLR build should be using
preinstalled system dotnet if it's the same version as requested
by the CoreCLR build.

We were suppressing this logic in configure-toolset.ps1 by setting
$script:useInstalledDotNetCli = $false with reference to some
obsolete build tools logic that no longer exists.

I have replaced this with a simple function that calls
InitializeBuildTool from the tools.ps1 Arcade script and produces
the result in form of a one-line batch file setting the dotnet
path to an environment variable we can then use in dotnet.cmd.

I have modified the Linux script dotnet.sh to again consume the
dotnet path from InitializeBuildTool.

Thanks

Tomas

* Address Viktor's and Jan's PR feedback

Based on offline discussion with Viktor I have cleaned this up
as follows:

1) I have deleted both init-dotnet scripts;

2) The dotnet script directly calls powershell on the tools.ps1
script to call the function InitializeDotNetCli and use JanV's
trick to capture its return value in an auxiliary environment
variable that is subsequently used to launch dotnet.

3) In tests/build.proj, I applied Viktor's feedback by deleting
the custom code and switching it over to the standard Arcade
property DotNetTool.

Thanks

Tomas

* Remove explicit inclusion of configure-toolset.ps1

* Fix Linux version of the dotnet script; missing quotes in build.proj

* Fix variable name typo in the Linux dotnet.sh script

Commit migrated from https://github.com/dotnet/coreclr/commit/3f6ed5b833071b4ba71fac46ea4a06fd9ef3eb4d

src/coreclr/dotnet.cmd
src/coreclr/dotnet.sh
src/coreclr/init-dotnet.cmd [deleted file]
src/coreclr/init-dotnet.sh [deleted file]
src/coreclr/tests/build.proj

index e65ff4f..686432d 100644 (file)
@@ -2,15 +2,14 @@
 setlocal
 
 set "__ProjectDir=%~dp0"
-set "__RepoRootDir=%~dp0..\..\"
+set "__RepoRootDir=%__ProjectDir%..\..\"
 
 rem Remove after repo consolidation
-if not exist "%__RepoRootDir%.dotnet-runtime-placeholder" ( set "__RepoRootDir=!__ProjectDir!" )
+if not exist "%__RepoRootDir%\.dotnet-runtime-placeholder" ( set "__RepoRootDir=%__ProjectDir%" )
 
 :: Clear the 'Platform' env variable for this session, as it's a per-project setting within the build, and
 :: misleading value (such as 'MCD' in HP PCs) may lead to build breakage (issue: #69).
 set Platform=
-set __ProjectDir=
 
 :: Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism
 set DOTNET_MULTILEVEL_LOOKUP=0
@@ -18,17 +17,23 @@ set DOTNET_MULTILEVEL_LOOKUP=0
 :: Disable first run since we do not need all ASP.NET packages restored.
 set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
 
-:: Install dotnet
-call %~dp0\init-dotnet.cmd
-if NOT [%ERRORLEVEL%]==[0] (
+echo Installing dotnet using Arcade...
+set PS_DOTNET_INSTALL_SCRIPT=". %__RepoRootDir%eng\common\tools.ps1; InitializeDotNetCli($true)"
+set "PS_COMMAND=powershell -NoProfile -ExecutionPolicy unrestricted -Command %PS_DOTNET_INSTALL_SCRIPT%"
+
+echo running: %PS_COMMAND%
+for /f "delims=" %%l in ('%PS_COMMAND%') do set "__dotnetDir=%%l"
+
+if NOT [%ERRORLEVEL%] == [0] (
+  echo Failed to install dotnet using Arcade.
   exit /b %ERRORLEVEL%
 )
 
-set "dotnetPath=%__RepoRootDir%.dotnet\dotnet.exe"
+set "dotnetPath=%__dotnetDir%\dotnet.exe"
 
 pushd %~dp0
-echo Running: %dotnetPath% %*
-call %dotnetPath% %*
+echo Running: "%dotnetPath%" %*
+call "%dotnetPath%" %*
 popd
 if NOT [%ERRORLEVEL%]==[0] (
   exit /b 1
index c0c3fe8..e54bbd5 100755 (executable)
@@ -1,11 +1,12 @@
 #!/usr/bin/env bash
 
 working_tree_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+__ProjectDir=${working_tree_root}
 __RepoRootDir=${working_tree_root}/../..
 
 # BEGIN SECTION to remove after repo consolidation
 if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then
-  __RepoRootDir=${__ProjectRoot}
+  __RepoRootDir=${__ProjectDir}
 fi
 # END SECTION to remove after repo consolidation
 
@@ -15,11 +16,17 @@ export DOTNET_MULTILEVEL_LOOKUP=0
 # Disable first run since we want to control all package sources
 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
 
-echo "Running init-dotnet.sh"
-source $working_tree_root/init-dotnet.sh
+source ${__RepoRootDir}/eng/common/tools.sh
 
-${_InitializeDotNetCli}/dotnet
-dotnetPath=${__RepoRootDir}/.dotnet/dotnet
+InitializeDotNetCli
+__dotnetDir=${_InitializeDotNetCli}
+
+if [ $? != 0 ]; then
+    echo "Failed to install dotnet using Arcade"
+    exit $?
+fi
+
+dotnetPath=${__dotnetDir}/dotnet
 
 echo "Running: ${dotnetPath} $@"
 ${dotnetPath} "$@"
diff --git a/src/coreclr/init-dotnet.cmd b/src/coreclr/init-dotnet.cmd
deleted file mode 100644 (file)
index c4853d6..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-@if not defined _echo @echo off
-setlocal
-
-set "__ProjectDir=%~dp0"
-set "__RepoRootDir=%__ProjectDir%..\..\"
-
-rem Remove after repo consolidation
-if not exist "%__RepoRootDir%\.dotnet-runtime-placeholder" ( set "__RepoRootDir=%__ProjectDir%" )
-
-echo Installing dotnet using Arcade...
-set PS_DOTNET_INSTALL_SCRIPT=". %__RepoRootDir%eng\configure-toolset.ps1; . %__RepoRootDir%eng\common\tools.ps1; InitializeBuildTool"
-echo running: powershell -NoProfile -ExecutionPolicy unrestricted -Command %PS_DOTNET_INSTALL_SCRIPT%
-powershell -NoProfile -ExecutionPolicy unrestricted -Command %PS_DOTNET_INSTALL_SCRIPT%
-if NOT [%ERRORLEVEL%] == [0] (
-  echo Failed to install dotnet using Arcade.
-  exit /b %ERRORLEVEL%
-)
-
-exit /b 0
\ No newline at end of file
diff --git a/src/coreclr/init-dotnet.sh b/src/coreclr/init-dotnet.sh
deleted file mode 100644 (file)
index 4c865fc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-
-__scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-__RepoRootDir="${__scriptpath}/../.."
-
-# BEGIN SECTION to remove after repo consolidation
-if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then
-  __RepoRootDir=${__scriptpath}
-fi
-# END SECTION to remove after repo consolidation
-
-echo "Installing dotnet using Arcade..."
-
-source ${__RepoRootDir}/eng/configure-toolset.sh
-source ${__RepoRootDir}/eng/common/tools.sh
-
-InitializeBuildTool
-
-if [ $? != 0 ]; then
-    echo "Failed to install dotnet using Arcade"
-    exit $?
-fi
\ No newline at end of file
index c804ea9..50c4682 100644 (file)
 
   <Target Name="RestorePackage">
     <PropertyGroup>
-      <DotnetCliPath Condition="'$(DotnetCliPath)'==''">$(RepoRoot)\.dotnet\</DotnetCliPath>
-      <DotnetToolPath Condition="'$(OS)' != 'Windows_NT'">$(DotnetCliPath)dotnet</DotnetToolPath>
-      <DotnetToolPath Condition="'$(OS)' == 'Windows_NT'">$(DotnetCliPath)dotnet.exe</DotnetToolPath>
       <_ConfigurationProperties>/p:__BuildOS=$(__BuildOS) /p:__BuildArch=$(__BuildArch) /p:__BuildType=$(__BuildType)</_ConfigurationProperties>
-      <DotnetRestoreCommand Condition="'$(__DistroRid)' == ''">$(DotnetToolPath) restore $(RestoreProj) $(PackageVersionArg) /p:SetTFMForRestore=true $(_ConfigurationProperties)</DotnetRestoreCommand>
-      <DotnetRestoreCommand Condition="'$(__DistroRid)' != ''">$(DotnetToolPath) restore -r $(__DistroRid) $(RestoreProj) $(PackageVersionArg) /p:SetTFMForRestore=true $(_ConfigurationProperties)</DotnetRestoreCommand>
+      <DotnetRestoreCommand Condition="'$(__DistroRid)' == ''">"$(DotNetTool)" restore $(RestoreProj) $(PackageVersionArg) /p:SetTFMForRestore=true $(_ConfigurationProperties)</DotnetRestoreCommand>
+      <DotnetRestoreCommand Condition="'$(__DistroRid)' != ''">"$(DotNetTool)" restore -r $(__DistroRid) $(RestoreProj) $(PackageVersionArg) /p:SetTFMForRestore=true $(_ConfigurationProperties)</DotnetRestoreCommand>
     </PropertyGroup>
     <Exec Command="$(DotnetRestoreCommand)"/>
   </Target>