set __DotNetToolDir=%__ThisScriptPath%..\Tools
set __DotNetCmd=%__DotNetToolDir%\dotnetcli\bin\dotnet.exe
set __PackageDir=%__ThisScriptPath%..\Packages
-set __JasonFilePath=%__ThisScriptPath%project.json
+set __TmpDir=%Temp%\coreclr_gcstress_%RANDOM%
-REM Check if dotnet CLI exists
+REM Check if donet cli exists
if not exist "%__DotNetToolDir%" (
echo Directory containing dotnet CLI does not exist: %__DotNetToolDir%
- exit /b 1
+ goto Fail
)
if not exist "%__DotNetCmd%" (
echo dotnet.exe does not exist: %__DotNetCmd%
- exit /b 1
+ goto Fail
)
REM Create directories needed
if not exist "%__PackageDir%" md "%__PackageDir%"
if not exist "%__OutputDir%" md "%__OutputDir%"
+REM Check and create a temp directory
+if exist "%__TmpDir%" (
+ rmdir /S /Q %__TmpDir%
+)
+mkdir %__TmpDir%
+
+REM Project.json path
+set __JasonFilePath=%__TmpDir%\project.json
REM =========================================================================================
REM ===
REM Download the package
echo Downloading CoreDisTools package
-echo on
-call "%__DotNetCmd%" restore "%__JasonFilePath%" --source https://dotnet.myget.org/F/dotnet-core/ --packages "%__PackageDir%"
-@echo off
+set DOTNETCMD="%__DotNetCmd%" restore "%__JasonFilePath%" --source https://dotnet.myget.org/F/dotnet-core/ --packages "%__PackageDir%"
+echo %DOTNETCMD%
+call %DOTNETCMD%
+if errorlevel 1 goto Fail
REM Get downloaded dll path
-FOR /F "delims=" %%i IN ('dir coredistools.dll /b/s') DO set __LibPath=%%i
+FOR /F "delims=" %%i IN ('dir %__PackageDir%\coredistools.dll /b/s') DO set __LibPath=%%i
if not exist "%__LibPath%" (
echo Failed to locate the downloaded library: %__LibPath%
- exit /b 1
+ goto Fail
)
REM Copy library to output directory
copy /y "%__LibPath%" "%__OutputDir%"
REM Delete temporary files
-del "%__JasonFilePath%"
+if exist "%__TmpDir%" (
+ rmdir /S /Q "%__TmpDir%"
+)
exit /b 0
+:Fail
+if exist "%__TmpDir%" (
+ rmdir /S /Q "%__TmpDir%"
+)
+exit /b 1
+
REM =========================================================================================
REM ===
REM === Helper routines
#!/usr/bin/env bash
+set -x
+#
+# Constants
+#
+readonly EXIT_CODE_SUCCESS=0
#
# This script should be located in coreclr/tests.
echo ''
}
+# temorary directory
+tmpDirPath=
+
+function exit_with_error {
+ local errorCode=$1
+ local errorMsg=$2
+
+ if [ ! -z "$2" ]; then
+ echo $2
+ fi
+
+ if [ -e $tmpDirPath ]; then
+ rm -rf $tmpDirPath
+ fi
+
+ exit $errorCode
+}
+
+function handle_ctrl_c {
+ exit_with_error 1 'Aborted by Ctrl+C'
+ }
+
+# Register the Ctrl-C handler
+trap handle_ctrl_c INT
+
# Argument variables
libInstallDir=
if [ -z "$libInstallDir" ]; then
echo "--libInstallDir is required."
print_usage
- exit $EXIT_CODE_EXCEPTION
+ exit_with_error 1
+fi
+
+# create temp directory
+tmpDirPath=`mktemp -d`
+if [ ! -e $tmpDirPath ]; then
+ exit_with_error 1 "Cannot create a temporary directory"
fi
# This script must be located in coreclr/tests.
dotnetToolsDir=$scriptDir/../Tools
dotnetCmd=${dotnetToolsDir}/dotnetcli/bin/dotnet
packageDir=${scriptDir}/../packages
-jsonFilePath=${scriptDir}/project.json
+jsonFilePath=${tmpDirPath}/project.json
# Check tool directory
if [ ! -e $dotnetToolsDir ]; then
- echo 'Directory containing dotnet commandline does not exist:' $dotnetToolsDir
- exit 1
+ exit_with_error 1 'Directory containing dotnet commandline does not exist:'$dotnetToolsDir
fi
if [ ! -e $dotnetCmd ]; then
- echo 'donet commandline does not exist:' $dotnetCmd
- exit 1
+ exit_with_error 1 'donet commandline does not exist:'$dotnetCmd
fi
# make package directory
# Download the package
echo Downloading CoreDisTools package
bash -c -x "$dotnetCmd restore $jsonFilePath --source https://dotnet.myget.org/F/dotnet-core/ --packages $packageDir"
+if [ $? -ne 0 ]
+then
+ exit_with_error 1 "Failed to restore the package"
+fi
# Get library path
libPath=`find $packageDir | grep -m 1 libcoredistools`
if [ ! -e $libPath ]; then
- echo 'Failed to locate the downloaded library'
- exit 1
+ exit_with_error 1 'Failed to locate the downloaded library'
fi
# Copy library to output directory
echo 'Copy library:' $libPath '-->' $libInstallDir/
cp -f $libPath $libInstallDir
+if [ $? -ne 0 ]
+then
+ exit_with_error 1 "Failed to copy the library"
+fi
# Delete temporary files
-rm -rf $jsonFilePath
+rm -rf $tmpDirPath
# Return success
-exit 0
+exit $EXIT_CODE_SUCCESS