Skip to content

Commit

Permalink
Move dotnet.cmd/sh helper scripts into the repo root (#672)
Browse files Browse the repository at this point in the history
* Move dotnet helper scripts to repo root

* Don't swallow InitializeDotNetCli output

* Use temporary file to store sdk location

To avoid a nested process chain in which the inner process then invokes
the host, we instead create a temporary file to store the sdk location.
  • Loading branch information
ViktorHofer committed Dec 11, 2019
1 parent 071da4c commit f5957b1
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 113 deletions.
22 changes: 22 additions & 0 deletions dotnet.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@echo off

powershell -ExecutionPolicy ByPass -NoProfile -Command "& { . '%~dp0eng\common\tools.ps1'; InitializeDotNetCli $true $true }"

if NOT [%ERRORLEVEL%] == [0] (
echo Failed to install or invoke dotnet... 1>&2
exit /b %ERRORLEVEL%
)

set /p dotnetPath=<%~dp0artifacts\toolset\sdk.txt

:: 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=

:: Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism
set DOTNET_MULTILEVEL_LOOKUP=0

:: Disable first run since we want to control all package sources
set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

call "%dotnetPath%\dotnet.exe" %*
27 changes: 27 additions & 0 deletions dotnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

source="${BASH_SOURCE[0]}"
# resolve $SOURCE until the file is no longer a symlink
while [[ -h $source ]]; do
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
source="$(readlink "$source")"

# if $source was a relative symlink, we need to resolve it relative to the path where the
# symlink file was located
[[ $source != /* ]] && source="$scriptroot/$source"
done
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"

# Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism
export DOTNET_MULTILEVEL_LOOKUP=0

# Disable first run since we want to control all package sources
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1

source $scriptroot/eng/common/tools.sh

InitializeDotNetCli true # Install
__dotnetDir=${_InitializeDotNetCli}

dotnetPath=${__dotnetDir}/dotnet
${dotnetPath} "$@"
18 changes: 17 additions & 1 deletion eng/common/tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function Exec-Process([string]$command, [string]$commandArgs) {
}
}

function InitializeDotNetCli([bool]$install) {
function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
if (Test-Path variable:global:_DotNetInstallDir) {
return $global:_DotNetInstallDir
}
Expand Down Expand Up @@ -146,6 +146,22 @@ function InitializeDotNetCli([bool]$install) {
}

$env:DOTNET_INSTALL_DIR = $dotnetRoot

if ($createSdkLocationFile) {
# Create a temporary file under the toolset dir and rename it to sdk.txt to avoid races.
do {
$sdkCacheFileTemp = Join-Path $ToolsetDir $([System.IO.Path]::GetRandomFileName())
}
until (!(Test-Path $sdkCacheFileTemp))
Set-Content -Path $sdkCacheFileTemp -Value $dotnetRoot

try {
Rename-Item -Force -Path $sdkCacheFileTemp 'sdk.txt'
} catch {
# Somebody beat us
Remove-Item -Path $sdkCacheFileTemp
}
}
}

# Add dotnet to PATH. This prevents any bare invocation of dotnet in custom
Expand Down
13 changes: 0 additions & 13 deletions eng/update-dependencies.cmd

This file was deleted.

2 changes: 1 addition & 1 deletion src/coreclr/build-test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!

REM Build wrappers using the local SDK's msbuild. As we move to arcade, the other builds should be moved away from run.exe as well.
call "%__ProjectDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\src\runtest.proj /nodereuse:false /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__SkipFXRestoreArg% %__UnprocessedBuildArgs%
call "%__RepoRootDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\src\runtest.proj /nodereuse:false /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__SkipFXRestoreArg% %__UnprocessedBuildArgs%
if errorlevel 1 (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: XUnit wrapper build failed. Refer to the build log files for details:
echo %__BuildLog%
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ __CrossBuild=0
__DistroRid=""
__DoCrossgen=0
__DoCrossgen2=0
__DotNetCli="$__ProjectDir/dotnet.sh"
__DotNetCli="$__RepoRootDir/dotnet.sh"
__GccBuild=0
__GccMajorVersion=0
__GccMinorVersion=0
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ if %__BuildCoreLib% EQU 1 (

if "%__BuildManagedTools%" == "1" (
echo %__MsgPrefix%Publishing crossgen2...
call %__ProjectDir%\dotnet.cmd publish --self-contained -r win-%__BuildArch% -c %__BuildType% -o "%__BinDir%\crossgen2" "%__ProjectDir%\src\tools\crossgen2\crossgen2\crossgen2.csproj" /p:BuildArch=%__BuildArch%
call %__RepoRootDir%\dotnet.cmd publish --self-contained -r win-%__BuildArch% -c %__BuildType% -o "%__BinDir%\crossgen2" "%__ProjectDir%\src\tools\crossgen2\crossgen2\crossgen2.csproj" /p:BuildArch=%__BuildArch%

if not !errorlevel! == 0 (
echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to build crossgen2.
Expand Down Expand Up @@ -706,7 +706,7 @@ if %__BuildCoreLib% EQU 1 (
)
)

set IBCMergeCommand=%__ProjectDir%\dotnet.cmd --roll-forward-on-no-candidate-fx 2 "!IbcMergePath!"
set IBCMergeCommand=%__RepoRootDir%\dotnet.cmd --roll-forward-on-no-candidate-fx 2 "!IbcMergePath!"

REM Merge the optimization data into the source DLL
set NEXTCMD=!IBCMergeCommand! -q -f -delete -mo "!InputAssemblyFile!" !RawOptimizationDataFile!
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ build_CoreLib()

if [[ "$__BuildManagedTools" -eq "1" ]]; then
echo "Publishing crossgen2 for $__DistroRid"
"$__ProjectRoot/dotnet.sh" publish --self-contained -r $__DistroRid -c $__BuildType -o "$__BinDir/crossgen2" "$__ProjectRoot/src/tools/crossgen2/crossgen2/crossgen2.csproj" /p:BuildArch=$__BuildArch
"$__RepoRootDir/dotnet.sh" publish --self-contained -r $__DistroRid -c $__BuildType -o "$__BinDir/crossgen2" "$__ProjectRoot/src/tools/crossgen2/crossgen2/crossgen2.csproj" /p:BuildArch=$__BuildArch

local exit_code=$?
if [ $exit_code != 0 ]; then
Expand Down
38 changes: 0 additions & 38 deletions src/coreclr/dotnet.cmd

This file was deleted.

34 changes: 0 additions & 34 deletions src/coreclr/dotnet.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/coreclr/tests/bringup_runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ function create_testhost
fi

# Initialize test variables
local dotnetExe=$coreClrSrc/dotnet.sh
local dotnetExe=$coreClrSrc/../../dotnet.sh
local coreClrSrcTestDir=$coreClrSrc/tests

if [ -z $coreClrBinDir ]; then
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tests/runtest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set "__RootBinDir=%__ProjectDir%\..\artifacts"
set "__LogsDir=%__RootBinDir%\log"
set "__MsbuildDebugLogsDir=%__LogsDir%\MsbuildDebugLogs"
set __ToolsDir=%__ProjectDir%\..\Tools
set "DotNetCli=%__ProjectDir%\..\dotnet.cmd"
set "DotNetCli=%__ProjectDir%\..\..\..\dotnet.cmd"

set __Sequential=
set __msbuildExtraArgs=
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tests/runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function create_testhost
fi

# Initialize test variables
local dotnetExe=$coreClrSrc/dotnet.sh
local dotnetExe=$coreClrSrc/../../dotnet.sh
local coreClrSrcTestDir=$coreClrSrc/tests

if [ -z $coreClrBinDir ]; then
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/tests/setup-stress-dependencies.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ REM === Check if dotnet CLI and necessary directories exist
REM ===
REM =========================================================================================

set __DotNetCmd=%__ThisScriptPath%..\dotnet.cmd
set __DotNetCmd=%__ThisScriptPath%..\..\..\dotnet.cmd
set __CsprojPath=%__ThisScriptPath%\stress_dependencies\stress_dependencies.csproj

if not exist "%__DotNetCmd%" (
echo dotnet.exe does not exist: %__DotNetCmd%
goto Fail
)

REM Create directories needed
if not exist "%__OutputDir%" md "%__OutputDir%"

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tests/setup-stress-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fi
# This script must be located in coreclr/tests.
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

dotnet=$"${scriptDir}"/../dotnet.sh
dotnet=$"${scriptDir}"/../../../dotnet.sh
csprojPath="${scriptDir}"/stress_dependencies/stress_dependencies.csproj

if [ ! -e $dotnetCmd ]; then
Expand Down
25 changes: 13 additions & 12 deletions src/coreclr/tests/src/readytorun/r2rdump/rebaseline.cmd
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
set CurrentDir=%~dp0
set ProjectDir=%CurrentDir%..\..\..\..\
set RepoRoot=%ProjectDir%..\..\

"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release %ProjectDir%src\tools\r2rdump\R2RDump.csproj
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj

set tests=HelloWorld GcInfoTransitions GenericFunctions MultipleRuntimeFunctions

(for %%a in (%tests%) do (
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
%ProjectDir%artifacts\tests\Windows_NT.x64.Checked\Tests\Core_Root\crossgen /readytorun /platform_assemblies_paths %ProjectDir%artifacts\tests\Windows_NT.x64.Checked\Tests\Core_Root /out %%a.ni.dll %ProjectDir%artifacts\tests\Windows_NT.x64.Checked\readytorun\r2rdump\files\%%a\%%a.dll
"%ProjectDir%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x64.Checked\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Checked\%%a.xml -x -v --ignoreSensitive
"%RepoRoot%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x64.Checked\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Checked\%%a.xml -x -v --ignoreSensitive
))

(for %%a in (%tests%) do (
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
%ProjectDir%artifacts\tests\Windows_NT.x64.Debug\Tests\Core_Root\crossgen /readytorun /platform_assemblies_paths %ProjectDir%artifacts\tests\Windows_NT.x64.Debug\Tests\Core_Root /out %%a.ni.dll %ProjectDir%artifacts\tests\Windows_NT.x64.Debug\readytorun\r2rdump\files\%%a\%%a.dll
"%ProjectDir%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x64.Debug\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Debug\%%a.xml -x -v --ignoreSensitive
"%RepoRoot%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x64.Debug\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Debug\%%a.xml -x -v --ignoreSensitive
))

(for %%a in (%tests%) do (
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
%ProjectDir%artifacts\tests\Windows_NT.x86.Release\Tests\Core_Root\crossgen /readytorun /platform_assemblies_paths %ProjectDir%artifacts\tests\Windows_NT.x86.Release\Tests\Core_Root /out %%a.ni.dll %ProjectDir%artifacts\tests\Windows_NT.x86.Release\readytorun\r2rdump\files\%%a\%%a.dll
"%ProjectDir%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x86.Release\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x86.Release\%%a.xml -x -v --ignoreSensitive
"%RepoRoot%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x86.Release\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x86.Release\%%a.xml -x -v --ignoreSensitive
))

(for %%a in (%tests%) do (
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
%ProjectDir%artifacts\tests\Windows_NT.x86.Debug\Tests\Core_Root\crossgen /readytorun /platform_assemblies_paths %ProjectDir%artifacts\tests\Windows_NT.x86.Debug\Tests\Core_Root /out %%a.ni.dll %ProjectDir%artifacts\tests\Windows_NT.x86.Debug\readytorun\r2rdump\files\%%a\%%a.dll
"%ProjectDir%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x86.Debug\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x86.Debug\%%a.xml -x -v --ignoreSensitive
"%RepoRoot%dotnet.cmd" %ProjectDir%artifacts\bin\coreclr\Windows_NT.x86.Debug\netcoreapp2.0\R2RDump.dll --in %%a.ni.dll --out %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x86.Debug\%%a.xml -x -v --ignoreSensitive
))

COPY /Y %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Checked\*.xml %ProjectDir%tests\src\readytorun\r2rdump\files\Windows_NT.x64.Release\
Expand Down

0 comments on commit f5957b1

Please sign in to comment.