From: WonYoung Choi Date: Thu, 5 Jan 2017 06:08:28 +0000 (+0900) Subject: Add dotnet-build.sh and fix macros X-Git-Tag: submit/tizen/20170105.060951^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec387ebb8c8f011df339adf4c2de93e79e842b4a;p=platform%2Fcore%2Fdotnet%2Fbuild-tools.git Add dotnet-build.sh and fix macros Change-Id: Ibd6034931d67d8f30af9b203f86f19cb2c2f926f --- diff --git a/Tools/dotnet-build.sh b/Tools/dotnet-build.sh new file mode 100755 index 00000000..c0fe8d14 --- /dev/null +++ b/Tools/dotnet-build.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +# Usages: +# dotnet-build.sh build [Target] [Configuration] +# dotnet-build.sh pack [NuSpec] [Version] + +usage() { + echo "Usage:" + echo " $0 restore TARGET" + echo " - TARGET : Project Directory, Solution File(.sln), Project JSON(.project.json)" + echo " $0 build TARGET CONFIGURATION" + echo " - TARGET : Project Directory, Solution File(.sln), Project File(.csproj)" + echo " - CONFIGURATION : Configuration name defined in .csproj (Debug, Release)" + echo " $0 pack NUSPEC VERSION CONFIGURATION" + echo " - NUSPEC : .nuspec file path" + echo " - VERSION : Version of nuget package to be created" + echo " - CONFIGURATION : Configuration name defined in .csproj (Debug, Release)" +} + +exit_on_error() { + if [ $1 -ne 0 ]; then + echo "Error $1" + exit $1 + fi +} + +nuget_retry() { + local RETRY=3 + local RET=0 + local n=0 + until [ $n -ge $RETRY ]; do + if [ $n -gt 0 ]; then + sleep 2 + echo "Retry $n ....." + fi + echo "+ nuget $@" + nuget $@ + RET=$? + if [ $RET -eq 0 ]; then + break + fi + n=$[$n+1] + done + exit_on_error $RET +} + +cs_build() { + echo "+ xbuild $@" + xbuild $@ + exit_on_error $? +} + +restore() { + local TARGET=$1; shift + + if [[ $TARGET == *".sln" ]]; then + nuget_retry restore $TARGET $@ + elif [[ $TARGET == *".project.json" ]]; then + nuget_retry restore $TARGET $@ + else + local PROJFILES=$(find $TARGET -name "*.project.json") + for P in $PROJFILES; do + nuget_retry restore $P $@ + done + fi +} + +build_solution() { + local TARGET=$1; shift + local CONFIGURATION=$1; shift + + cs_build $TARGET /p:Configuration=$CONFIGURATION $@ +} + +build_project() { + local TARGET=$1; shift + local CONFIGURATION=$1; shift + + local PROJECT=${TARGET%.*} + local PROJECT_JSON=$PROJECT.project.json + if [ -f $PROJECT_JSON ]; then + restore $PROJECT_JSON + fi + cs_build $TARGET /p:Configuration=$CONFIGURATION $@ +} + +build() { + local TARGET=$1; shift + local CONFIGURATION=$1; shift + + if [[ $TARGET == *".sln" ]]; then + build_solution $TARGET $CONFIGURATION $@ + elif [[ $TARGET == *".csproj" ]]; then + build_project $TARGET $CONFIGURATION $@ + else + local PROJFILES=$(find $TARGET -name "*.csproj") + for P in $PROJFILES; do + build_project $P $CONFIGURATION $@ + done + fi +} + +pack() { + local NUSPEC=$1; shift + local VERSION=$1; shift + local CONFIGURATION=$1; shift + + if [ -f $NUSPEC ]; then + nuget_retry pack $NUSPEC -Version $VERSION -Properties Configuration=$CONFIGURATION + fi +} + +CMD=$1; shift +case $CMD in + restore) + if [ $# -ge 1 ]; then + restore $@ + exit 0 + fi + ;; + build) + if [ $# -ge 2 ]; then + build $@ + exit 0 + fi + ;; + pack) + if [ $# -ge 3 ]; then + pack $@ + exit 0 + fi + ;; +esac + +usage; exit 1 diff --git a/packaging/dotnet-build-tools.spec b/packaging/dotnet-build-tools.spec index c9eae0ba..2c3493c0 100644 --- a/packaging/dotnet-build-tools.spec +++ b/packaging/dotnet-build-tools.spec @@ -1,6 +1,6 @@ Name: dotnet-build-tools Summary: Tools for building C# API projects -Version: 1.0.10 +Version: 1.0.11 Release: 1 Group: Development/Libraries License: MIT and Apache-2.0 @@ -28,6 +28,7 @@ C# Deivce API with xbuild in GBS environment. %install %define NuGetDir %{_datadir}/NuGet %define XBuildDir /usr/lib/mono/xbuild +%define ToolsDir %{_datadir}/DotnetBuildTools # Tizen.GBS.BuildTasks mkdir -p %{buildroot}%{XBuildDir}/14.0/Microsoft.Common.targets/ImportAfter @@ -54,6 +55,11 @@ install -p -m 644 NuGet.BuildTasks/ImportBeforeAfter/Microsoft.NuGet.ImportAfter mkdir -p %{buildroot}/nuget install -p -m 644 LocalPackages/*.nupkg %{buildroot}/nuget +# BuildTools +mkdir -p %{buildroot}%{ToolsDir} +install -p -m 755 Tools/dotnet-build.sh %{buildroot}%{ToolsDir} +ln -s %{ToolsDir}/dotnet-build.sh %{buildroot}%{_bindir}/dotnet-build + # RPM Macros install -D -p -m 0644 %{S:1} %{buildroot}%{_sysconfdir}/rpm/macros.dotnet-build-tools @@ -63,5 +69,5 @@ install -D -p -m 0644 %{S:1} %{buildroot}%{_sysconfdir}/rpm/macros.dotnet-build- %{_bindir}/* %{NuGetDir}/* %{XBuildDir}/* +%{ToolsDir}/* /nuget/*.nupkg - diff --git a/packaging/macros.dotnet-build-tools b/packaging/macros.dotnet-build-tools index cc47f640..19d2f4ca 100644 --- a/packaging/macros.dotnet-build-tools +++ b/packaging/macros.dotnet-build-tools @@ -32,6 +32,7 @@ NuGet package for %{name}\ %package mono\ Summary: %{name} for Mono Runtime\ Group: Development/Libraries\ +AutoReqProv: no\ %description mono\ %{name} for Mono Runtime\ %files mono\ @@ -47,13 +48,16 @@ Group: Development/Libraries\ %endif \ %{nil} +%dotnet_restore() \ +dotnet-build restore %{1} \ +%{nil} + %dotnet_build() \ -find %{1}/*.project.json -print0 | xargs -n1 -0 nuget restore \ -find %{1}/*.csproj -print0 | xargs -n1 -0 xbuild /p:Configuration=%{_dotnet_build_conf} \ +dotnet-build build %{1} %{_dotnet_build_conf} %{?2} %{?3} %{?4} %{?5} %{?6} \ %{nil} %dotnet_pack() \ -nuget pack %{1} -Version %{?2}%{!?2:%{version}} -Properties Configuration=%{_dotnet_build_conf} \ +dotnet-build pack %{1} %{2} %{_dotnet_build_conf} %{?3} %{?4} %{?5} %{?6} %{?7} \ %{nil} %dotnet_install() \