Release 10.0.0.17834
[platform/core/csapi/tizenfx.git] / build.sh
1 #!/bin/bash -e
2
3 SCRIPT_DIR=$(dirname $(readlink -f $0))
4
5 CONFIGURATION=Release
6 SLN_NAME=_Build
7 SLN_FILE=$SCRIPT_DIR/$SLN_NAME.sln
8 OUTDIR=$SCRIPT_DIR/Artifacts
9
10 PROFILES=(mobile tv wearable)
11 TARGET_ASSEMBLY_DIR=/usr/share/dotnet.tizen/framework
12 TARGET_PRELOAD_DIR=/usr/share/dotnet.tizen/preload
13
14 source $SCRIPT_DIR/packaging/version.txt
15 VERSION_PREFIX=$(expr $NUGET_VERSION : '\([0-9]\+\.[0-9]\+\.[0-9]\+\)')
16
17 usage() {
18   echo "Usage: $0 [command] [args]"
19   echo "Commands:"
20   echo "    build [module]     Build a specific module"
21   echo "    full               Build all modules in src/ directory"
22   echo "    design             Build NUI Design module"
23   echo "    xamlbuild          Build NUI XamlBuild module"
24   echo "    dummy              Generate dummy assemblies of all modules"
25   echo "    pack [version]     Make a NuGet package with build artifacts"
26   echo "    install [target]   Install assemblies to the target device"
27   echo "    clean              Clean all artifacts"
28 }
29
30 prepare_solution() {
31   target=$1; [ -z "$target" ] && target="full"
32
33   dotnet new sln -n $SLN_NAME -o $SCRIPT_DIR --force
34   if [ "$target" == "public" -o "$target" == "full" ]; then
35     dotnet sln $SLN_FILE add $SCRIPT_DIR/src/*/*.csproj
36   fi
37   if [ "$target" == "internal" -o "$target" == "full" ]; then
38     dotnet sln $SLN_FILE add $SCRIPT_DIR/internals/src/*/*.csproj
39   fi
40   if [ "$target" == "design" ]; then
41     dotnet sln $SLN_FILE add $SCRIPT_DIR/src/*/*.Design.csproj
42   else
43     dotnet sln $SLN_FILE remove $SCRIPT_DIR/src/*/*.Design.csproj
44   fi
45   if [ "$target" == "xamlbuild" ]; then
46     dotnet sln $SLN_FILE add $SCRIPT_DIR/src/*/*.XamlBuild.csproj
47   else
48     dotnet sln $SLN_FILE remove $SCRIPT_DIR/src/*/*.XamlBuild.csproj
49   fi
50 }
51
52 cleanup_solution() {
53   rm -f $SLN_FILE
54 }
55
56 remove_intermediates() {
57   find $1 -type d \
58     \( -name obj -o -name bin \) -print0 | xargs -0 -I {} rm -fr "{}"
59 }
60
61 clean() {
62   remove_intermediates $SCRIPT_DIR/build/
63   remove_intermediates $SCRIPT_DIR/src/
64   remove_intermediates $SCRIPT_DIR/internals/src/
65   rm -fr $OUTDIR
66   rm -f msbuild.log
67   cleanup_solution
68 }
69
70 restore() {
71   if [ -d /nuget ]; then
72     dotnet restore -s /nuget $@
73   else
74     dotnet restore $@
75   fi
76 }
77
78 build() {
79   dotnet build --no-restore -c $CONFIGURATION /fl $@
80 }
81
82 copy_artifacts() {
83   mkdir -p $2
84   for proj in $(ls -d1 $1/*/); do
85     if [ -d $proj/bin/$CONFIGURATION ]; then
86       cp -fr $proj/bin/$CONFIGURATION/*/* $2
87     fi
88   done
89 }
90
91 build_artifacts() {
92   copy_artifacts $SCRIPT_DIR/src $OUTDIR/bin/public
93   copy_artifacts $SCRIPT_DIR/internals/src $OUTDIR/bin/internal
94
95   # move preload
96   mkdir -p $OUTDIR/preload
97   mv $OUTDIR/bin/public/*.preload $OUTDIR/preload 2>/dev/null || :
98   mv $OUTDIR/bin/internal/*.preload $OUTDIR/preload 2>/dev/null || :
99
100   # merge filelist
101   for profile in ${PROFILES[@]}; do
102     list=$(cat $OUTDIR/bin/public/*.$profile.filelist \
103                $OUTDIR/bin/internal/*.$profile.filelist \
104                | sort | uniq)
105     rm -f $OUTDIR/$profile.filelist
106     for item in $list; do
107       if [[ "$item" == *.preload ]]; then
108         echo $TARGET_PRELOAD_DIR/$item >> $OUTDIR/$profile.filelist
109       else
110         echo $TARGET_ASSEMBLY_DIR/$item >> $OUTDIR/$profile.filelist
111       fi
112     done
113   done
114 }
115
116 cmd_module_build() {
117   if [ -z "$1" ]; then
118     echo "No module specified."
119     exit 1
120   fi
121   module=$1; shift;
122   sources=(src internals/src)
123   for src in $sources; do
124     project=$SCRIPT_DIR/$src/$module/$module.csproj
125     echo $project
126     if [ -f "$project" ]; then
127       restore $project
128       build $project $@
129     fi
130   done
131 }
132
133 cmd_full_build() {
134   clean
135   prepare_solution full
136   restore $SLN_FILE $@
137   build $SLN_FILE $@
138   cleanup_solution
139   build_artifacts
140   cmd_dummy_build
141 }
142
143 cmd_design_build() {
144   prepare_solution design
145   restore $SLN_FILE
146   build $SLN_FILE $@
147   projects=$(dirname $(ls -1 $SCRIPT_DIR/src/*/*.Design.csproj))
148   for proj in $projects; do
149     if [ -d $proj/bin/$CONFIGURATION ]; then
150       cp -f $proj/bin/$CONFIGURATION/*/*.Design.dll $SCRIPT_DIR/pkg/Tizen.NET.API*/design/
151     fi
152   done
153   cleanup_solution
154 }
155
156 cmd_xamlbuild_build() {
157   prepare_solution xamlbuild
158   restore $SLN_FILE
159   build $SLN_FILE $@
160   projects=$(dirname $(ls -1 $SCRIPT_DIR/src/*/*.XamlBuild.csproj))
161   for proj in $projects; do
162     if [ -d $proj/bin/$CONFIGURATION ]; then
163       cp -f $proj/bin/$CONFIGURATION/*/*.XamlBuild.dll $SCRIPT_DIR/pkg/Tizen.NET.API*/xamlbuild/
164     fi
165   done
166   cleanup_solution
167 }
168
169 cmd_dummy_build() {
170   if [ ! -d $OUTDIR/bin/public/ref  ]; then
171     echo "No assemblies to read. Build TizenFX first."
172     exit 1
173   fi
174   mkdir -p $OUTDIR/bin/dummy
175   dotnet $SCRIPT_DIR/tools/bin/APITool.dll \
176          dummy $OUTDIR/bin/public/ref $OUTDIR/bin/dummy
177 }
178
179 cmd_pack() {
180   VERSION=$1
181   if [ -z "$VERSION" ]; then
182     pushd $SCRIPT_DIR > /dev/null
183     VERSION=$VERSION_PREFIX.$((10000+$(git rev-list --count HEAD)))
184     popd > /dev/null
185   fi
186
187   restore $SCRIPT_DIR/build/pack.csproj
188   nuspecs=$(find $SCRIPT_DIR/pkg/ -name "*.nuspec")
189   for nuspec in $nuspecs; do
190     dotnet pack --no-restore --no-build --nologo -o $OUTDIR \
191            $SCRIPT_DIR/build/pack.csproj \
192            /p:Version=$VERSION \
193            /p:NuspecFile=$(readlink -f $nuspec)
194   done
195 }
196
197 cmd_install() {
198   DEVICE_ID=$1
199
200   RUNTIME_ASSEMBLIES="$OUTDIR/bin/public/*.dll $OUTDIR/bin/internal/*.dll"
201
202   device_cnt=$(sdb devices | grep -v "List" | wc -l)
203
204   if [ $device_cnt -eq 0 ]; then
205     echo "No connected devices"
206     exit 1
207   fi
208
209   if [ $device_cnt -gt 1 ] && [ -z "$DEVICE_ID" ]; then
210     echo "Multiple devices are connected. Specify the device. (ex: ./build.sh install [device-id])"
211     sdb devices
212     exit 1
213   fi
214
215   SDB_OPTIONS=""
216   if [ -n "$DEVICE_ID" ]; then
217     SDB_OPTIONS="-s $DEVICE_ID"
218   fi
219
220   sdb $SDB_OPTIONS root on
221   sdb $SDB_OPTIONS shell mount -o remount,rw /
222   sdb $SDB_OPTIONS push $RUNTIME_ASSEMBLIES $TARGET_ASSEMBLY_DIR
223
224   nifile_cnt=$(sdb $SDB_OPTIONS shell find $TARGET_ASSEMBLY_DIR -name '*.ni.dll' | wc -l)
225   if [ $nifile_cnt -gt 0 ]; then
226     sdb $SDB_OPTIONS shell "rm -f $TARGET_ASSEMBLY_DIR/*.ni.dll"
227     sdb $SDB_OPTIONS shell dotnettool --ni-system
228     sdb $SDB_OPTIONS shell dotnettool --ni-regen-all-app
229   fi
230
231   sdb $SDB_OPTIONS shell chsmack -a '_' $TARGET_ASSEMBLY_DIR/*
232 }
233
234 cmd=$1; [ $# -gt 0 ] && shift;
235 case "$cmd" in
236   build|--build|-b) cmd_module_build $@ ;;
237   full |--full |-f) cmd_full_build $@ ;;
238   design|--design)  cmd_design_build $@ ;;
239   xamlbuild|--xamlbuild)  cmd_xamlbuild_build $@ ;;
240   dummy|--dummy|-d) cmd_dummy_build $@ ;;
241   pack |--pack |-p) cmd_pack $@ ;;
242   install |--install |-i) cmd_install $@ ;;
243   clean|--clean|-c) clean ;;
244   *) usage ;;
245 esac