2016-02-26 02:46:30 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-02-09 01:18:44 +03:00
|
|
|
# Colors
|
|
|
|
GREEN="\033[1;32m"
|
|
|
|
CYAN="\033[0;36m"
|
|
|
|
RESET="\033[0m"
|
|
|
|
RED="\033[0;31m"
|
|
|
|
|
|
|
|
# functions
|
|
|
|
|
|
|
|
__exec() {
|
|
|
|
local cmd=$1
|
|
|
|
shift
|
|
|
|
|
|
|
|
local cmdname=$(basename $cmd)
|
|
|
|
echo -e "${CYAN}> $cmdname $@${RESET}"
|
|
|
|
$cmd "$@"
|
|
|
|
|
|
|
|
local exitCode=$?
|
|
|
|
if [ $exitCode -ne 0 ]; then
|
|
|
|
echo -e "${RED}'$cmdname $@' failed with exit code $exitCode${RESET}" 1>&2
|
|
|
|
exit $exitCode
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-26 02:46:30 +03:00
|
|
|
targets=""
|
2016-02-25 21:24:25 +03:00
|
|
|
repoFolder=""
|
2016-02-26 02:46:30 +03:00
|
|
|
while [[ $# > 0 ]]; do
|
|
|
|
case $1 in
|
2016-02-25 21:24:25 +03:00
|
|
|
-r)
|
2016-02-26 02:46:30 +03:00
|
|
|
shift
|
2016-02-25 21:24:25 +03:00
|
|
|
repoFolder=$1
|
2016-02-26 02:46:30 +03:00
|
|
|
;;
|
|
|
|
*)
|
2017-02-06 20:24:40 +03:00
|
|
|
if [ -z "$targets" ]; then
|
2017-02-09 01:18:44 +03:00
|
|
|
targets="$1"
|
2017-02-06 20:24:40 +03:00
|
|
|
else
|
2017-02-09 01:18:44 +03:00
|
|
|
targets+=":$1"
|
2017-02-06 20:24:40 +03:00
|
|
|
fi
|
2016-02-26 02:46:30 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2016-02-25 21:24:25 +03:00
|
|
|
if [ ! -e "$repoFolder" ]; then
|
|
|
|
printf "Usage: $filename -r [repoFolder] [ [targets] ]\n\n"
|
|
|
|
echo " -r [repo] The repository to build"
|
|
|
|
echo " [targets] A space separated list of targets to run"
|
2016-02-26 02:46:30 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-25 21:24:25 +03:00
|
|
|
echo "Building $repoFolder"
|
|
|
|
cd $repoFolder
|
2016-02-26 02:46:30 +03:00
|
|
|
|
2016-03-29 02:18:27 +03:00
|
|
|
scriptRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2016-02-25 21:24:25 +03:00
|
|
|
# Make the path relative to the repo root because Sake/Spark doesn't support full paths
|
2016-03-29 02:18:27 +03:00
|
|
|
koreBuildFolder="${scriptRoot/$repoFolder/}"
|
2016-02-25 21:24:25 +03:00
|
|
|
koreBuildFolder="${koreBuildFolder#/}"
|
2016-02-26 02:46:30 +03:00
|
|
|
|
2016-12-13 00:05:37 +03:00
|
|
|
versionFile="$koreBuildFolder/cli.version"
|
2016-03-07 21:37:38 +03:00
|
|
|
version=$(<$versionFile)
|
2016-12-29 21:14:11 +03:00
|
|
|
sharedRuntimeVersionFile="$koreBuildFolder/shared-runtime.version"
|
2016-12-30 03:38:48 +03:00
|
|
|
sharedRuntimeVersion=$(<$sharedRuntimeVersionFile)
|
2016-03-04 01:16:50 +03:00
|
|
|
|
2017-02-16 04:07:33 +03:00
|
|
|
[ -z "$KOREBUILD_DOTNET_CHANNEL" ] && KOREBUILD_DOTNET_CHANNEL=rel-1.0.0
|
|
|
|
[ -z "$KOREBUILD_DOTNET_VERSION" ] && KOREBUILD_DOTNET_VERSION=$version
|
|
|
|
|
2016-12-01 04:17:13 +03:00
|
|
|
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
|
|
|
|
$koreBuildFolder/dotnet/dotnet-install.sh --shared-runtime --channel $channel --version $version
|
|
|
|
fi
|
|
|
|
}
|
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"
|
2016-03-04 02:30:06 +03:00
|
|
|
|
|
|
|
# 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
|
2016-02-25 21:24:25 +03:00
|
|
|
export KOREBUILD_FOLDER="$(dirname $koreBuildFolder)"
|
2016-05-31 20:02:29 +03:00
|
|
|
chmod +x $koreBuildFolder/dotnet/dotnet-install.sh
|
2016-03-28 20:52:47 +03:00
|
|
|
|
2017-02-16 04:07:33 +03:00
|
|
|
$koreBuildFolder/dotnet/dotnet-install.sh --channel $KOREBUILD_DOTNET_CHANNEL --version $KOREBUILD_DOTNET_VERSION
|
2016-03-04 02:30:06 +03:00
|
|
|
|
|
|
|
# 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"
|
2016-02-26 02:46:30 +03:00
|
|
|
fi
|
|
|
|
|
2016-04-03 04:20:32 +03:00
|
|
|
|
|
|
|
# workaround for CLI issue: https://github.com/dotnet/cli/issues/2143
|
|
|
|
DOTNET_PATH=`which dotnet | head -n 1`
|
|
|
|
ROOT_PATH=`dirname $DOTNET_PATH`
|
|
|
|
FOUND=`find $ROOT_PATH/shared -name dotnet`
|
|
|
|
if [ ! -z "$FOUND" ]; then
|
|
|
|
echo $FOUND | xargs rm
|
2016-04-01 19:12:15 +03:00
|
|
|
fi
|
|
|
|
|
2016-02-27 03:44:52 +03:00
|
|
|
if [ "$(uname)" == "Darwin" ]; then
|
|
|
|
ulimit -n 2048
|
|
|
|
fi
|
|
|
|
|
2017-02-03 04:53:30 +03:00
|
|
|
netfxversion='4.6.1'
|
2017-02-09 01:18:44 +03:00
|
|
|
if [ "$NUGET_PACKAGES" == "" ]; then
|
|
|
|
NUGET_PACKAGES="$HOME/.nuget/packages"
|
2016-02-25 21:24:25 +03:00
|
|
|
fi
|
2017-02-09 01:18:44 +03:00
|
|
|
export ReferenceAssemblyRoot=$NUGET_PACKAGES/netframeworkreferenceassemblies/$netfxversion/content
|
2016-11-17 03:22:50 +03:00
|
|
|
|
2016-03-04 00:09:25 +03:00
|
|
|
nugetPath="$koreBuildFolder/nuget.exe"
|
|
|
|
if [ ! -f $nugetPath ]; then
|
2017-02-09 01:18:44 +03:00
|
|
|
nugetUrl="https://dist.nuget.org/win-x86-commandline/v4.0.0-rc4/NuGet.exe"
|
2016-03-04 00:09:25 +03:00
|
|
|
wget -O $nugetPath $nugetUrl 2>/dev/null || curl -o $nugetPath --location $nugetUrl 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
2017-02-06 20:24:40 +03:00
|
|
|
export KOREBUILD_FOLDER="$koreBuildFolder"
|
2017-02-09 01:18:44 +03:00
|
|
|
makeFileProj="$koreBuildFolder/makefile.proj"
|
2017-02-06 20:24:40 +03:00
|
|
|
|
2017-02-09 01:18:44 +03:00
|
|
|
__exec dotnet restore "$makeFileProj" "/p:NetFxVersion=$netfxversion"
|
2017-02-06 20:24:40 +03:00
|
|
|
|
|
|
|
msbuildArtifactsDir="$repoFolder/artifacts/msbuild"
|
|
|
|
msbuildResponseFile="$msbuildArtifactsDir/msbuild.rsp"
|
|
|
|
msbuildLogFile="$msbuildArtifactsDir/msbuild.log"
|
|
|
|
|
|
|
|
if [ ! -f $msbuildArtifactsDir ]; then
|
|
|
|
mkdir -p $msbuildArtifactsDir
|
2016-02-25 21:24:25 +03:00
|
|
|
fi
|
|
|
|
|
2017-02-06 20:24:40 +03:00
|
|
|
cat > $msbuildResponseFile <<ENDMSBUILDARGS
|
|
|
|
/nologo
|
|
|
|
/m
|
|
|
|
"$makeFileProj"
|
|
|
|
/p:RepositoryRoot="$repoFolder/"
|
|
|
|
/fl
|
2017-02-09 01:18:44 +03:00
|
|
|
/flp:LogFile="$msbuildLogFile";Verbosity=diagnostic;Encoding=UTF-8
|
|
|
|
/p:SakeTargets=$targets
|
2017-02-06 20:24:40 +03:00
|
|
|
ENDMSBUILDARGS
|
|
|
|
|
2017-02-09 01:18:44 +03:00
|
|
|
__exec dotnet msbuild @"$msbuildResponseFile"
|