Build content_shell by default in desktop build
[platform/framework/web/chromium-efl.git] / tizen_src / build / common.sh
1 #!/bin/bash
2
3 export SCRIPTDIR=$(readlink -e $(dirname $0))
4 export TOPDIR=$(readlink -f "${SCRIPTDIR}/../..")
5 export CHROME_SRC="${TOPDIR}"
6
7 function getHostOs() {
8   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
9 }
10
11 function getHostArch() {
12   echo $(uname -m | sed -e \
13         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/;s/aarch64/arm64/')
14 }
15
16 function getPythonVersion() {
17   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
18 }
19
20 function setIfUndef() {
21     eval original=\$$1
22     new=$2
23     if [ -n "$original" ]; then
24         echo $original
25     else
26         echo $new
27     fi
28 }
29
30
31 function hostBuldScriptUsage() {
32 cat << EOF
33 usage: $1 [OPTIONS]
34
35 Build non gbs version of chromium-efl
36
37 OPTIONS:
38    -h, --help            Show this message
39    --build-ewk-unittests Build ewk unittests
40    --ccache              Configure ccache installed in your system
41    --clang               Use chromium's clang compiler to build the sources
42    --no-content-shell    Don't build content_shell application
43    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
44    -jN                   Set number of jobs, just like with make or ninja
45    --skip-gyp            Skip restore_gyp, jhbuild and gyp_chromium steps
46    --skip-ninja          Skip ninja step
47    --xwalk               Build crosswalk and friends
48
49 examples:
50 $0 --skip-gyp
51 $0 --skip-gyp --ccache
52 $0 --skip-ninja
53 EOF
54   exit
55 }
56
57 function parseHostBuildScriptParams() {
58
59   export SKIP_GYP=0
60   export USE_CCACHE=0
61   export USE_CLANG=0
62   export FORCE_JHBUILD=0
63   export SKIP_NINJA=0
64   export BUILD_EWK_UNITTESTS=0
65   export BUILD_CONTENT_SHELL=1
66   export BUILD_XWALK=0
67   export BUILD_SUBDIRECTORY=Release
68   export COMPONENT_BUILD=0
69
70   local platform="$1"
71   shift
72
73   while [[ $# > 0 ]]; do
74     case "$1" in
75       -h|--help)
76         hostBuldScriptUsage ${0}
77         ;;
78       --skip-gyp)
79         export SKIP_GYP=1
80         ;;
81       --ccache)
82         echo using ccache
83         export USE_CCACHE=1
84         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
85         ;;
86       --clang)
87         export USE_CLANG=1
88         ;;
89       --no-content-shell)
90         export BUILD_CONTENT_SHELL=0
91         ;;
92       --force-jhbuild)
93         export FORCE_JHBUILD=1
94         ;;
95       --skip-ninja)
96         export SKIP_NINJA=1
97         ;;
98       --build-ewk-unittests)
99         export BUILD_EWK_UNITTESTS=1
100         ;;
101       --debug)
102         export BUILD_SUBDIRECTORY="Debug"
103         ;;
104       --xwalk)
105         export BUILD_XWALK=1
106         ;;
107       --component-build)
108         export COMPONENT_BUILD=1
109         ;;
110       -j*)
111         export JOBS="$1"
112         ;;
113       *)
114         echo "Unknown argument: $1"
115         exit 1
116         ;;
117     esac
118     shift;
119   done
120 }
121
122 function hostGypChromiumEfl() {
123   if [[ $SKIP_GYP == 0 ]]; then
124     local XWALK_ARG=""
125     local COMPONENT_ARG=""
126     if [[ $BUILD_XWALK == 1 ]]; then
127       XWALK_ARG="--xwalk"
128     fi
129     if [[ $COMPONENT_BUILD == 1 ]]; then
130       COMPONENT_ARG="-Dcomponent=shared_library"
131     fi
132     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh $XWALK_ARG $COMPONENT_ARG $@
133   fi
134 }
135
136 function hostNinja() {
137   if [[ $SKIP_NINJA == 0 ]]; then
138     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
139     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
140       TARGETS="$TARGETS ewk_unittests"
141     fi
142     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
143       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
144     fi
145     if [[ $BUILD_XWALK == 1 ]]; then
146       TARGETS="$TARGETS xwalk"
147     fi
148     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
149     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
150   fi
151 }
152
153 function error_report() {
154   echo "Error: File:$1 Line:$2"
155   exit 1
156 }
157
158 function findElementInArray() {
159   local elm
160   for elm in "${@:2}"; do
161     [[ "$elm" = "$1" ]] && return 0;
162   done
163   return 1;
164 }
165
166 function setupAndExecuteTargetBuild() {
167
168   local platform="$1"
169   shift
170
171   local PROFILE
172   local ARCHITECTURE
173   local CONF_FLAG
174   local SPEC_FILE="chromium-efl.spec"
175   local -a ARGS
176
177   # "|| :" means "or always succeeding built-in command"
178   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
179   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" || :)
180
181   if [ "$PROFILE" == "" ]; then
182     if [[ $platform == "mobile" ]]; then
183       PROFILE=tzmb_v3.0_arm64-wayland
184     elif [[ $platform == "mobile_emulator" ]]; then
185       PROFILE=tzmb_v3.0_emulator-wayland
186     elif [[ $platform == "tv" ]]; then
187       PROFILE=tztv_v3.0_arm-wayland
188     elif [[ $platform == "tv_emulator" ]]; then
189       PROFILE=tztv_v3.0_emulator-wayland
190     else
191       echo "Cannot set default PROFILE for platform=${platform}"
192       exit 1
193     fi
194   fi
195   echo "Set the profile : $PROFILE"
196
197   if [ "$ARCHITECTURE" == "" ]; then
198     if [[ $platform == "mobile" ]]; then
199       ARCHITECTURE=aarch64
200     elif [[ $platform == "mobile_emulator" ]]; then
201       ARCHITECTURE=i586
202     elif [[ $platform == "tv" ]]; then
203       ARCHITECTURE=armv7l
204     elif [[ $platform == "tv_emulator" ]]; then
205       ARCHITECTURE=i586
206     else
207       echo "Cannot set default ARCHITECTURE for platform=${platform}"
208       exit 1
209     fi
210   fi
211   echo "Set the architecture : $ARCHITECTURE"
212
213   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
214     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
215   fi
216
217   EXTRA_PACK_OPTS=""
218   if [ "$PROFILE" == "tztv_v2.2.1_prehawk" ]; then
219     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
220   fi
221
222   if [ "$(echo "${PROFILE}" | grep -Po "v3.0")" != "" ]; then
223     prepareTizen3Build $PROFILE
224   fi
225
226   local count=0
227   local exclusive_options=0
228   while [[ $# > 0 ]]; do
229     count=$(( $count + 1 ))
230     case "$1" in
231     --debug)
232         ARGS[$count]=--define
233         count=$(( $count + 1 ))
234         ARGS[$count]="_debug_mode 1"
235     ;;
236     --skip-ninja)
237         ARGS[$count]=--define
238         count=$(( $count + 1 ))
239         ARGS[$count]="_skip_ninja 1"
240     ;;
241     --skip-gyp)
242         ARGS[$count]=--define
243         count=$(( $count + 1 ))
244         ARGS[$count]="_skip_gyp 1"
245     ;;
246     --xwalk)
247         ARGS[$count]=--define
248         count=$(( $count + 1 ))
249         ARGS[$count]="build_xwalk 1"
250     ;;
251     --component-build)
252         ARGS[$count]=--define
253         count=$(( $count + 1 ))
254         ARGS[$count]="component_build 1"
255     ;;
256     --libs)
257         target="libs"
258         exclusive_options=$(( $exclusive_options + 1 ))
259     ;;
260     --crosswalk-bin)
261         target="crosswalk-bin"
262         exclusive_options=$(( $exclusive_options + 1 ))
263     ;;
264     --gbs-debug)
265         ARGS[$count]=--debug
266     ;;
267     *)
268       ARGS[$count]="$1"
269     ;;
270     esac
271     shift;
272   done
273
274   if [[ $exclusive_options -gt 1 ]]; then
275     echo "ERROR: --libs and --crosswalk-bin are mutually exclusive parameters."
276     exit 1
277   fi
278
279   cd $TOPDIR
280   rm -f packaging
281   ln -sf tizen_src/packaging packaging
282
283   if [ "$target" == "libs" ]; then
284     SPEC_FILE="chromium-efl-libs.spec"
285   elif [ "$target" == "crosswalk-bin" ]; then
286     SPEC_FILE="crosswalk-bin.spec"
287   fi
288
289   gbs $CONF_FLAG build -P $PROFILE --spec $SPEC_FILE --include-all -A $ARCHITECTURE --incremental "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS
290 }
291
292 function prepareTizen3Build() {
293   local PROFILE=$1
294   BUILD_CONF_OPTS=""
295
296   # In case of '_rpmlint 1', build.conf of gbs repo will be used, enabling rpmlint.
297   # Otherwise, locally prepared build.conf will be used, disabling rpmlint.
298   local PREVIOUS_BUILD_CONF_PATH=""
299   local LOCAL_BUILD_CONF_PATH=""
300
301   if [ "$PROFILE" == "tztv_v3.0_arm-wayland" ]; then
302     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm-walynad.conf"
303     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tztv_v3.0_arm-wayland.conf"
304   elif [ "$PROFILE" == "tzmb_v3.0_arm-wayland" ]; then
305     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm-walynad.conf"
306     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm-wayland.conf"
307   elif [ "$PROFILE" == "tzmb_v3.0_arm64-wayland" ]; then
308     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm64-walynad.conf"
309     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm64-wayland.conf"
310   fi
311
312   local PREVIOUS_RPMLINT="!rpmlint"
313   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
314     PREVIOUS_RPMLINT=""
315   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
316     PREVIOUS_RPMLINT="rpmlint"
317   fi
318
319   if [ "$LOCAL_BUILD_CONF_PATH" != "" ]; then
320     BUILD_CONF_OPTS="-D $LOCAL_BUILD_CONF_PATH"
321   fi
322
323   if [ "$(echo "$@" | grep -Po "_rpmlint\ 1")" == "" ]; then
324     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
325       BUILD_CONF_OPTS+=" --clean"
326     fi
327   else
328     BUILD_CONF_OPTS=""
329     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
330       BUILD_CONF_OPTS="--clean"
331     fi
332   fi
333 }