[M67 Dev][EFL] Integrate GN configuration
[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       --use-gn)
82         export USE_GN=1
83         ;;
84       --skip-gn)
85         export SKIP_GN=1
86         ;;
87       --ccache)
88         echo using ccache
89         export USE_CCACHE=1
90         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
91         ;;
92       --clang)
93         export USE_CLANG=1
94         ;;
95       --no-content-shell)
96         export BUILD_CONTENT_SHELL=0
97         ;;
98       --force-jhbuild)
99         export FORCE_JHBUILD=1
100         ;;
101       --skip-ninja)
102         export SKIP_NINJA=1
103         ;;
104       --build-ewk-unittests)
105         export BUILD_EWK_UNITTESTS=1
106         ;;
107       --debug)
108         export BUILD_SUBDIRECTORY="Debug"
109         ;;
110       --xwalk)
111         export BUILD_XWALK=1
112         ;;
113       --component-build)
114         export COMPONENT_BUILD=1
115         ;;
116       -j*)
117         export JOBS="$1"
118         ;;
119       *)
120         echo "Unknown argument: $1"
121         exit 1
122         ;;
123     esac
124     shift;
125   done
126 }
127
128 function hostGypChromiumEfl() {
129   if [[ $SKIP_GYP == 0 ]]; then
130     local XWALK_ARG=""
131     local COMPONENT_ARG=""
132     if [[ $BUILD_XWALK == 1 ]]; then
133       XWALK_ARG="--xwalk"
134     fi
135     if [[ $COMPONENT_BUILD == 1 ]]; then
136       COMPONENT_ARG="-Dcomponent=shared_library"
137     fi
138     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh \
139       $XWALK_ARG \
140       $COMPONENT_ARG \
141       -Doutdir="$TOPDIR/out.$(getHostArch)" \
142       $@
143   fi
144 }
145
146 function hostGnChromiumEfl() {
147   if [[ $SKIP_GN != 1 ]]; then
148     local XWALK_ARG=""
149     local COMPONENT_ARG=""
150     if [[ $BUILD_XWALK == 1 ]]; then
151       XWALK_ARG="xwalk=true"
152     fi
153     if [[ $COMPONENT_BUILD == 1 ]]; then
154       COMPONENT_ARG="component=shared_library"
155     fi
156     ${TOPDIR}/tizen_src/build/gn_chromiumefl.sh \
157       $XWALK_ARG \
158       $COMPONENT_ARG \
159       "outdir=\"$TOPDIR/out.$(getHostArch)\"" \
160       "chromium_efl_tizen_version=30" \
161       $@
162   fi
163 }
164
165 function hostNinja() {
166   if [[ $SKIP_NINJA == 0 ]]; then
167     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
168     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
169       TARGETS="$TARGETS ewk_unittests"
170     fi
171     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
172       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
173     fi
174     if [[ $BUILD_XWALK == 1 ]]; then
175       TARGETS="$TARGETS xwalk"
176     fi
177     if [[ $BUILD_CHROMEDRIVER == 1 ]]; then
178       TARGETS="$TARGETS chromedriver"
179     fi
180     if [ "$USE_GN" ]; then
181       export BUILD_SUBDIRECTORY=""
182       BUILDDIR=${GN_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
183     else
184       BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
185     fi
186     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
187   fi
188 }
189
190 function error_report() {
191   echo "Error: File:$1 Line:$2"
192   exit 1
193 }
194
195 function findElementInArray() {
196   local elm
197   for elm in "${@:2}"; do
198     [[ "$elm" = "$1" ]] && return 0;
199   done
200   return 1;
201 }
202
203 function setupAndExecuteTargetBuild() {
204
205   local platform="$1"
206   shift
207
208   local PROFILE
209   local ARCHITECTURE
210   local CONF_FLAG
211   local SPEC_FILE="chromium-efl.spec"
212   local -a ARGS
213
214   # "|| :" means "or always succeeding built-in command"
215   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
216   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" || :)
217
218   if [ "$PROFILE" == "" ]; then
219     if [[ $platform == "mobile" ]]; then
220       PROFILE=tzmb_v3.0_arm64-wayland
221     elif [[ $platform == "mobile_emulator" ]]; then
222       PROFILE=tzmb_v3.0_emulator-wayland
223     elif [[ $platform == "tv" ]]; then
224       PROFILE=tztv_v3.0_arm-wayland
225     elif [[ $platform == "tv_emulator" ]]; then
226       PROFILE=tztv_v3.0_emulator-wayland
227     else
228       echo "Cannot set default PROFILE for platform=${platform}"
229       exit 1
230     fi
231   fi
232   echo "Set the profile : $PROFILE"
233
234   if [ "$ARCHITECTURE" == "" ]; then
235     if [[ $platform == "mobile" ]]; then
236       ARCHITECTURE=aarch64
237     elif [[ $platform == "mobile_emulator" ]]; then
238       ARCHITECTURE=i586
239     elif [[ $platform == "tv" ]]; then
240       ARCHITECTURE=armv7l
241     elif [[ $platform == "tv_emulator" ]]; then
242       ARCHITECTURE=i586
243     else
244       echo "Cannot set default ARCHITECTURE for platform=${platform}"
245       exit 1
246     fi
247   fi
248   echo "Set the architecture : $ARCHITECTURE"
249
250   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
251     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
252   fi
253
254   EXTRA_PACK_OPTS=""
255   if [ "$PROFILE" == "tztv_v2.4_product" ]; then
256     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
257   fi
258
259   local count=0
260   local exclusive_options=0
261   local RPMLINT=0
262   local NOINIT=0
263   while [[ $# > 0 ]]; do
264     count=$(( $count + 1 ))
265     case "$1" in
266     --debug)
267         ARGS[$count]=--define
268         count=$(( $count + 1 ))
269         ARGS[$count]="_debug_mode 1"
270     ;;
271     --skip-ninja)
272         ARGS[$count]=--define
273         count=$(( $count + 1 ))
274         ARGS[$count]="_skip_ninja 1"
275     ;;
276     --skip-gyp)
277         ARGS[$count]=--define
278         count=$(( $count + 1 ))
279         ARGS[$count]="_skip_gyp 1"
280     ;;
281     --use-gn)
282         ARGS[$count]=--define
283         count=$(( $count + 1 ))
284         ARGS[$count]="_use_gn 1"
285     ;;
286     --skip-gn)
287         ARGS[$count]=--define
288         count=$(( $count + 1 ))
289         ARGS[$count]="_skip_gn 1"
290     ;;
291     --xwalk)
292         ARGS[$count]=--define
293         count=$(( $count + 1 ))
294         ARGS[$count]="build_xwalk 1"
295     ;;
296     --component-build)
297         ARGS[$count]=--define
298         count=$(( $count + 1 ))
299         ARGS[$count]="component_build 1"
300     ;;
301     --libs)
302         target="libs"
303         exclusive_options=$(( $exclusive_options + 1 ))
304     ;;
305     --crosswalk-bin)
306         target="crosswalk-bin"
307         exclusive_options=$(( $exclusive_options + 1 ))
308     ;;
309     --gbs-debug)
310         ARGS[$count]=--debug
311     ;;
312     --rpmlint)
313         RPMLINT=1
314         count=$(( $count + 1 ))
315     ;;
316     --noinit)
317         NOINIT=1
318         ARGS[$count]="$1"
319         count=$(( $count + 1 ))
320     ;;
321     *)
322       ARGS[$count]="$1"
323     ;;
324     esac
325     shift;
326   done
327
328   if [ "$exclusive_options" -gt 1 ]; then
329     echo "ERROR: --libs and --crosswalk-bin are mutually exclusive parameters."
330     exit 1
331   fi
332
333   cd $TOPDIR
334   rm -f packaging
335   ln -sf tizen_src/packaging packaging
336
337   if [ "$target" == "libs" ]; then
338     SPEC_FILE="chromium-efl-libs.spec"
339   elif [ "$target" == "crosswalk-bin" ]; then
340     SPEC_FILE="crosswalk-bin.spec"
341   fi
342
343   if [ "$(echo "${PROFILE}" | grep -Po "v3.0")" != "" -a "$NOINIT" == 0 ]; then
344     prepareTizen3Build $PROFILE $RPMLINT
345   fi
346
347   gbs $CONF_FLAG build -P $PROFILE --spec $SPEC_FILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS --incremental
348 }
349
350 function prepareTizen3Build() {
351   local PROFILE=$1
352   local RPMLINT=$2
353   BUILD_CONF_OPTS=""
354
355   # In case of '_rpmlint 1', build.conf of gbs repo will be used, enabling rpmlint.
356   # Otherwise, locally prepared build.conf will be used, disabling rpmlint.
357   local PREVIOUS_BUILD_CONF_PATH=""
358
359   if [ "$PROFILE" == "tztv_v3.0_arm-wayland" ]; then
360     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm_wayland.conf"
361   elif [ "$PROFILE" == "tzmb_v3.0_arm-wayland" ]; then
362     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm_wayland.conf"
363   elif [ "$PROFILE" == "tzmb_v3.0_arm64-wayland" ]; then
364     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm64_wayland.conf"
365   fi
366
367   local PREVIOUS_RPMLINT="!rpmlint"
368   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
369     # Never built before
370     PREVIOUS_RPMLINT=""
371   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
372     # Once built with rpmlint
373     PREVIOUS_RPMLINT="rpmlint"
374   fi
375
376   # Disable rpmlint
377   if [ "$RPMLINT" == 0 ]; then
378     echo "** Disable rpmlint"
379     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
380     rm -rf $BUILD_CONF_DIR
381     mkdir $BUILD_CONF_DIR
382     REPO=http://download.tizen.org/snapshots/tizen/$platform/latest/repos/$(echo $ARCHITECTURE | sed -e "s/armv7l/arm/;s/aarch64/arm64/")-wayland/packages/repodata/
383     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
384     BUILD_CONF_GZ=$(awk -F\" '{ print $6 }' $BUILD_CONF_DIR/index.html | grep "build.conf.gz")
385     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
386     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
387     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
388       echo "It's failed to donwload build.conf. Please contact system administrator."
389       exit 1
390     fi
391     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
392     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
393     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
394     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
395       echo "** Once built with rpmlint"
396       BUILD_CONF_OPTS+=" --clean"
397     fi
398   else # Enable rpmlint
399     echo "** Enable rpmlint"
400     BUILD_CONF_OPTS=""
401     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
402       BUILD_CONF_OPTS="--clean"
403     fi
404   fi
405 }