[Tizen] Update build tools to 2.1.0-rc1-03006-01
[platform/upstream/coreclr.git] / packages / microsoft.dotnet.buildtools / 2.1.0-rc1-03006-01 / lib / crossgen.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 # Restores crossgen and runs it on all tools components.
5 usage()
6 {
7     echo "crossgen.sh <directory>"
8     echo "    Restores crossgen and runs it on all assemblies in <directory>."
9     exit 0
10 }
11
12 restore_crossgen()
13 {
14     __crossgen=$__sharedFxDir/crossgen
15     if [ -e $__crossgen ]; then
16         return
17     fi
18
19     __pjDir=$__toolsDir/crossgen
20     mkdir -p $__pjDir
21     echo "<Project Sdk=\"Microsoft.NET.Sdk\"><PropertyGroup><DisableImplicitNuGetFallbackFolder>false</DisableImplicitNuGetFallbackFolder><TreatWarningsAsErrors>false</TreatWarningsAsErrors><NoWarn>\$(NoWarn);NU1605;NU1103</NoWarn><TargetFramework>netcoreapp2.0</TargetFramework><DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences><RuntimeIdentifiers>$__packageRid</RuntimeIdentifiers></PropertyGroup><ItemGroup><PackageReference Include=\"Microsoft.NETCore.App\" Version=\"$__sharedFxVersion\" /></ItemGroup></Project>" > "$__pjDir/crossgen.csproj"
22     $__dotnet restore $__pjDir/crossgen.csproj --packages $__packagesDir --source $__MyGetFeed
23     __crossgen=$__packagesDir/runtime.$__packageRid.microsoft.netcore.app/$__sharedFxVersion/tools/crossgen
24     if [ ! -e $__crossgen ]; then
25         echo "The crossgen executable could not be found at "$__crossgen". Aborting crossgen.sh."
26         exit 1
27     fi
28     # Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424
29     chmod +x $__crossgen
30 }
31
32 crossgen_everything()
33 {
34     echo "Running crossgen on all assemblies in $__targetDir."
35     for file in $__targetDir/*.{dll,exe}
36     do
37         if [ $(basename $file) != "Microsoft.Build.Framework.dll" ]; then
38             crossgen_single $file & pid=$!
39             __pids+=" $pid"
40         fi
41     done
42
43     trap "kill $__pids 2&> /dev/null" SIGINT
44     wait $__pids
45     echo "Crossgen finished."
46 }
47
48 crossgen_single()
49 {
50     __file=$1
51     if [[ $__file != *.ni.dll && $__file != *.ni.exe ]]; then
52         if [[ ($__file == *.dll && -e ${__file/.dll/.ni.dll}) || ($__file == *.exe && -e ${__file/.exe/.ni.exe}) ]]; then
53             echo "$__file has already been crossgen'd.  Skipping."
54         else
55             set +e
56             $__crossgen /Platform_Assemblies_Paths $__sharedFxDir:$__toolsDir /JitPath $__sharedFxDir/libclrjit.$__libraryExtension /nologo /MissingDependenciesOK /ReadyToRun $__file > /dev/null
57             if [ $? -eq 0 ]; then
58                 __outname="${__file/.dll/.ni.dll}"
59                 __outname="${__outname/.exe/.ni.exe}"
60                 echo "$__file -> $__outname"
61             else
62                 echo "Unable to successfully compile $__file"
63             fi
64             set -e
65         fi
66     fi
67 }
68
69 if [ ! -z ${BUILDTOOLS_SKIP_CROSSGEN:-} ]; then
70     echo "BUILDTOOLS_SKIP_CROSSGEN is set. Skipping crossgen step."
71     exit 0
72 fi
73
74 if [[ -z "${1:-}" || "$1" == "-?" || "$1" == "--help" || "$1" == "-h" ]]; then
75     usage
76 fi
77
78 __MyGetFeed=${BUILDTOOLS_CROSSGEN_FEED:-https://dotnet.myget.org/F/dotnet-core/api/v3/index.json}
79 __targetDir=$1
80 __scriptpath=$(cd "$(dirname "$0")"; pwd -P)
81 __toolsDir=$__scriptpath/../Tools
82 __dotnet=$__toolsDir/dotnetcli/dotnet
83 __packagesDir="${NUGET_PACKAGES:-${__scriptpath}/../packages}"
84 __mncaFolder=$__toolsDir/dotnetcli/shared/Microsoft.NETCore.App
85 __sharedFxVersion=`ls $__mncaFolder | sed 'r/\([0-9]\+\).*/\1/g' | sort -n | tail -1`
86 __sharedFxDir=$__toolsDir/dotnetcli/shared/Microsoft.NETCore.App/$__sharedFxVersion/
87
88 case $(uname -s) in
89     Darwin)
90         __packageRid=osx-x64
91         __libraryExtension=dylib
92         ;;
93     Linux)
94         __packageRid=linux-x64
95         __libraryExtension=so
96         ;;
97     *)
98         echo "Unsupported OS $(uname -s) detected. Skipping crossgen of the toolset."
99         exit 0
100         ;;
101 esac
102
103 restore_crossgen
104 crossgen_everything
105 exit 0