Remove wayland from ozone platform build target
[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 export LATEST_TIZEN_VERSION=7.0
7 export DEFAULT_TIZEN_VERSION=$LATEST_TIZEN_VERSION
8
9 if [ "$(echo "$@" | grep -e "--tizen")" != "" ]; then
10   tizen_version=$(echo $@ | sed -e 's#.*--tizen_\([0-9.]*\).*#\1#')
11   DEFAULT_TIZEN_VERSION=$tizen_version
12 fi
13
14 # Generate gbs.conf
15 export PUBLIC_REPO_VERSION=
16 if [ "$DEFAULT_TIZEN_VERSION" != "${LATEST_TIZEN_VERSION}" ]; then
17   PUBLIC_REPO_VERSION=$DEFAULT_TIZEN_VERSION-
18 fi
19 sed -e "s/@PUBLIC_REPO_VERSION@/$PUBLIC_REPO_VERSION/g" \
20     -e "s/@TIZEN_VERSION@/$DEFAULT_TIZEN_VERSION/g" \
21     tizen_src/build/gbs.conf.in > tizen_src/build/gbs.conf
22
23 function getSystemDeps() {
24   local host_arch=$(getHostArch)
25   local platform=$1
26   local system_deps="--system-libraries
27                      libpng
28                      libxml
29                      libxslt
30                      zlib
31                     "
32   # Tizen profile
33   if [ "$platform" != "desktop" ]; then
34     # Emulator profile
35     if [ "$host_arch" == "x86" -o "$host_arch" == "x64" ]; then
36       system_deps+="libjpeg
37                    "
38     fi
39     # Non product tv profiles on tizen 6.0
40     if [ "$platform" != "tv" -a "$DEFAULT_TIZEN_VERSION" == "6.0" ]; then
41       system_deps+="icu
42                    "
43     fi
44   fi
45   echo $system_deps
46 }
47
48 function getHostOs() {
49   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
50 }
51
52 function getHostArch() {
53   echo $(uname -m | sed -e \
54         's/i.86/x86/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/x86/;s/aarch64/arm64/')
55 }
56
57 function getGccVersion() {
58   echo $(gcc -dumpversion)
59 }
60
61 function getPythonVersion() {
62   echo $(python3 --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
63 }
64
65 function setIfUndef() {
66     eval original=\$$1
67     new=$2
68     if [ -n "$original" ]; then
69         echo $original
70     else
71         echo $new
72     fi
73 }
74
75 function hostBuldScriptUsage() {
76 cat << EOF
77 usage: $1 [OPTIONS]
78
79 Build non gbs version of chromium-efl
80
81 OPTIONS:
82    -h, --help            Show this message
83    --build-ewk-unittests Build ewk unittests
84    --enable-pepper-extensions    Enable Tizen Pepper Extensions
85    --ccache              Configure ccache installed in your system
86    --clang               Use chromium's clang compiler to build the sources
87    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
88    -jN                   Set number of jobs, just like with make or ninja
89    --skip-ninja          Skip ninja step
90
91 examples:
92 $0 --ccache
93 $0 --skip-ninja
94 EOF
95   exit
96 }
97
98 function undoReplacedGn() {
99   local system_deps=$(getSystemDeps $1)
100   if [ "$system_deps" != "" ]; then
101     echo "** use system lib : undo **"
102     # Restore gn files to their original states not to mess up the tree permanently.
103     $TOPDIR/build/linux/unbundle/replace_gn_files.py --undo $system_deps icu
104   fi
105 }
106
107 function parseHostBuildScriptParams() {
108   trap 'undoReplacedGn $1' SIGINT
109   export USE_CCACHE=0
110   export USE_CLANG=1
111   export FORCE_JHBUILD=0
112   export SKIP_NINJA=0
113   export BUILD_EWK_UNITTESTS=0
114   export BUILD_CHROME=0
115   export BUILD_SUBDIRECTORY=Release
116   export COMPONENT_BUILD=0
117   export ENABLE_PEPPER_EXTENSIONS=0
118
119   local platform="$1"
120   shift
121
122   while [[ $# > 0 ]]; do
123     case "$1" in
124       -h|--help)
125         hostBuldScriptUsage ${0}
126         ;;
127       --skip-gn)
128         export SKIP_GN=1
129         ;;
130       --ccache)
131         echo using ccache
132         export USE_CCACHE=1
133         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
134         ;;
135       --gcc)
136         export USE_CLANG=0
137         ;;
138       --build-chrome)
139         export BUILD_CHROME=1
140         ;;
141       --force-jhbuild)
142         export FORCE_JHBUILD=1
143         ;;
144       --skip-ninja)
145         export SKIP_NINJA=1
146         ;;
147       --build-ewk-unittests)
148         export BUILD_EWK_UNITTESTS=1
149         ;;
150       --debug)
151         export BUILD_SUBDIRECTORY="Debug"
152         ;;
153       --component-build)
154         export COMPONENT_BUILD=1
155         ;;
156       --enable-pepper-extensions)
157         export ENABLE_PEPPER_EXTENSIONS=1
158         ;;
159       -j*)
160         export JOBS="$1"
161         ;;
162       *)
163         echo "Unknown argument: $1"
164         exit 1
165         ;;
166     esac
167     shift;
168   done
169 }
170
171 function hostGnChromiumEfl() {
172   if [[ $SKIP_GN != 1 ]]; then
173     local XWALK_ARG=""
174     local COMPONENT_ARG=""
175     local PEPPER_EXTENSIONS_ARG=""
176     if [[ $COMPONENT_BUILD == 1 ]]; then
177       COMPONENT_ARG="component=shared_library"
178     fi
179     if [[ $ENABLE_PEPPER_EXTENSIONS == 1 ]]; then
180       PEPPER_EXTENSIONS_ARG="tizen_pepper_extensions=true"
181     fi
182     ${TOPDIR}/tizen_src/build/gn_chromiumefl.sh \
183       $XWALK_ARG \
184       $COMPONENT_ARG \
185       $PEPPER_EXTENSIONS_ARG \
186       $@
187   fi
188 }
189
190 function hostNinja() {
191   if [[ $SKIP_NINJA == 0 ]]; then
192     if [[ $BUILD_CHROME == 1 ]]; then
193       TARGETS="content_shell chrome"
194     else
195       TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
196     fi
197     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
198       TARGETS="$TARGETS ewk_unittests"
199     fi
200     if [[ $BUILD_CHROMEDRIVER == 1 ]]; then
201       TARGETS="$TARGETS chromedriver"
202     fi
203     export BUILD_SUBDIRECTORY=""
204     BUILDDIR=${GN_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
205     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
206   fi
207   undoReplacedGn $1
208 }
209
210 function error_report() {
211   echo "Error: File:$1 Line:$2"
212   exit 1
213 }
214
215 function findElementInArray() {
216   local elm
217   for elm in "${@:2}"; do
218     [[ "$elm" = "$1" ]] && return 0;
219   done
220   return 1;
221 }
222
223 function setupAndExecuteTargetBuild() {
224   local platform="$1"
225   shift
226
227   local PROFILE
228   local ARCHITECTURE
229   local CONF_FLAG
230   local -a ARGS
231
232   local exclusive_options=0
233   local RPMLINT=0
234   local NOINIT=0
235   local MIRROR=0
236   local LOCAL_BUILD=1
237   local RELEASE_BUILD=0
238   local MAKE_SQUASHFS_RPM=0
239
240   # "|| :" means "or always succeeding built-in command"
241   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" | head -1 || :)
242   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" | head -1 || :)
243   GBS_ROOT=$(echo "$@" | grep -Po "(?<=\-B\s)[^\s]*" | head -1 || :)
244
245   while [[ $# > 0 ]]; do
246     case "$1" in
247     --debug)
248         ARGS+=(--define "_debug_mode 1")
249     ;;
250     --skip-ninja)
251         ARGS+=(--define "_skip_ninja 1")
252     ;;
253     --skip-gn)
254         ARGS+=(--define "_skip_gn 1")
255     ;;
256     --ttrace)
257         ARGS[$count]=--define
258         count=$(( $count + 1 ))
259         ARGS[$count]="_ttrace 1"
260     ;;
261     --component-build)
262         ARGS+=(--define "component_build 1")
263     ;;
264     --disable-wrtjs)
265         ARGS+=(--define "_disable_wrt_js 1")
266     ;;
267     --gbs-debug)
268         ARGS+=(--debug)
269     ;;
270     --icu=*)
271         ARGS+=(--define "_use_system_icu $(echo $1 | sed -e 's/--icu=//g')")
272     ;;
273     --rpmlint)
274         RPMLINT=1
275     ;;
276     --nodebug)
277         ARGS+=(--define "_nodebug 1")
278     ;;
279     --noinit)
280         NOINIT=1
281         ARGS+=("$1")
282     ;;
283     --mirror)
284         MIRROR=1
285     ;;
286     --release)
287         LOCAL_BUILD=0
288         RELEASE_BUILD=1
289     ;;
290     --squashfs)
291         MAKE_SQUASHFS_RPM=1
292     ;;
293     --gcc)
294         LOCAL_BUILD=0
295         ARGS+=(--define "_clang 0")
296     ;;
297     --clang)
298         LOCAL_BUILD=0
299         ARGS+=(--define "_clang 1")
300     ;;
301     --standard*)
302         PROFILE=tz_$(echo $1 | sed 's/--//g')
303     ;;
304     --emulator*)
305         PROFILE=tz_$(echo $1 | sed 's/--//g')
306     ;;
307     --tizen*)
308     ;;
309     --build-chrome)
310         ARGS+=(--define "_build_chrome 1")
311     ;;
312     *)
313       ARGS+=("$1")
314     ;;
315     esac
316     shift;
317   done
318
319   ARGS+=(--define "_make_squashfs_rpm $MAKE_SQUASHFS_RPM")
320
321   if [ "$LOCAL_BUILD" == "1" ]; then
322     ARGS+=(--define "_local_build 1")
323     local _jobs=$((`/usr/bin/getconf _NPROCESSORS_ONLN` / 2 - `ps -ef | grep " ninja " | wc -l` -1))
324     local _smp_mflags=-j$(if ((${_jobs} > 10)); then echo ${_jobs}; else echo 10; fi)
325     ARGS+=(--define "_costomized_smp_mflags $_smp_mflags")
326     # Default values
327     ARGS+=(--define "_clang 1")
328   fi
329
330   if [ "$RELEASE_BUILD" == "1" ]; then
331     ARGS+=(--define "_local_build 0")
332     if [[ $platform == "tv" ]]; then
333       ARGS+=(--define "_clang 1")
334     else
335       ARGS+=(--define "_clang 0")
336       ARGS+=(--define "_no_lto 0")
337     fi
338   fi
339
340   if [ "$PROFILE" == "" ]; then
341     if [[ $platform == "tv" ]]; then
342       PROFILE=tztv_${DEFAULT_TIZEN_VERSION}_arm-pontusm
343     elif [[ $platform == "da" ]]; then
344       PROFILE=tzda_${DEFAULT_TIZEN_VERSION}_arm-kantm
345     elif [[ $platform == "wearable" ]]; then
346       PROFILE=tzwr_5.5_arm-spin
347     else
348       echo "Cannot set default PROFILE for platform=${platform}"
349       exit 1
350     fi
351   fi
352
353   if [ "$MIRROR" == "1" ]; then
354     PROFILE=${PROFILE}_mirror
355   fi
356
357   echo "Set the profile : $PROFILE"
358
359   if [ "$ARCHITECTURE" == "" ]; then
360     ARCHITECTURE=armv7l
361   fi
362   echo "Set the architecture : $ARCHITECTURE"
363
364   if [ "$(echo "${PROFILE}" | grep -P "tz_standard")" != "" -a "$NOINIT" == 0 ]; then
365     processRpmlintOption $PROFILE $RPMLINT
366   fi
367   local BRANCH=$(echo $(basename $(git symbolic-ref HEAD)))
368   if [ "$(echo $BRANCH | grep dev)" != "" ]; then
369     BRANCH=dev
370   elif [ "$(echo $BRANCH | grep beta)" != "" ]; then
371     BRANCH=beta
372   else
373     BRANCH=release
374   fi
375   local CHROMIUM_VERSION=$(echo $(head -n 1 chrome/VERSION) | sed -e 's/MAJOR=//g')
376
377   local GBS_ROOT_OPT=
378   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
379     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
380     if [ "$GBS_ROOT" == "" ]; then
381       GBS_ROOT_OPT="-B ~/GBS-ROOT-M${CHROMIUM_VERSION}-${PROFILE^^}-TIZEN_${DEFAULT_TIZEN_VERSION^^}-${BRANCH^^}"
382     else
383       GBS_ROOT_OPT="-B $GBS_ROOT"
384     fi
385   fi
386
387   processICU initialize_icu
388   gbs $CONF_FLAG build -P $PROFILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS --incremental $GBS_ROOT_OPT
389
390   undoReplacedGn $platform
391   processICU restore_icu
392 }
393
394 function processICU() {
395   local ICU_PATH="$TOPDIR/third_party/icu/source"
396   local ICU_REPLACE_PATH="$TOPDIR/third_party/icu/source_replace"
397
398   if [ "$1" == "replace_icu" ]; then
399     if [ ! -e $ICU_REPLACE_PATH ] && [ -e $ICU_PATH ]; then
400       echo "** third_party/icu/source is replaced to use system icu."
401       mv $ICU_PATH $ICU_REPLACE_PATH
402     fi
403   elif [ "$1" == "restore_icu" ]; then
404     if [ -e $ICU_REPLACE_PATH ] && [ ! -e $ICU_PATH ]; then
405       echo "** third_party/icu/source is restored."
406       mv $ICU_REPLACE_PATH $ICU_PATH
407     fi
408   elif [ "$1" == "initialize_icu" ]; then
409     if [ -e $ICU_REPLACE_PATH ]; then
410       echo "** third_party/icu/source is initialized."
411       rm -rf $ICU_PATH
412       mv $ICU_REPLACE_PATH $ICU_PATH
413     fi
414   fi
415 }
416
417 function processRpmlintOption() {
418   local PROFILE=$1
419   local RPMLINT=$2
420   local URL_TARGET=
421   export BUILD_CONF_OPTS=
422
423   echo "** Process rpmlint option"
424
425   local PREVIOUS_RPMLINT="!rpmlint"
426   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
427     # Never built before
428     PREVIOUS_RPMLINT=""
429   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
430     # Once built with rpmlint
431     PREVIOUS_RPMLINT="rpmlint"
432   fi
433
434   # Disable rpmlint
435   if [ "$RPMLINT" == 0 ]; then
436     echo "** Disable rpmlint"
437     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
438     rm -rf $BUILD_CONF_DIR
439     mkdir $BUILD_CONF_DIR
440     URL_TARGET=$(echo $PROFILE | sed -e 's#.*\.[0-9]*_\([-a-zA-Z0-9]*\).*#\1#;s/tz_//g')
441     # The latest version doesn't have tizen version in snapshot repository url.
442     if [ "$DEFAULT_TIZEN_VERSION" == "${LATEST_TIZEN_VERSION}" ]; then
443       URL_TIZEN_VERSION=
444     else
445       URL_TIZEN_VERSION=$DEFAULT_TIZEN_VERSION-
446     fi
447     REPO=http://download.tizen.org/snapshots/tizen/$URL_TIZEN_VERSION$platform/latest/repos/$URL_TARGET/packages/repodata/
448     echo "** Repo : $REPO"
449     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
450     BUILD_CONF_GZ=$(grep "build.conf.gz" $BUILD_CONF_DIR/index.html | sed -e 's#.*\=\"\(.*\)\".*#\1#')
451     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
452     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
453     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
454       echo "It's failed to donwload build.conf. Please contact system administrator."
455       exit 1
456     fi
457     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
458     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
459     if [ "$DEFAULT_TIZEN_VERSION" == "6.0" ]; then
460       sed -i 's/tizen_version_major 5/tizen_version_major 6/g' $BUILD_CONF_DIR/$BUILD_CONF
461       sed -i 's/tizen_version_minor 5/tizen_version_minor 0/g' $BUILD_CONF_DIR/$BUILD_CONF
462     fi
463     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
464     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
465       echo "** Once built with rpmlint"
466       BUILD_CONF_OPTS+=" --clean"
467     fi
468   else # Enable rpmlint
469     echo "** Enable rpmlint"
470     BUILD_CONF_OPTS=""
471     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
472       BUILD_CONF_OPTS="--clean"
473     fi
474   fi
475 }