Merge pull request #3244 from erozenfeld/SIMDInit
[platform/upstream/coreclr.git] / init-tools.sh
1 #!/usr/bin/env bash
2
3 initDistroName()
4 {
5     if [ "$1" == "Linux" ]; then
6         # Detect Distro
7         if [ "$(cat /etc/*-release | grep -cim1 ubuntu)" -eq 1 ]; then
8             export __DistroName=ubuntu
9         elif [ "$(cat /etc/*-release | grep -cim1 centos)" -eq 1 ]; then
10             export __DistroName=centos
11         elif [ "$(cat /etc/*-release | grep -cim1 rhel)" -eq 1 ]; then
12             export __DistroName=rhel
13         elif [ "$(cat /etc/*-release | grep -cim1 debian)" -eq 1 ]; then
14             export __DistroName=debian
15         else
16             export __DistroName=""
17         fi
18     fi
19 }
20
21 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
22
23 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
24 # This is needed by CLI to function.
25 if [ -z "$HOME" ]; then
26     if [ ! -d "$__scriptpath/temp_home" ]; then
27         mkdir temp_home
28     fi
29     export HOME=$__scriptpath/temp_home
30     echo "HOME not defined; setting it to $HOME"
31 fi
32
33 __PACKAGES_DIR=$__scriptpath/packages
34 __TOOLRUNTIME_DIR=$__scriptpath/Tools
35 __DOTNET_PATH=$__TOOLRUNTIME_DIR/dotnetcli
36 __DOTNET_CMD=$__DOTNET_PATH/bin/dotnet
37 if [ -z "$__BUILDTOOLS_SOURCE" ]; then __BUILDTOOLS_SOURCE=https://www.myget.org/F/dotnet-buildtools/; fi
38 __BUILD_TOOLS_PACKAGE_VERSION=$(cat $__scriptpath/BuildToolsVersion.txt)
39 __DOTNET_TOOLS_VERSION=$(cat $__scriptpath/DotnetCLIVersion.txt)
40 __BUILD_TOOLS_PATH=$__PACKAGES_DIR/Microsoft.DotNet.BuildTools/$__BUILD_TOOLS_PACKAGE_VERSION/lib
41 __PROJECT_JSON_PATH=$__TOOLRUNTIME_DIR/$__BUILD_TOOLS_PACKAGE_VERSION
42 __PROJECT_JSON_FILE=$__PROJECT_JSON_PATH/project.json
43 __PROJECT_JSON_CONTENTS="{ \"dependencies\": { \"Microsoft.DotNet.BuildTools\": \"$__BUILD_TOOLS_PACKAGE_VERSION\" }, \"frameworks\": { \"dnxcore50\": { } } }"
44 __DistroName=""
45
46 OSName=$(uname -s)
47 case $OSName in
48     Darwin)
49         OS=OSX
50         __DOTNET_PKG=dotnet-osx-x64
51         ;;
52
53     Linux)
54         OS=Linux
55         __DOTNET_PKG=dotnet-ubuntu-x64
56         ;;
57
58     *)
59         echo "Unsupported OS $OSName detected. Downloading ubuntu-x64 tools"
60         OS=Linux
61         __DOTNET_PKG=dotnet-ubuntu-x64
62         ;;
63 esac
64
65 # Initialize Linux Distribution name and .NET CLI package name.
66
67 initDistroName $OS
68 if [ "$__DistroName" == "centos" ]; then
69     __DOTNET_PKG=dotnet-centos-x64
70 fi
71
72 __CLIDownloadURL=https://dotnetcli.blob.core.windows.net/dotnet/dev/Binaries/${__DOTNET_TOOLS_VERSION}/${__DOTNET_PKG}.${__DOTNET_TOOLS_VERSION}.tar.gz
73 echo ".NET CLI will be downloaded from $__CLIDownloadURL"
74
75 if [ ! -e $__PROJECT_JSON_FILE ]; then
76  if [ -e $__TOOLRUNTIME_DIR ]; then rm -rf -- $__TOOLRUNTIME_DIR; fi
77
78  if [ ! -e $__DOTNET_PATH ]; then
79     # curl has HTTPS CA trust-issues less often than wget, so lets try that first.
80     which curl > /dev/null 2> /dev/null
81     if [ $? -ne 0 ]; then
82       mkdir -p "$__DOTNET_PATH"
83       wget -q -O $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
84     else
85       curl -sSL --create-dirs -o $__DOTNET_PATH/dotnet.tar $__CLIDownloadURL
86     fi
87     cd $__DOTNET_PATH
88     tar -xf $__DOTNET_PATH/dotnet.tar
89     if [ -n "$BUILDTOOLS_OVERRIDE_RUNTIME" ]; then
90         find $__DOTNET_PATH -name *.ni.* | xargs rm 2>/dev/null
91         cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin
92         cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/bin/dnx
93         cp -R $BUILDTOOLS_OVERRIDE_RUNTIME/* $__DOTNET_PATH/runtime/coreclr
94     fi
95
96     cd $__scriptpath
97  fi
98
99  mkdir "$__PROJECT_JSON_PATH"
100  echo $__PROJECT_JSON_CONTENTS > "$__PROJECT_JSON_FILE"
101
102  if [ ! -e $__BUILD_TOOLS_PATH ]; then
103     $__DOTNET_CMD restore "$__PROJECT_JSON_FILE" --packages $__PACKAGES_DIR --source $__BUILDTOOLS_SOURCE
104  fi
105
106  sh $__BUILD_TOOLS_PATH/init-tools.sh $__scriptpath $__DOTNET_CMD $__TOOLRUNTIME_DIR
107  chmod a+x $__TOOLRUNTIME_DIR/corerun
108 fi