Merge remote-tracking branch 'github/master' into tizen
[platform/core/csapi/tizenfx.git] / build.sh
1 #!/bin/bash
2
3 SCRIPT_FILE=$(readlink -f $0)
4 SCRIPT_DIR=$(dirname $SCRIPT_FILE)
5
6 OUTDIR=$SCRIPT_DIR/Artifacts
7
8 RETRY_CMD="$SCRIPT_DIR/tools/scripts/retry.sh"
9 TIMEOUT_CMD="$SCRIPT_DIR/tools/scripts/timeout.sh"
10 DOTNET_CMD="$RETRY_CMD $TIMEOUT_CMD 600 dotnet"
11
12 RUN_BUILD="$DOTNET_CMD msbuild $SCRIPT_DIR/build/build.proj /nologo"
13
14 VERSION_PREFIX=5.0.0
15
16 usage() {
17   echo "Usage: $0 [command] [args]"
18   echo "Commands:"
19   echo "    build [module]     Build a specific module"
20   echo "    full               Build all modules in src/ directory"
21   echo "    ext                Build external modules in externals/ directory"
22   echo "    dummy              Generate dummy assemblies of all modules"
23   echo "    pack [version]     Make a NuGet package with build artifacts"
24   echo "    clean              Clean all artifacts"
25 }
26
27 cmd_build() {
28   if [ -z "$1" ]; then
29     echo "No module specified."
30     exit 1
31   fi
32   if [ -d /nuget ]; then
33     NUGET_SOURCE_OPT="/p:RestoreSources=/nuget"
34   fi
35   $RUN_BUILD /t:restore /p:Project=$1 $NUGET_SOURCE_OPT
36   $RUN_BUILD /t:build /p:Project=$1
37 }
38
39 cmd_full_build() {
40   if [ -d /nuget ]; then
41     NUGET_SOURCE_OPT="/p:RestoreSources=/nuget"
42   fi
43   $RUN_BUILD /t:clean
44   $RUN_BUILD /t:restore $NUGET_SOURCE_OPT
45   $RUN_BUILD /t:build
46 }
47
48 cmd_dummy_build() {
49   if [ -d /nuget ]; then
50     NUGET_SOURCE_OPT="/p:RestoreSources=/nuget"
51   fi
52   $RUN_BUILD /t:restore $NUGET_SOURCE_OPT
53   $RUN_BUILD /t:dummy $NUGET_SOURCE_OPT
54 }
55
56 cmd_ext_build() {
57   if [ -d /nuget ]; then
58     NUGET_SOURCE_OPT="/p:RestoreSources=/nuget;$SCRIPT_DIR/packages;$SCRIPT_DIR/Artifacts"
59   fi
60   PROJECTS=$(ls -1 $SCRIPT_DIR/externals/*.proj)
61   for p in $PROJECTS; do
62     $DOTNET_CMD msbuild $p /t:Build $NUGET_SOURCE_OPT /nologo
63   done
64 }
65
66 cmd_pack() {
67   VERSION=$1
68   if [ -z "$VERSION" ]; then
69     VERSION=$VERSION_PREFIX.$((10000+$(git rev-list --count HEAD)))
70   fi
71
72   $RUN_BUILD /t:pack /p:Version=$VERSION
73 }
74
75 cmd_clean() {
76   $RUN_BUILD /t:clean
77 }
78
79 cmd=$1; shift;
80 case "$cmd" in
81   build|--build|-b) cmd_build $@ ;;
82   full |--full |-f) cmd_full_build $@ ;;
83   dummy|--dummy|-d) cmd_dummy_build $@ ;;
84   ext  |--ext  |-e) cmd_ext_build $@ ;;
85   pack |--pack |-p) cmd_pack $@ ;;
86   clean|--clean|-c) cmd_clean $@ ;;
87   *) usage ;;
88 esac