7 readonly EXIT_CODE_SUCCESS=0
10 # This script should be located in coreclr/tests.
13 function print_usage {
15 echo 'Download coredistools for GC stress testing'
19 echo './setup-gcstress.sh --outputDir=<coredistools_lib_install_path>'
21 echo 'Required arguments:'
22 echo ' --outputDir=<path> : Directory to install libcoredistools.so'
29 function exit_with_error {
33 if [ ! -z "$2" ]; then
37 if [ -e $tmpDirPath ]; then
44 function handle_ctrl_c {
45 exit_with_error 1 'Aborted by Ctrl+C'
48 # Register the Ctrl-C handler
49 trap handle_ctrl_c INT
60 exit $EXIT_CODE_SUCCESS
69 echo "Unknown switch: $i"
71 exit $EXIT_CODE_SUCCESS
76 if [ -z "$libInstallDir" ]; then
77 echo "--libInstallDir is required."
82 # create temp directory
83 tmpDirPath=`mktemp -d`
84 if [ ! -e $tmpDirPath ]; then
85 exit_with_error 1 "Cannot create a temporary directory"
88 # This script must be located in coreclr/tests.
89 scriptDir=$(cd "$(dirname "$0")"; pwd -P)
91 echo "Running init-tools.sh"
92 $scriptDir/../init-tools.sh
94 dotnetToolsDir=$scriptDir/../Tools
95 dotnetCmd=${dotnetToolsDir}/dotnetcli/dotnet
96 packageDir=${scriptDir}/../packages
97 jsonFilePath=${tmpDirPath}/project.json
99 # Check tool directory
100 if [ ! -e $dotnetToolsDir ]; then
101 exit_with_error 1 'Directory containing dotnet commandline does not exist:'$dotnetToolsDir
103 if [ ! -e $dotnetCmd ]; then
104 exit_with_error 1 'dotnet commandline does not exist:'$dotnetCmd
107 # make package directory
108 if [ ! -e $packageDir ]; then
112 # make output directory
113 if [ ! -e $libInstallDir ]; then
114 mkdir -p $libInstallDir
118 rid=`$dotnetCmd --info | grep 'RID:' | sed 's/^ *RID: *//g'`
119 if [ -z "$rid" ]; then
120 exit_with_error 1 "Failed to query runtime Id"
123 # Write dependency information to project.json
124 packageName='runtime.'$rid'.Microsoft.NETCore.CoreDisTools'
126 \"dependencies\": { \
127 \"$packageName\": \"1.0.1-prerelease-*\" \
129 \"frameworks\": { \"dnxcore50\": { } } \
132 # Download the package
133 echo Downloading CoreDisTools package
134 bash -c -x "$dotnetCmd restore $jsonFilePath --source https://dotnet.myget.org/F/dotnet-core/ --packages $packageDir"
137 exit_with_error 1 "Failed to restore the package"
141 libPath=`find $packageDir | grep $rid | grep -m 1 libcoredistools`
142 if [ ! -e $libPath ]; then
143 exit_with_error 1 'Failed to locate the downloaded library'
146 # Copy library to output directory
147 echo 'Copy library:' $libPath '-->' $libInstallDir/
148 cp -f $libPath $libInstallDir
151 exit_with_error 1 "Failed to copy the library"
154 # Delete temporary files
158 exit $EXIT_CODE_SUCCESS