Fix setup-runtime-dependencies.cmd
authorSejong Oh <sejooh@microsoft.com>
Tue, 15 Mar 2016 20:56:41 +0000 (13:56 -0700)
committerSejong OH <sejooh@microsoft.com>
Wed, 16 Mar 2016 23:58:30 +0000 (16:58 -0700)
tests/setup-runtime-dependencies.cmd [changed mode: 0644->0755]
tests/setup-runtime-dependencies.sh

old mode 100644 (file)
new mode 100755 (executable)
index e7d6099..6c7f6d1
@@ -42,22 +42,30 @@ REM ============================================================================
 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 ===
@@ -75,15 +83,16 @@ echo { ^
 
 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
@@ -91,10 +100,18 @@ echo Copy library: %__LibPath% to %__OutputDir%
 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
index 9bd1003e54527ef81616f10c4b4a08a2bdc4cb9d..17fbb16334a39ba9968dbe00a8a5f050143c8771 100755 (executable)
@@ -1,4 +1,9 @@
 #!/usr/bin/env bash
+set -x
+#
+# Constants
+#
+readonly EXIT_CODE_SUCCESS=0
 
 #
 # This script should be located in coreclr/tests.
@@ -17,6 +22,31 @@ function print_usage {
     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=
 
@@ -45,7 +75,13 @@ done
 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.
@@ -53,16 +89,14 @@ scriptDir=$(cd "$(dirname "$0")"; pwd -P)
 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
@@ -86,21 +120,28 @@ echo {  \
 # 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