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)
90 dotnetToolsDir=$scriptDir/../Tools
91 dotnetCmd=${dotnetToolsDir}/dotnetcli/dotnet
92 packageDir=${scriptDir}/../packages
93 jsonFilePath=${tmpDirPath}/project.json
95 # Check tool directory
96 if [ ! -e $dotnetToolsDir ]; then
97 exit_with_error 1 'Directory containing dotnet commandline does not exist:'$dotnetToolsDir
99 if [ ! -e $dotnetCmd ]; then
100 exit_with_error 1 'dotnet commandline does not exist:'$dotnetCmd
103 # make package directory
104 if [ ! -e $packageDir ]; then
108 # make output directory
109 if [ ! -e $libInstallDir ]; then
110 mkdir -p $libInstallDir
114 rid=`$dotnetCmd --info | grep 'RID:' | sed 's/^ *RID: *//g'`
115 if [ -z "$rid" ]; then
116 exit_with_error 1 "Failed to query runtime Id"
119 # Write dependency information to project.json
120 packageName='runtime.'$rid'.Microsoft.NETCore.CoreDisTools'
122 \"dependencies\": { \
123 \"$packageName\": \"1.0.1-prerelease-*\" \
125 \"frameworks\": { \"dnxcore50\": { } } \
128 # Download the package
129 echo Downloading CoreDisTools package
130 bash -c -x "$dotnetCmd restore $jsonFilePath --source https://dotnet.myget.org/F/dotnet-core/ --packages $packageDir"
133 exit_with_error 1 "Failed to restore the package"
137 libPath=`find $packageDir | grep $rid | grep -m 1 libcoredistools`
138 if [ ! -e $libPath ]; then
139 exit_with_error 1 'Failed to locate the downloaded library'
142 # Copy library to output directory
143 echo 'Copy library:' $libPath '-->' $libInstallDir/
144 cp -f $libPath $libInstallDir
147 exit_with_error 1 "Failed to copy the library"
150 # Delete temporary files
154 exit $EXIT_CODE_SUCCESS