Integrate chromedriver in a simpler way.
[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_CHROMEDRIVER=0
68   export BUILD_SUBDIRECTORY=Release
69   export COMPONENT_BUILD=0
70
71   local platform="$1"
72   shift
73
74   while [[ $# > 0 ]]; do
75     case "$1" in
76       -h|--help)
77         hostBuldScriptUsage ${0}
78         ;;
79       --skip-gyp)
80         export SKIP_GYP=1
81         ;;
82       --ccache)
83         echo using ccache
84         export USE_CCACHE=1
85         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
86         ;;
87       --clang)
88         export USE_CLANG=1
89         ;;
90       --no-content-shell)
91         export BUILD_CONTENT_SHELL=0
92         ;;
93       --force-jhbuild)
94         export FORCE_JHBUILD=1
95         ;;
96       --skip-ninja)
97         export SKIP_NINJA=1
98         ;;
99       --build-ewk-unittests)
100         export BUILD_EWK_UNITTESTS=1
101         ;;
102       --debug)
103         export BUILD_SUBDIRECTORY="Debug"
104         ;;
105       --xwalk)
106         export BUILD_XWALK=1
107         ;;
108       --chromedriver)
109         export BUILD_CHROMEDRIVER=1
110         ;;
111       --component-build)
112         export COMPONENT_BUILD=1
113         ;;
114       -j*)
115         export JOBS="$1"
116         ;;
117       *)
118         echo "Unknown argument: $1"
119         exit 1
120         ;;
121     esac
122     shift;
123   done
124 }
125
126 function hostGypChromiumEfl() {
127   if [[ $SKIP_GYP == 0 ]]; then
128     local XWALK_ARG=""
129     local COMPONENT_ARG=""
130     if [[ $BUILD_XWALK == 1 ]]; then
131       XWALK_ARG="--xwalk"
132     fi
133     if [[ $COMPONENT_BUILD == 1 ]]; then
134       COMPONENT_ARG="-Dcomponent=shared_library"
135     fi
136     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh \
137       $XWALK_ARG \
138       $COMPONENT_ARG \
139       -Doutdir="$TOPDIR/out.$(getHostArch)" \
140       $@
141   fi
142 }
143
144 function hostNinja() {
145   if [[ $SKIP_NINJA == 0 ]]; then
146     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
147     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
148       TARGETS="$TARGETS ewk_unittests"
149     fi
150     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
151       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
152     fi
153     if [[ $BUILD_XWALK == 1 ]]; then
154       TARGETS="$TARGETS xwalk"
155     fi
156     if [[ $BUILD_CHROMEDRIVER == 1 ]]; then
157       TARGETS="$TARGETS chromedriver"
158     fi
159     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
160     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
161   fi
162 }
163
164 function error_report() {
165   echo "Error: File:$1 Line:$2"
166   exit 1
167 }
168
169 function findElementInArray() {
170   local elm
171   for elm in "${@:2}"; do
172     [[ "$elm" = "$1" ]] && return 0;
173   done
174   return 1;
175 }
176
177 function setupAndExecuteTargetBuild() {
178
179   local platform="$1"
180   shift
181
182   local PROFILE
183   local ARCHITECTURE
184   local CONF_FLAG
185   local SPEC_FILE="chromium-efl.spec"
186   local -a ARGS
187
188   # "|| :" means "or always succeeding built-in command"
189   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
190   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" || :)
191
192   if [ "$PROFILE" == "" ]; then
193     if [[ $platform == "mobile" ]]; then
194       PROFILE=tzmb_v3.0_arm64-wayland
195     elif [[ $platform == "mobile_emulator" ]]; then
196       PROFILE=tzmb_v3.0_emulator-wayland
197     elif [[ $platform == "tv" ]]; then
198       PROFILE=tztv_v3.0_arm-wayland
199     elif [[ $platform == "tv_emulator" ]]; then
200       PROFILE=tztv_v3.0_emulator-wayland
201     else
202       echo "Cannot set default PROFILE for platform=${platform}"
203       exit 1
204     fi
205   fi
206   echo "Set the profile : $PROFILE"
207
208   if [ "$ARCHITECTURE" == "" ]; then
209     if [[ $platform == "mobile" ]]; then
210       ARCHITECTURE=aarch64
211     elif [[ $platform == "mobile_emulator" ]]; then
212       ARCHITECTURE=i586
213     elif [[ $platform == "tv" ]]; then
214       ARCHITECTURE=armv7l
215     elif [[ $platform == "tv_emulator" ]]; then
216       ARCHITECTURE=i586
217     else
218       echo "Cannot set default ARCHITECTURE for platform=${platform}"
219       exit 1
220     fi
221   fi
222   echo "Set the architecture : $ARCHITECTURE"
223
224   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
225     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
226   fi
227
228   EXTRA_PACK_OPTS=""
229   if [ "$PROFILE" == "tztv_v2.4_product" ]; then
230     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
231   fi
232
233   if [ "$(echo "${PROFILE}" | grep -Po "v3.0")" != "" ]; then
234     prepareTizen3Build $PROFILE
235   fi
236
237   local count=0
238   local exclusive_options=0
239   while [[ $# > 0 ]]; do
240     count=$(( $count + 1 ))
241     case "$1" in
242     --debug)
243         ARGS[$count]=--define
244         count=$(( $count + 1 ))
245         ARGS[$count]="_debug_mode 1"
246     ;;
247     --skip-ninja)
248         ARGS[$count]=--define
249         count=$(( $count + 1 ))
250         ARGS[$count]="_skip_ninja 1"
251     ;;
252     --skip-gyp)
253         ARGS[$count]=--define
254         count=$(( $count + 1 ))
255         ARGS[$count]="_skip_gyp 1"
256     ;;
257     --xwalk)
258         ARGS[$count]=--define
259         count=$(( $count + 1 ))
260         ARGS[$count]="build_xwalk 1"
261     ;;
262     --component-build)
263         ARGS[$count]=--define
264         count=$(( $count + 1 ))
265         ARGS[$count]="component_build 1"
266     ;;
267     --libs)
268         target="libs"
269         exclusive_options=$(( $exclusive_options + 1 ))
270     ;;
271     --crosswalk-bin)
272         target="crosswalk-bin"
273         exclusive_options=$(( $exclusive_options + 1 ))
274     ;;
275     --gbs-debug)
276         ARGS[$count]=--debug
277     ;;
278     --chromedriver)
279         ARGS[$count]=--define
280         count=$(( $count + 1 ))
281         ARGS[$count]="build_chromedriver 1"
282     ;;
283     *)
284       ARGS[$count]="$1"
285     ;;
286     esac
287     shift;
288   done
289
290   if [[ $exclusive_options -gt 1 ]]; then
291     echo "ERROR: --libs and --crosswalk-bin are mutually exclusive parameters."
292     exit 1
293   fi
294
295   cd $TOPDIR
296   rm -f packaging
297   ln -sf tizen_src/packaging packaging
298
299   if [ "$target" == "libs" ]; then
300     SPEC_FILE="chromium-efl-libs.spec"
301   elif [ "$target" == "crosswalk-bin" ]; then
302     SPEC_FILE="crosswalk-bin.spec"
303   fi
304
305   gbs $CONF_FLAG build -P $PROFILE --spec $SPEC_FILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS --incremental
306 }
307
308 function prepareTizen3Build() {
309   local PROFILE=$1
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   local LOCAL_BUILD_CONF_PATH=""
316
317   if [ "$PROFILE" == "tztv_v3.0_arm-wayland" ]; then
318     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm-walynad.conf"
319     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tztv_v3.0_arm-wayland.conf"
320   elif [ "$PROFILE" == "tzmb_v3.0_arm-wayland" ]; then
321     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm-walynad.conf"
322     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm-wayland.conf"
323   elif [ "$PROFILE" == "tzmb_v3.0_arm64-wayland" ]; then
324     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm64-walynad.conf"
325     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm64-wayland.conf"
326   fi
327
328   local PREVIOUS_RPMLINT="!rpmlint"
329   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
330     PREVIOUS_RPMLINT=""
331   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
332     PREVIOUS_RPMLINT="rpmlint"
333   fi
334
335   if [ "$LOCAL_BUILD_CONF_PATH" != "" ]; then
336     BUILD_CONF_OPTS="-D $LOCAL_BUILD_CONF_PATH"
337   fi
338
339   if [ "$(echo "$@" | grep -Po "_rpmlint\ 1")" == "" ]; then
340     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
341       BUILD_CONF_OPTS+=" --clean"
342     fi
343   else
344     BUILD_CONF_OPTS=""
345     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
346       BUILD_CONF_OPTS="--clean"
347     fi
348   fi
349 }