Skip to content

Commit f5957b1

Browse files
authored
Move dotnet.cmd/sh helper scripts into the repo root (#672)
* 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.
1 parent 071da4c commit f5957b1

16 files changed

+89
-113
lines changed

dotnet.cmd

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@echo off
2+
3+
powershell -ExecutionPolicy ByPass -NoProfile -Command "& { . '%~dp0eng\common\tools.ps1'; InitializeDotNetCli $true $true }"
4+
5+
if NOT [%ERRORLEVEL%] == [0] (
6+
echo Failed to install or invoke dotnet... 1>&2
7+
exit /b %ERRORLEVEL%
8+
)
9+
10+
set /p dotnetPath=<%~dp0artifacts\toolset\sdk.txt
11+
12+
:: Clear the 'Platform' env variable for this session, as it's a per-project setting within the build, and
13+
:: misleading value (such as 'MCD' in HP PCs) may lead to build breakage (issue: #69).
14+
set Platform=
15+
16+
:: Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism
17+
set DOTNET_MULTILEVEL_LOOKUP=0
18+
19+
:: Disable first run since we want to control all package sources
20+
set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
22+
call "%dotnetPath%\dotnet.exe" %*

dotnet.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
source="${BASH_SOURCE[0]}"
4+
# resolve $SOURCE until the file is no longer a symlink
5+
while [[ -h $source ]]; do
6+
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
7+
source="$(readlink "$source")"
8+
9+
# if $source was a relative symlink, we need to resolve it relative to the path where the
10+
# symlink file was located
11+
[[ $source != /* ]] && source="$scriptroot/$source"
12+
done
13+
scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
14+
15+
# Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism
16+
export DOTNET_MULTILEVEL_LOOKUP=0
17+
18+
# Disable first run since we want to control all package sources
19+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
20+
21+
source $scriptroot/eng/common/tools.sh
22+
23+
InitializeDotNetCli true # Install
24+
__dotnetDir=${_InitializeDotNetCli}
25+
26+
dotnetPath=${__dotnetDir}/dotnet
27+
${dotnetPath} "$@"

eng/common/tools.ps1

+17-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function Exec-Process([string]$command, [string]$commandArgs) {
9898
}
9999
}
100100

101-
function InitializeDotNetCli([bool]$install) {
101+
function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
102102
if (Test-Path variable:global:_DotNetInstallDir) {
103103
return $global:_DotNetInstallDir
104104
}
@@ -146,6 +146,22 @@ function InitializeDotNetCli([bool]$install) {
146146
}
147147

148148
$env:DOTNET_INSTALL_DIR = $dotnetRoot
149+
150+
if ($createSdkLocationFile) {
151+
# Create a temporary file under the toolset dir and rename it to sdk.txt to avoid races.
152+
do {
153+
$sdkCacheFileTemp = Join-Path $ToolsetDir $([System.IO.Path]::GetRandomFileName())
154+
}
155+
until (!(Test-Path $sdkCacheFileTemp))
156+
Set-Content -Path $sdkCacheFileTemp -Value $dotnetRoot
157+
158+
try {
159+
Rename-Item -Force -Path $sdkCacheFileTemp 'sdk.txt'
160+
} catch {
161+
# Somebody beat us
162+
Remove-Item -Path $sdkCacheFileTemp
163+
}
164+
}
149165
}
150166

151167
# Add dotnet to PATH. This prevents any bare invocation of dotnet in custom

eng/update-dependencies.cmd

-13
This file was deleted.

src/coreclr/build-test.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ set __MsbuildErr=/flp2:ErrorsOnly;LogFile="%__BuildErr%"
531531
set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr!
532532

533533
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.
534-
call "%__ProjectDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\src\runtest.proj /nodereuse:false /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__SkipFXRestoreArg% %__UnprocessedBuildArgs%
534+
call "%__RepoRootDir%\dotnet.cmd" msbuild %__ProjectDir%\tests\src\runtest.proj /nodereuse:false /p:BuildWrappers=true !__Logging! %__msbuildArgs% %TargetsWindowsMsbuildArg% %__SkipFXRestoreArg% %__UnprocessedBuildArgs%
535535
if errorlevel 1 (
536536
echo %__ErrMsgPrefix%%__MsgPrefix%Error: XUnit wrapper build failed. Refer to the build log files for details:
537537
echo %__BuildLog%

src/coreclr/build-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ __CrossBuild=0
663663
__DistroRid=""
664664
__DoCrossgen=0
665665
__DoCrossgen2=0
666-
__DotNetCli="$__ProjectDir/dotnet.sh"
666+
__DotNetCli="$__RepoRootDir/dotnet.sh"
667667
__GccBuild=0
668668
__GccMajorVersion=0
669669
__GccMinorVersion=0

src/coreclr/build.cmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ if %__BuildCoreLib% EQU 1 (
656656

657657
if "%__BuildManagedTools%" == "1" (
658658
echo %__MsgPrefix%Publishing crossgen2...
659-
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%
659+
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%
660660

661661
if not !errorlevel! == 0 (
662662
echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to build crossgen2.
@@ -706,7 +706,7 @@ if %__BuildCoreLib% EQU 1 (
706706
)
707707
)
708708

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

711711
REM Merge the optimization data into the source DLL
712712
set NEXTCMD=!IBCMergeCommand! -q -f -delete -mo "!InputAssemblyFile!" !RawOptimizationDataFile!

src/coreclr/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ build_CoreLib()
392392

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

397397
local exit_code=$?
398398
if [ $exit_code != 0 ]; then

src/coreclr/dotnet.cmd

-38
This file was deleted.

src/coreclr/dotnet.sh

-34
This file was deleted.

src/coreclr/tests/bringup_runtest.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ function create_testhost
448448
fi
449449

450450
# Initialize test variables
451-
local dotnetExe=$coreClrSrc/dotnet.sh
451+
local dotnetExe=$coreClrSrc/../../dotnet.sh
452452
local coreClrSrcTestDir=$coreClrSrc/tests
453453

454454
if [ -z $coreClrBinDir ]; then

src/coreclr/tests/runtest.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set "__RootBinDir=%__ProjectDir%\..\artifacts"
2020
set "__LogsDir=%__RootBinDir%\log"
2121
set "__MsbuildDebugLogsDir=%__LogsDir%\MsbuildDebugLogs"
2222
set __ToolsDir=%__ProjectDir%\..\Tools
23-
set "DotNetCli=%__ProjectDir%\..\dotnet.cmd"
23+
set "DotNetCli=%__ProjectDir%\..\..\..\dotnet.cmd"
2424

2525
set __Sequential=
2626
set __msbuildExtraArgs=

src/coreclr/tests/runtest.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function create_testhost
5959
fi
6060

6161
# Initialize test variables
62-
local dotnetExe=$coreClrSrc/dotnet.sh
62+
local dotnetExe=$coreClrSrc/../../dotnet.sh
6363
local coreClrSrcTestDir=$coreClrSrc/tests
6464

6565
if [ -z $coreClrBinDir ]; then

src/coreclr/tests/setup-stress-dependencies.cmd

+1-6
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,9 @@ REM === Check if dotnet CLI and necessary directories exist
5252
REM ===
5353
REM =========================================================================================
5454

55-
set __DotNetCmd=%__ThisScriptPath%..\dotnet.cmd
55+
set __DotNetCmd=%__ThisScriptPath%..\..\..\dotnet.cmd
5656
set __CsprojPath=%__ThisScriptPath%\stress_dependencies\stress_dependencies.csproj
5757

58-
if not exist "%__DotNetCmd%" (
59-
echo dotnet.exe does not exist: %__DotNetCmd%
60-
goto Fail
61-
)
62-
6358
REM Create directories needed
6459
if not exist "%__OutputDir%" md "%__OutputDir%"
6560

src/coreclr/tests/setup-stress-dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fi
9090
# This script must be located in coreclr/tests.
9191
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9292

93-
dotnet=$"${scriptDir}"/../dotnet.sh
93+
dotnet=$"${scriptDir}"/../../../dotnet.sh
9494
csprojPath="${scriptDir}"/stress_dependencies/stress_dependencies.csproj
9595

9696
if [ ! -e $dotnetCmd ]; then

src/coreclr/tests/src/readytorun/r2rdump/rebaseline.cmd

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
set CurrentDir=%~dp0
22
set ProjectDir=%CurrentDir%..\..\..\..\
3+
set RepoRoot=%ProjectDir%..\..\
34

4-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked %ProjectDir%src\tools\r2rdump\R2RDump.csproj
5-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
6-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release %ProjectDir%src\tools\r2rdump\R2RDump.csproj
7-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
5+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked %ProjectDir%src\tools\r2rdump\R2RDump.csproj
6+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
7+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release %ProjectDir%src\tools\r2rdump\R2RDump.csproj
8+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug %ProjectDir%src\tools\r2rdump\R2RDump.csproj
89

910
set tests=HelloWorld GcInfoTransitions GenericFunctions MultipleRuntimeFunctions
1011

1112
(for %%a in (%tests%) do (
12-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
13+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Checked "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
1314
%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
14-
"%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
15+
"%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
1516
))
1617

1718
(for %%a in (%tests%) do (
18-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
19+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x64 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
1920
%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
20-
"%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
21+
"%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
2122
))
2223

2324
(for %%a in (%tests%) do (
24-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
25+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Release "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
2526
%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
26-
"%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
27+
"%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
2728
))
2829

2930
(for %%a in (%tests%) do (
30-
"%ProjectDir%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
31+
"%RepoRoot%dotnet.cmd" build /p:__BuildArch=x86 /p:__BuildOS=Windows_NT /p:__BuildType=Debug "%ProjectDir%tests\src\readytorun\r2rdump\files\%%a.csproj"
3132
%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
32-
"%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
33+
"%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
3334
))
3435

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

0 commit comments

Comments
 (0)