Add dotnet-build.sh and fix macros 68/108568/1 accepted/tizen/mobile/20170105.223150 accepted/tizen/tv/20170105.223152 submit/tizen/20170105.060951
authorWonYoung Choi <wy80.choi@samsung.com>
Thu, 5 Jan 2017 06:08:28 +0000 (15:08 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Thu, 5 Jan 2017 06:08:28 +0000 (15:08 +0900)
Change-Id: Ibd6034931d67d8f30af9b203f86f19cb2c2f926f

Tools/dotnet-build.sh [new file with mode: 0755]
packaging/dotnet-build-tools.spec
packaging/macros.dotnet-build-tools

diff --git a/Tools/dotnet-build.sh b/Tools/dotnet-build.sh
new file mode 100755 (executable)
index 0000000..c0fe8d1
--- /dev/null
@@ -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
index c9eae0b..2c3493c 100644 (file)
@@ -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
-
index cc47f64..19d2f4c 100644 (file)
@@ -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() \