Update SDK used to build jitutils to 2.1 RC (#18290)
[platform/upstream/coreclr.git] / tests / setup-stress-dependencies.sh
1 #!/usr/bin/env bash
2 # set -x
3
4 #
5 # Constants
6 #
7 readonly EXIT_CODE_SUCCESS=0
8
9 #
10 # This script should be located in coreclr/tests.
11 #
12
13 function print_usage {
14     echo ''
15     echo 'Download coredistools for GC stress testing'
16     echo ''
17     echo 'Command line:'
18     echo ''
19     echo './setup-gcstress.sh --outputDir=<coredistools_lib_install_path>'
20     echo ''
21     echo 'Required arguments:'
22     echo '  --outputDir=<path>         : Directory to install libcoredistools.so'
23     echo ''
24 }
25
26 function exit_with_error {
27     local errorCode=$1
28     local errorMsg=$2
29
30     if [ ! -z "$2" ]; then
31         echo $2
32     fi
33     
34     exit $errorCode
35 }
36
37 function handle_ctrl_c {
38     exit_with_error 1 'Aborted by Ctrl+C'
39  }
40
41 # Register the Ctrl-C handler
42 trap handle_ctrl_c INT
43
44 # Argument variables
45 libInstallDir=
46
47 # Handle arguments
48 verbose=0
49 for i in "$@"
50 do
51     case $i in
52         -h|--help)
53             exit $EXIT_CODE_SUCCESS
54             ;;
55         -v|--verbose)
56             verbose=1
57             ;;
58         --outputDir=*)
59             libInstallDir=${i#*=}
60             ;;
61         *)
62             echo "Unknown switch: $i"
63             print_usage
64             exit $EXIT_CODE_SUCCESS
65             ;;
66     esac
67 done
68
69 if [ -z "$libInstallDir" ]; then
70     echo "--libInstallDir is required."
71     print_usage
72     exit_with_error 1
73 fi
74
75 # This script must be located in coreclr/tests.
76 scriptDir=$(cd "$(dirname "$0")"; pwd -P)
77
78 echo "Running init-tools.sh"
79 $scriptDir/../init-tools.sh
80
81 dotnetToolsDir=$scriptDir/../Tools
82 dotnetCmd=${dotnetToolsDir}/dotnetcli/dotnet
83 packageDir=${scriptDir}/../packages
84 csprojPath=${scriptDir}/src/Common/stress_dependencies/stress_dependencies.csproj
85
86 # Check tool directory
87 if [ ! -e $dotnetToolsDir ]; then
88     exit_with_error 1 'Directory containing dotnet commandline does not exist:'$dotnetToolsDir 
89 fi
90 if [ ! -e $dotnetCmd ]; then
91     exit_with_error 1 'dotnet commandline does not exist:'$dotnetCmd
92 fi
93
94 # make package directory
95 if [ ! -e $packageDir ]; then
96     mkdir -p $packageDir
97 fi
98
99 # make output directory
100 if [ ! -e $libInstallDir ]; then
101     mkdir -p $libInstallDir
102 fi
103
104 # Query runtime Id
105 rid=`$dotnetCmd --info | grep 'RID:' | sed 's/^ *RID: *//g'`  
106 if [ -z "$rid" ]; then
107     exit_with_error 1 "Failed to query runtime Id"
108 fi    
109
110 # Download the package
111 echo Downloading CoreDisTools package
112 bash -c -x "$dotnetCmd restore $csprojPath --source https://dotnet.myget.org/F/dotnet-core/ --packages $packageDir"
113 if [ $? -ne 0 ]
114 then
115     exit_with_error 1 "Failed to restore the package"
116 fi
117
118 # Get library path
119 libPath=`find $packageDir | grep $rid | grep -m 1 libcoredistools`
120 if [ ! -e $libPath ]; then
121     exit_with_error 1 'Failed to locate the downloaded library'
122 fi
123
124 # Copy library to output directory
125 echo 'Copy library:' $libPath '-->' $libInstallDir/
126 cp -f $libPath $libInstallDir
127 if [ $? -ne 0 ]
128 then
129     exit_with_error 1 "Failed to copy the library"
130 fi
131
132 # Return success
133 exit $EXIT_CODE_SUCCESS