KoreBuild/build/KoreBuild.sh

174 строки
5.0 KiB
Bash
Исходник Обычный вид История

2016-02-26 02:46:30 +03:00
#!/usr/bin/env bash
set -o pipefail
2016-02-26 02:46:30 +03:00
2017-02-09 01:18:44 +03:00
# Colors
GREEN="\033[1;32m"
CYAN="\033[0;36m"
RESET="\033[0m"
RED="\033[0;31m"
2017-02-09 01:18:44 +03:00
# functions
__exec() {
local cmd=$1
shift
local cmdname=$(basename $cmd)
echo -e "${CYAN}> $cmdname $@${RESET}"
2017-05-03 02:52:07 +03:00
$cmd "$@"
2017-02-09 01:18:44 +03:00
local exitCode=$?
if [ $exitCode -ne 0 ]; then
echo -e "${RED}'$cmdname $@' failed with exit code $exitCode${RESET}" 1>&2
exit $exitCode
fi
}
msbuild_args=""
repoFolder=""
2016-02-26 02:46:30 +03:00
while [[ $# > 0 ]]; do
case $1 in
-r)
2016-02-26 02:46:30 +03:00
shift
repoFolder=$1
2016-02-26 02:46:30 +03:00
;;
*)
msbuild_args+="\"$1\"\n"
2016-02-26 02:46:30 +03:00
;;
esac
shift
done
if [ ! -e "$repoFolder" ]; then
printf "Usage: $filename -r [repoFolder] [ [msbuild-args] ]\n\n"
echo " -r [repo] The repository to build"
echo " [msbuild-args] A space separated list of arguments to pass to MSBuild"
2016-02-26 02:46:30 +03:00
exit 1
fi
echo "Building $repoFolder"
cd $repoFolder
2016-02-26 02:46:30 +03:00
scriptRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ "$(uname)" == "Darwin" ]; then
ulimit -n 2048
# Check that OS is 10.12 or newer
osx_version="$(sw_vers | grep ProductVersion | awk '{print $2}')"
minor_version="$(echo $osx_version | awk -F '.' '{print $2}')"
if [ $minor_version -lt 12 ]; then
echo -e "${RED}.NET Core 2.0 requires OSX 10.12 or newer. Current version is $osx_version.${RESET}"
exit 1
fi
fi
2017-03-07 21:21:56 +03:00
versionFile="$scriptRoot/cli.version"
2016-03-07 21:37:38 +03:00
version=$(<$versionFile)
2017-03-07 21:21:56 +03:00
sharedRuntimeVersionFile="$scriptRoot/shared-runtime.version"
2016-12-30 03:38:48 +03:00
sharedRuntimeVersion=$(<$sharedRuntimeVersionFile)
2016-03-04 01:16:50 +03:00
[ -z "$KOREBUILD_DOTNET_CHANNEL" ] && KOREBUILD_DOTNET_CHANNEL="preview"
[ -z "$KOREBUILD_DOTNET_VERSION" ] && KOREBUILD_DOTNET_VERSION=$version
[ -z "$KOREBUILD_DOTNET_SHARED_RUNTIME_CHANNEL" ] && KOREBUILD_DOTNET_SHARED_RUNTIME_CHANNEL="master"
[ -z "$KOREBUILD_DOTNET_SHARED_RUNTIME_VERSION" ] && KOREBUILD_DOTNET_SHARED_RUNTIME_VERSION=$sharedRuntimeVersion
install_shared_runtime() {
eval $invocation
local version=$1
local channel=$2
local sharedRuntimePath="$DOTNET_INSTALL_DIR/shared/Microsoft.NETCore.App/$version"
if [ ! -d "$sharedRuntimePath" ]; then
$scriptRoot/dotnet/dotnet-install.sh \
--shared-runtime \
--channel $channel \
--version $version
if [ $? -ne 0 ]; then
exit 1
fi
fi
}
2016-02-26 02:46:30 +03:00
build_taskproject() {
local taskProj="$repoFolder/build/tasks/RepoTasks.csproj"
local publishFolder="$repoFolder/build/tasks/bin/publish/"
if [[ ! -f $taskProj ]]; then
# skipping
return
2017-06-03 01:23:09 +03:00
fi
if [[ -d $publishFolder ]]; then
rm -rf $publishFolder
fi
__exec dotnet restore $taskProj
__exec dotnet publish $taskProj --configuration Release --output $publishFolder
}
2016-02-26 02:46:30 +03:00
if [ ! -z "$KOREBUILD_SKIP_RUNTIME_INSTALL" ]; then
echo "Skipping runtime installation because KOREBUILD_SKIP_RUNTIME_INSTALL is set"
# Add .NET installation directory to the path if it isn't yet included.
# Add to the _end_ in case preferred .NET CLI is not in the default location.
2016-04-03 04:20:32 +03:00
[[ ":$PATH:" != *":$DOTNET_INSTALL_DIR:"* ]] && export PATH="$PATH:$DOTNET_INSTALL_DIR"
2016-02-26 02:46:30 +03:00
else
# Need to set this variable because by default the install script
# requires sudo
2016-11-08 21:30:03 +03:00
[ -z "$DOTNET_INSTALL_DIR" ] && DOTNET_INSTALL_DIR=~/.dotnet
export DOTNET_INSTALL_DIR=$DOTNET_INSTALL_DIR
2017-03-07 21:21:56 +03:00
chmod +x $scriptRoot/dotnet/dotnet-install.sh
2016-03-28 20:52:47 +03:00
# Temporarily install these runtimes to prevent build breaks for repos not yet converted
# 1.0.5 - for tools
install_shared_runtime "1.0.5" "preview"
# 1.1.2 - for test projects which haven't yet been converted to netcoreapp2.0
install_shared_runtime "1.1.2" "release/1.1.0"
if [ "$sharedRuntimeVersion" != "" ]; then
install_shared_runtime $KOREBUILD_DOTNET_SHARED_RUNTIME_VERSION $KOREBUILD_DOTNET_SHARED_RUNTIME_CHANNEL
fi
$scriptRoot/dotnet/dotnet-install.sh \
--channel $KOREBUILD_DOTNET_CHANNEL \
--version $KOREBUILD_DOTNET_VERSION
if [ $? -ne 0 ]; then
exit 1
fi
# Add .NET installation directory to the path if it isn't yet included.
2016-04-03 04:20:32 +03:00
[[ ":$PATH:" != *":$DOTNET_INSTALL_DIR:"* ]] && export PATH="$DOTNET_INSTALL_DIR:$PATH"
fi
2016-04-03 04:20:32 +03:00
netfxversion='4.6.1'
2017-02-09 01:18:44 +03:00
if [ "$NUGET_PACKAGES" == "" ]; then
NUGET_PACKAGES="$HOME/.nuget/packages"
fi
2017-02-09 01:18:44 +03:00
export ReferenceAssemblyRoot=$NUGET_PACKAGES/netframeworkreferenceassemblies/$netfxversion/content
2016-11-17 03:22:50 +03:00
2017-03-07 21:21:56 +03:00
makeFileProj="$scriptRoot/KoreBuild.proj"
msbuildArtifactsDir="$repoFolder/artifacts/msbuild"
msbuildResponseFile="$msbuildArtifactsDir/msbuild.rsp"
msbuildLogFile="$msbuildArtifactsDir/msbuild.binlog"
if [ ! -f $msbuildArtifactsDir ]; then
mkdir -p $msbuildArtifactsDir
fi
cat > $msbuildResponseFile <<ENDMSBUILDARGS
/nologo
/m
/p:RepositoryRoot="$repoFolder/"
2017-06-07 02:16:33 +03:00
/fl /flp:verbosity=diagnostic
2017-05-03 02:52:07 +03:00
/clp:Summary
"$makeFileProj"
ENDMSBUILDARGS
echo -e "$msbuild_args" >> $msbuildResponseFile
build_taskproject
2017-05-03 02:52:07 +03:00
__exec dotnet restore /p:PreflightRestore=true /p:NetFxVersion=$netfxversion "$makeFileProj"
2017-02-09 01:18:44 +03:00
__exec dotnet msbuild @"$msbuildResponseFile"