Fix build.sh to fix gbs build error if network is unavailable
[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 # Properties
7 OUTDIR=$SCRIPT_DIR/Artifacts
8 NUGET_CMD="mono $SCRIPT_DIR/tools/NuGet.exe"
9
10 usage() {
11   echo "Usage: $0 [options] [args]"
12   echo "    Options:"
13   echo "        -h, --help            Show this usages message"
14   echo "        -b, --build [module]  Build a module"
15   echo "        -f, --full            Build all modules in src/ directory. The module should be added in pkg/Tizen.NET.Private.sln"
16   echo "        -d, --dummy           Build dummy modules"
17   echo "        -p, --pack            Make nuget packages"
18   echo "        -c, --clean           Clean all artifacts"
19 }
20
21 cmd_clean() {
22   rm -fr $OUTDIR
23   LIST=$(find $SCRIPT_DIR -type d -a -name bin -o -name obj)
24   for d in $LIST; do
25     rm -fr $d
26   done
27 }
28
29 cmd_build() {
30   if [ -z "$1" ]; then
31     echo "No module specified."
32     exit 1
33   fi
34   dotnet restore $SCRIPT_DIR/src/$1 --source /nuget
35   dotnet build $SCRIPT_DIR/src/$1 --no-restore --configuration=Release --output=$OUTDIR/bin
36 }
37
38 cmd_full_build() {
39   dotnet restore $SCRIPT_DIR/pkg/Tizen.NET.Private.sln --source /nuget
40   dotnet build $SCRIPT_DIR/pkg/Tizen.NET.Private.sln --no-restore --configuration=Release --output=$OUTDIR/bin
41 }
42
43 cmd_pack() {
44   VERSION_FILE=$OUTDIR/Version.txt
45   if [ -f $VERSION_FILE ]; then
46     NUGET_VERSION_PREFIX=$(cat $VERSION_FILE | grep Prefix | cut -d: -f2 | sed 's/\r$//')
47     NUGET_VERSION_SUFFIX=$(cat $VERSION_FILE | grep Suffix | cut -d: -f2 | sed 's/\r$//')
48           NUGET_VERSION_OPT="-Version $NUGET_VERSION_PREFIX-$NUGET_VERSION_SUFFIX"
49   fi
50   $NUGET_CMD pack $SCRIPT_DIR/pkg/Tizen.NET.Private.nuspec -Symbols -NoPackageAnalysis $NUGET_VERSION_OPT -BasePath $OUTDIR -OutputDirectory $OUTDIR
51   $NUGET_CMD pack $SCRIPT_DIR/pkg/Tizen.NET.nuspec -Symbols -NoPackageAnalysis $NUGET_VERSION_OPT -BasePath $OUTDIR -OutputDirectory $OUTDIR
52 }
53
54 cmd_dummy_build() {
55   dotnet restore $SCRIPT_DIR/pkg/Tizen.NET.Dummy.csproj --source /nuget
56   dotnet build $SCRIPT_DIR/pkg/Tizen.NET.Dummy.csproj --no-restore --configuration=Release
57 }
58
59 OPTS=`getopt -o hcbfpd --long help,clean,build,full,pack,dummy -n 'build' -- "$@"`
60 if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; usage; exit 1 ; fi
61 eval set -- "$OPTS"
62
63 FLAG_HELP=false
64 FLAG_FULL=false
65 FLAG_BUILD=false
66 FLAG_CLEAN=false
67 FLAG_DUMMY=false
68 FLAG_PACK=false
69
70 while true; do
71   case "$1" in
72     -h|--help) FLAG_HELP=true; shift ;;
73     -b|--build) FLAG_BUILD=true; shift ;;
74     -f|--full) FLAG_FULL=true; shift ;;
75     -d|--dummy) FLAG_DUMMY=true; shift ;;
76     -p|--pack) FLAG_PACK=true; shift ;;
77     -c|--clean) FLAG_CLEAN=true; shift ;;
78     --) shift; break ;;
79     *) break ;;
80   esac
81 done
82
83 if $FLAG_HELP; then usage; exit 0; fi
84 if $FLAG_CLEAN; then cmd_clean; exit 0; fi
85 if $FLAG_FULL; then cmd_full_build; exit 0; fi
86 if $FLAG_BUILD; then cmd_build $@; exit 0; fi
87 if $FLAG_PACK; then cmd_pack $@; exit 0; fi
88 if $FLAG_DUMMY; then cmd_dummy_build; exit 0; fi
89
90 usage;