[M53_2785] Chromium upversion to m53_2785 branch.
[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 \
133       $XWALK_ARG \
134       $COMPONENT_ARG \
135       -Doutdir="$TOPDIR/out.$(getHostArch)" \
136       $@
137   fi
138 }
139
140 function hostNinja() {
141   if [[ $SKIP_NINJA == 0 ]]; then
142     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
143     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
144       TARGETS="$TARGETS ewk_unittests"
145     fi
146     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
147       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
148     fi
149     if [[ $BUILD_XWALK == 1 ]]; then
150       TARGETS="$TARGETS xwalk"
151     fi
152     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
153     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
154   fi
155 }
156
157 function error_report() {
158   echo "Error: File:$1 Line:$2"
159   exit 1
160 }
161
162 function findElementInArray() {
163   local elm
164   for elm in "${@:2}"; do
165     [[ "$elm" = "$1" ]] && return 0;
166   done
167   return 1;
168 }
169
170 function setupAndExecuteTargetBuild() {
171
172   local platform="$1"
173   shift
174
175   local PROFILE
176   local ARCHITECTURE
177   local CONF_FLAG
178   local SPEC_FILE="chromium-efl.spec"
179   local -a ARGS
180
181   # "|| :" means "or always succeeding built-in command"
182   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
183   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" || :)
184
185   if [ "$PROFILE" == "" ]; then
186     if [[ $platform == "mobile" ]]; then
187       PROFILE=tzmb_v3.0_arm64-wayland
188     elif [[ $platform == "mobile_emulator" ]]; then
189       PROFILE=tzmb_v3.0_emulator-wayland
190     elif [[ $platform == "tv" ]]; then
191       PROFILE=tztv_v3.0_arm-wayland
192     elif [[ $platform == "tv_emulator" ]]; then
193       PROFILE=tztv_v3.0_emulator-wayland
194     else
195       echo "Cannot set default PROFILE for platform=${platform}"
196       exit 1
197     fi
198   fi
199   echo "Set the profile : $PROFILE"
200
201   if [ "$ARCHITECTURE" == "" ]; then
202     if [[ $platform == "mobile" ]]; then
203       ARCHITECTURE=aarch64
204     elif [[ $platform == "mobile_emulator" ]]; then
205       ARCHITECTURE=i586
206     elif [[ $platform == "tv" ]]; then
207       ARCHITECTURE=armv7l
208     elif [[ $platform == "tv_emulator" ]]; then
209       ARCHITECTURE=i586
210     else
211       echo "Cannot set default ARCHITECTURE for platform=${platform}"
212       exit 1
213     fi
214   fi
215   echo "Set the architecture : $ARCHITECTURE"
216
217   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
218     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
219   fi
220
221   EXTRA_PACK_OPTS=""
222   if [ "$PROFILE" == "tztv_v2.4_product" ]; then
223     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
224   fi
225
226   local count=0
227   local exclusive_options=0
228   local RPMLINT=0
229   local NOINIT=0
230   while [[ $# > 0 ]]; do
231     count=$(( $count + 1 ))
232     case "$1" in
233     --debug)
234         ARGS[$count]=--define
235         count=$(( $count + 1 ))
236         ARGS[$count]="_debug_mode 1"
237     ;;
238     --skip-ninja)
239         ARGS[$count]=--define
240         count=$(( $count + 1 ))
241         ARGS[$count]="_skip_ninja 1"
242     ;;
243     --skip-gyp)
244         ARGS[$count]=--define
245         count=$(( $count + 1 ))
246         ARGS[$count]="_skip_gyp 1"
247     ;;
248     --xwalk)
249         ARGS[$count]=--define
250         count=$(( $count + 1 ))
251         ARGS[$count]="build_xwalk 1"
252     ;;
253     --component-build)
254         ARGS[$count]=--define
255         count=$(( $count + 1 ))
256         ARGS[$count]="component_build 1"
257     ;;
258     --libs)
259         target="libs"
260         exclusive_options=$(( $exclusive_options + 1 ))
261     ;;
262     --crosswalk-bin)
263         target="crosswalk-bin"
264         exclusive_options=$(( $exclusive_options + 1 ))
265     ;;
266     --gbs-debug)
267         ARGS[$count]=--debug
268     ;;
269     --rpmlint)
270         RPMLINT=1
271         count=$(( $count + 1 ))
272     ;;
273     --noinit)
274         NOINIT=1
275         ARGS[$count]="$1"
276         count=$(( $count + 1 ))
277     ;;
278     *)
279       ARGS[$count]="$1"
280     ;;
281     esac
282     shift;
283   done
284
285   if [ "$exclusive_options" -gt 1 ]; then
286     echo "ERROR: --libs and --crosswalk-bin are mutually exclusive parameters."
287     exit 1
288   fi
289
290   cd $TOPDIR
291   rm -f packaging
292   ln -sf tizen_src/packaging packaging
293
294   if [ "$target" == "libs" ]; then
295     SPEC_FILE="chromium-efl-libs.spec"
296   elif [ "$target" == "crosswalk-bin" ]; then
297     SPEC_FILE="crosswalk-bin.spec"
298   fi
299
300   if [ "$(echo "${PROFILE}" | grep -Po "v3.0")" != "" -a "$NOINIT" == 0 ]; then
301     prepareTizen3Build $PROFILE $RPMLINT
302   fi
303
304   gbs $CONF_FLAG build -P $PROFILE --spec $SPEC_FILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS --incremental
305 }
306
307 function prepareTizen3Build() {
308   local PROFILE=$1
309   local RPMLINT=$2
310   BUILD_CONF_OPTS=""
311
312   # In case of '_rpmlint 1', build.conf of gbs repo will be used, enabling rpmlint.
313   # Otherwise, locally prepared build.conf will be used, disabling rpmlint.
314   local PREVIOUS_BUILD_CONF_PATH=""
315
316   if [ "$PROFILE" == "tztv_v3.0_arm-wayland" ]; then
317     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm_wayland.conf"
318   elif [ "$PROFILE" == "tzmb_v3.0_arm-wayland" ]; then
319     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm_wayland.conf"
320   elif [ "$PROFILE" == "tzmb_v3.0_arm64-wayland" ]; then
321     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm64_wayland.conf"
322   fi
323
324   local PREVIOUS_RPMLINT="!rpmlint"
325   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
326     # Never built before
327     PREVIOUS_RPMLINT=""
328   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
329     # Once built with rpmlint
330     PREVIOUS_RPMLINT="rpmlint"
331   fi
332
333   # Disable rpmlint
334   if [ "$RPMLINT" == 0 ]; then
335     echo "** Disable rpmlint"
336     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
337     rm -rf $BUILD_CONF_DIR
338     mkdir $BUILD_CONF_DIR
339     REPO=http://download.tizen.org/snapshots/tizen/$platform/latest/repos/$(echo $ARCHITECTURE | sed -e "s/armv7l/arm/;s/aarch64/arm64/")-wayland/packages/repodata/
340     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
341     BUILD_CONF_GZ=$(awk -F\" '{ print $6 }' $BUILD_CONF_DIR/index.html | grep "build.conf.gz")
342     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
343     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
344     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
345       echo "It's failed to donwload build.conf. Please contact system administrator."
346       exit 1
347     fi
348     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
349     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
350     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
351     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
352       echo "** Once built with rpmlint"
353       BUILD_CONF_OPTS+=" --clean"
354     fi
355   else # Enable rpmlint
356     echo "** Enable rpmlint"
357     BUILD_CONF_OPTS=""
358     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
359       BUILD_CONF_OPTS="--clean"
360     fi
361   fi
362 }