59db70d2391bd966cf4e58e2a2941ac70fd83c60
[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 # Please set DEFAULT_TIZEN_VERSION to 'latest' for the latest tizen version
7 # or set DEFAULT_TIZEN_VERSION to current tizen version for the others.
8 export DEFAULT_TIZEN_VERSION=latest
9
10 if [ "$(echo "$@" | grep -e "--tizen")" != "" ]; then
11   tizen_version=$(echo $@ | sed -e 's#.*--tizen_\([0-9.]*\).*#\1#')
12   if $(echo $tizen_version | grep -qe "^[-\?[0-9]\+\.\?[0-9]*$" && echo true || echo false); then
13     DEFAULT_TIZEN_VERSION=$tizen_version
14   else
15     DEFAULT_TIZEN_VERSION=latest
16   fi
17 fi
18
19 function getHostOs() {
20   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
21 }
22
23 function getHostArch() {
24   echo $(uname -m | sed -e \
25         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/;s/aarch64/arm64/')
26 }
27
28 function getPythonVersion() {
29   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
30 }
31
32 function setIfUndef() {
33     eval original=\$$1
34     new=$2
35     if [ -n "$original" ]; then
36         echo $original
37     else
38         echo $new
39     fi
40 }
41
42
43 function hostBuldScriptUsage() {
44 cat << EOF
45 usage: $1 [OPTIONS]
46
47 Build non gbs version of chromium-efl
48
49 OPTIONS:
50    -h, --help            Show this message
51    --build-ewk-unittests Build ewk unittests
52    --ccache              Configure ccache installed in your system
53    --clang               Use chromium's clang compiler to build the sources
54    --no-content-shell    Don't build content_shell application
55    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
56    -jN                   Set number of jobs, just like with make or ninja
57    --skip-ninja          Skip ninja step
58
59 examples:
60 $0 --ccache
61 $0 --skip-ninja
62 EOF
63   exit
64 }
65
66 function parseHostBuildScriptParams() {
67
68   export USE_CCACHE=0
69   export USE_CLANG=1
70   export FORCE_JHBUILD=0
71   export SKIP_NINJA=0
72   export BUILD_EWK_UNITTESTS=0
73   export BUILD_CONTENT_SHELL=1
74   export BUILD_SUBDIRECTORY=Release
75   export COMPONENT_BUILD=0
76
77   local platform="$1"
78   shift
79
80   while [[ $# > 0 ]]; do
81     case "$1" in
82       -h|--help)
83         hostBuldScriptUsage ${0}
84         ;;
85       --skip-gn)
86         export SKIP_GN=1
87         ;;
88       --ccache)
89         echo using ccache
90         export USE_CCACHE=1
91         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
92         ;;
93       --gcc)
94         export USE_CLANG=0
95         ;;
96       --no-content-shell)
97         export BUILD_CONTENT_SHELL=0
98         ;;
99       --force-jhbuild)
100         export FORCE_JHBUILD=1
101         ;;
102       --skip-ninja)
103         export SKIP_NINJA=1
104         ;;
105       --build-ewk-unittests)
106         export BUILD_EWK_UNITTESTS=1
107         ;;
108       --debug)
109         export BUILD_SUBDIRECTORY="Debug"
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 hostGnChromiumEfl() {
127   if [[ $SKIP_GN != 1 ]]; then
128     local XWALK_ARG=""
129     local COMPONENT_ARG=""
130     if [[ $COMPONENT_BUILD == 1 ]]; then
131       COMPONENT_ARG="component=shared_library"
132     fi
133     ${TOPDIR}/tizen_src/build/gn_chromiumefl.sh \
134       $XWALK_ARG \
135       $COMPONENT_ARG \
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_CHROMEDRIVER == 1 ]]; then
150       TARGETS="$TARGETS chromedriver"
151     fi
152     export BUILD_SUBDIRECTORY=""
153     BUILDDIR=${GN_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
154     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
155   fi
156 }
157
158 function error_report() {
159   echo "Error: File:$1 Line:$2"
160   exit 1
161 }
162
163 function findElementInArray() {
164   local elm
165   for elm in "${@:2}"; do
166     [[ "$elm" = "$1" ]] && return 0;
167   done
168   return 1;
169 }
170
171 function setupAndExecuteTargetBuild() {
172   local platform="$1"
173   shift
174
175   local PROFILE
176   local ARCHITECTURE
177   local CONF_FLAG
178   local -a ARGS
179
180   local count=0
181   local exclusive_options=0
182   local RPMLINT=0
183   local NOINIT=0
184   local MIRROR=0
185
186   # "|| :" means "or always succeeding built-in command"
187   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" | head -1 || :)
188   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" | head -1 || :)
189   GBS_ROOT=$(echo "$@" | grep -Po "(?<=\-B\s)[^\s]*" | head -1 || :)
190
191   while [[ $# > 0 ]]; do
192     count=$(( $count + 1 ))
193     case "$1" in
194     --debug)
195         ARGS[$count]=--define
196         count=$(( $count + 1 ))
197         ARGS[$count]="_debug_mode 1"
198     ;;
199     --skip-ninja)
200         ARGS[$count]=--define
201         count=$(( $count + 1 ))
202         ARGS[$count]="_skip_ninja 1"
203     ;;
204     --skip-gn)
205         ARGS[$count]=--define
206         count=$(( $count + 1 ))
207         ARGS[$count]="_skip_gn 1"
208     ;;
209     --component-build)
210         ARGS[$count]=--define
211         count=$(( $count + 1 ))
212         ARGS[$count]="component_build 1"
213     ;;
214     --gbs-debug)
215         ARGS[$count]=--debug
216     ;;
217     --rpmlint)
218         RPMLINT=1
219         count=$(( $count + 1 ))
220     ;;
221     --nodebug)
222         ARGS[$count]=--define
223         count=$(( $count + 1 ))
224         ARGS[$count]="_nodebug 1"
225     ;;
226     --noinit)
227         NOINIT=1
228         ARGS[$count]="$1"
229         count=$(( $count + 1 ))
230     ;;
231     --mirror)
232         MIRROR=1
233     ;;
234     --gcc)
235         ARGS[$count]=--define
236         count=$(( $count + 1 ))
237         ARGS[$count]="_gcc 1"
238     ;;
239     --clang)
240         ARGS[$count]=--define
241         count=$(( $count + 1 ))
242         ARGS[$count]="_clang 1"
243     ;;
244     --standard*)
245         if [ "$DEFAULT_TIZEN_VERSION" == "latest" ]; then
246           echo $1
247           PROFILE=tz_$(echo $1 | sed 's/--//g')
248         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
249           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
250         else
251           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
252         fi
253     ;;
254     --emulator*)
255         if [ "$DEFAULT_TIZEN_VERSION" == "latest" ]; then
256           PROFILE=tz_$(echo $1 | sed 's/--//g')
257         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
258           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
259         else
260           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
261         fi
262     ;;
263     --tizen*)
264     ;;
265     *)
266       ARGS[$count]="$1"
267     ;;
268     esac
269     shift;
270   done
271
272   if [ "$PROFILE" == "" ]; then
273     if [[ $platform == "mobile" ]]; then
274       PROFILE=tzmb_3.0_target-TM1
275     elif [[ $platform == "tv" ]]; then
276       if [ "$DEFAULT_TIZEN_VERSION" == "latest" ]; then
277         PROFILE=tztv_arm-kantm2
278       elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
279         PROFILE=tztv_4.0_arm-kantm
280       fi
281     elif [[ $platform == "da" ]]; then
282       if [ "$DEFAULT_TIZEN_VERSION" == "latest" ]; then
283         PROFILE=tzda_arm-kantm
284       else
285         PROFILE=tzda_${DEFAULT_TIZEN_VERSION}_arm-kantm
286       fi
287     else
288       echo "Cannot set default PROFILE for platform=${platform}"
289       exit 1
290     fi
291   fi
292
293   if [ "$MIRROR" == "1" ]; then
294     PROFILE=${PROFILE}_mirror
295   fi
296
297   echo "Set the profile : $PROFILE"
298
299   if [ "$ARCHITECTURE" == "" ]; then
300     if [[ $platform == "mobile" ]]; then
301       ARCHITECTURE=armv7l
302     elif [[ $platform == "mobile_emulator" ]]; then
303       ARCHITECTURE=i586
304     elif [[ $platform == "tv" ]]; then
305       ARCHITECTURE=armv7l
306     elif [[ $platform == "tv_emulator" ]]; then
307       ARCHITECTURE=i586
308     else
309       echo "Cannot set default ARCHITECTURE for platform=${platform}"
310       exit 1
311     fi
312   fi
313   echo "Set the architecture : $ARCHITECTURE"
314
315   if [ "$(echo "${PROFILE}" | grep -P "kant|jazz|hawk|product")" == "" -a "$NOINIT" == 0 ]; then
316     processRpmlintOption $PROFILE $RPMLINT
317   fi
318   local BRANCH=$(echo $(basename $(git symbolic-ref HEAD)))
319   if [ "$(echo $BRANCH | grep dev)" != "" ]; then
320     BRANCH=dev
321   elif [ "$(echo $BRANCH | grep beta)" != "" ]; then
322     BRANCH=beta
323   else
324     BRANCH=release
325   fi
326   local CHROMIUM_VERSION=$(echo $(head -n 1 chrome/VERSION) | sed -e 's/MAJOR=//g')
327
328   local GBS_ROOT_OPT=
329   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
330     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
331     if [ "$GBS_ROOT" == "" ]; then
332       GBS_ROOT_OPT="-B ~/GBS-ROOT-M${CHROMIUM_VERSION}-${PROFILE^^}-TIZEN_${DEFAULT_TIZEN_VERSION^^}-${BRANCH^^}"
333     else
334       GBS_ROOT_OPT="-B $GBS_ROOT"
335     fi
336   fi
337
338   gbs $CONF_FLAG build -P $PROFILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS --incremental $GBS_ROOT_OPT
339 }
340
341 function processRpmlintOption() {
342   local PROFILE=$1
343   local RPMLINT=$2
344   local URL_TARGET=
345   export BUILD_CONF_OPTS=
346
347   echo "** Process rpmlint option"
348
349   local PREVIOUS_RPMLINT="!rpmlint"
350   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
351     # Never built before
352     PREVIOUS_RPMLINT=""
353   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
354     # Once built with rpmlint
355     PREVIOUS_RPMLINT="rpmlint"
356   fi
357
358   # Disable rpmlint
359   if [ "$RPMLINT" == 0 ]; then
360     echo "** Disable rpmlint"
361     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
362     rm -rf $BUILD_CONF_DIR
363     mkdir $BUILD_CONF_DIR
364     URL_TARGET=$(echo $PROFILE | sed -e 's#.*\.[0-9]*_\([-a-zA-Z0-9]*\).*#\1#;s/tz_//g')
365     # The latest version doesn't have tizen version in snapshot repository url.
366     if [ "$(echo $DEFAULT_TIZEN_VERSION)" == "latest" ]; then
367       URL_TIZEN_VERSION=
368     else
369       URL_TIZEN_VERSION=$DEFAULT_TIZEN_VERSION-
370     fi
371     REPO=http://download.tizen.org/snapshots/tizen/$URL_TIZEN_VERSION$platform/latest/repos/$URL_TARGET/packages/repodata/
372     echo "** Repo : $REPO"
373     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
374     BUILD_CONF_GZ=$(grep "build.conf.gz" $BUILD_CONF_DIR/index.html | sed -e 's#.*\=\"\(.*\)\".*#\1#')
375     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
376     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
377     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
378       echo "It's failed to donwload build.conf. Please contact system administrator."
379       exit 1
380     fi
381     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
382     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
383     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
384     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
385       echo "** Once built with rpmlint"
386       BUILD_CONF_OPTS+=" --clean"
387     fi
388   else # Enable rpmlint
389     echo "** Enable rpmlint"
390     BUILD_CONF_OPTS=""
391     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
392       BUILD_CONF_OPTS="--clean"
393     fi
394   fi
395 }