Enable more hw intrinsics for AOT (#17160)
[mono-project.git] / eng / common / init-tools-native.sh
blob4dafaaca130f2dc0c6eed8daf706a2f05f92316e
1 #!/usr/bin/env bash
3 source="${BASH_SOURCE[0]}"
4 scriptroot="$( cd -P "$( dirname "$source" )" && pwd )"
6 base_uri='https://netcorenativeassets.blob.core.windows.net/resource-packages/external'
7 install_directory=''
8 clean=false
9 force=false
10 download_retries=5
11 retry_wait_time_seconds=30
12 global_json_file="$(dirname "$(dirname "${scriptroot}")")/global.json"
13 declare -A native_assets
15 . $scriptroot/native/common-library.sh
17 while (($# > 0)); do
18 lowerI="$(echo $1 | awk '{print tolower($0)}')"
19 case $lowerI in
20 --baseuri)
21 base_uri=$2
22 shift 2
24 --installdirectory)
25 install_directory=$2
26 shift 2
28 --clean)
29 clean=true
30 shift 1
32 --force)
33 force=true
34 shift 1
36 --downloadretries)
37 download_retries=$2
38 shift 2
40 --retrywaittimeseconds)
41 retry_wait_time_seconds=$2
42 shift 2
44 --help)
45 echo "Common settings:"
46 echo " --installdirectory Directory to install native toolset."
47 echo " This is a command-line override for the default"
48 echo " Install directory precedence order:"
49 echo " - InstallDirectory command-line override"
50 echo " - NETCOREENG_INSTALL_DIRECTORY environment variable"
51 echo " - (default) %USERPROFILE%/.netcoreeng/native"
52 echo ""
53 echo " --clean Switch specifying not to install anything, but cleanup native asset folders"
54 echo " --force Clean and then install tools"
55 echo " --help Print help and exit"
56 echo ""
57 echo "Advanced settings:"
58 echo " --baseuri <value> Base URI for where to download native tools from"
59 echo " --downloadretries <value> Number of times a download should be attempted"
60 echo " --retrywaittimeseconds <value> Wait time between download attempts"
61 echo ""
62 exit 0
64 esac
65 done
67 function ReadGlobalJsonNativeTools {
68 # Get the native-tools section from the global.json.
69 local native_tools_section=$(cat $global_json_file | awk '/"native-tools"/,/}/')
70 # Only extract the contents of the object.
71 local native_tools_list=$(echo $native_tools_section | awk -F"[{}]" '{print $2}')
72 native_tools_list=${native_tools_list//[\" ]/}
73 native_tools_list=$( echo "$native_tools_list" | sed 's/\s//g' | sed 's/,/\n/g' )
75 local old_IFS=$IFS
76 while read -r line; do
77 # Lines are of the form: 'tool:version'
78 IFS=:
79 while read -r key value; do
80 native_assets[$key]=$value
81 done <<< "$line"
82 done <<< "$native_tools_list"
83 IFS=$old_IFS
85 return 0;
88 native_base_dir=$install_directory
89 if [[ -z $install_directory ]]; then
90 native_base_dir=$(GetNativeInstallDirectory)
93 install_bin="${native_base_dir}/bin"
95 ReadGlobalJsonNativeTools
97 if [[ ${#native_assets[@]} -eq 0 ]]; then
98 echo "No native tools defined in global.json"
99 exit 0;
100 else
101 native_installer_dir="$scriptroot/native"
102 for tool in "${!native_assets[@]}"
104 tool_version=${native_assets[$tool]}
105 installer_name="install-$tool.sh"
106 installer_command="$native_installer_dir/$installer_name"
107 installer_command+=" --baseuri $base_uri"
108 installer_command+=" --installpath $install_bin"
109 installer_command+=" --version $tool_version"
110 echo $installer_command
112 if [[ $force = true ]]; then
113 installer_command+=" --force"
116 if [[ $clean = true ]]; then
117 installer_command+=" --clean"
120 $installer_command
122 if [[ $? != 0 ]]; then
123 echo "Execution Failed" >&2
124 exit 1
126 done
129 if [[ $clean = true ]]; then
130 exit 0
133 if [[ -d $install_bin ]]; then
134 echo "Native tools are available from $install_bin"
135 echo "##vso[task.prependpath]$install_bin"
136 else
137 echo "Native tools install directory does not exist, installation failed" >&2
138 exit 1
141 exit 0