[M67 Dev][Tizen] Migrate version and profile related changes
[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 empty value for the latest tizen version
7 # or set DEFAULT_TIZEN_VERSION to current tizen version for the others.
8 export DEFAULT_TIZEN_VERSION=
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=
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=0
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       --clang)
94         export USE_CLANG=1
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]*" | uniq || :)
188   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" | uniq || :)
189
190   while [[ $# > 0 ]]; do
191     count=$(( $count + 1 ))
192     case "$1" in
193     --debug)
194         ARGS[$count]=--define
195         count=$(( $count + 1 ))
196         ARGS[$count]="_debug_mode 1"
197     ;;
198     --skip-ninja)
199         ARGS[$count]=--define
200         count=$(( $count + 1 ))
201         ARGS[$count]="_skip_ninja 1"
202     ;;
203     --skip-gn)
204         ARGS[$count]=--define
205         count=$(( $count + 1 ))
206         ARGS[$count]="_skip_gn 1"
207     ;;
208     --component-build)
209         ARGS[$count]=--define
210         count=$(( $count + 1 ))
211         ARGS[$count]="component_build 1"
212     ;;
213     --gbs-debug)
214         ARGS[$count]=--debug
215     ;;
216     --rpmlint)
217         RPMLINT=1
218         count=$(( $count + 1 ))
219     ;;
220     --nodebug)
221         ARGS[$count]=--define
222         count=$(( $count + 1 ))
223         ARGS[$count]="_nodebug 1"
224     ;;
225     --noinit)
226         NOINIT=1
227         ARGS[$count]="$1"
228         count=$(( $count + 1 ))
229     ;;
230     --mirror)
231         MIRROR=1
232     ;;
233     --standard*)
234         if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
235           echo $1
236           PROFILE=tz_$(echo $1 | sed 's/--//g')
237         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
238           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
239         else
240           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
241         fi
242     ;;
243     --emulator*)
244         if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
245           PROFILE=tz_$(echo $1 | sed 's/--//g')
246         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
247           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
248         else
249           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
250         fi
251     ;;
252     --tizen*)
253     ;;
254     *)
255       ARGS[$count]="$1"
256     ;;
257     esac
258     shift;
259   done
260
261   if [ "$PROFILE" == "" ]; then
262     if [[ $platform == "mobile" ]]; then
263       PROFILE=tzmb_3.0_target-TM1
264     elif [[ $platform == "tv" ]]; then
265       if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
266         PROFILE=tztv_arm-kantm
267       else
268         PROFILE=tztv_${DEFAULT_TIZEN_VERSION}_arm-kantm
269       fi
270     elif [[ $platform == "da" ]]; then
271       if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
272         PROFILE=tzda_arm-kantm
273       else
274         PROFILE=tzda_${DEFAULT_TIZEN_VERSION}_arm-kantm
275       fi
276     else
277       echo "Cannot set default PROFILE for platform=${platform}"
278       exit 1
279     fi
280   fi
281
282   if [ "$MIRROR" == "1" ]; then
283     PROFILE=${PROFILE}_mirror
284   fi
285
286   echo "Set the profile : $PROFILE"
287
288   if [ "$ARCHITECTURE" == "" ]; then
289     if [[ $platform == "mobile" ]]; then
290       ARCHITECTURE=armv7l
291     elif [[ $platform == "mobile_emulator" ]]; then
292       ARCHITECTURE=i586
293     elif [[ $platform == "tv" ]]; then
294       ARCHITECTURE=armv7l
295     elif [[ $platform == "tv_emulator" ]]; then
296       ARCHITECTURE=i586
297     else
298       echo "Cannot set default ARCHITECTURE for platform=${platform}"
299       exit 1
300     fi
301   fi
302   echo "Set the architecture : $ARCHITECTURE"
303
304   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
305     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
306   fi
307
308   if [ "$(echo "${PROFILE}" | grep -P "kant|jazz|hawk|product")" == "" -a "$NOINIT" == 0 ]; then
309     processRpmlintOption $PROFILE $RPMLINT
310   fi
311
312   gbs $CONF_FLAG build -P $PROFILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS --incremental
313 }
314
315 function processRpmlintOption() {
316   local PROFILE=$1
317   local RPMLINT=$2
318   local URL_TARGET=
319   export BUILD_CONF_OPTS=
320
321   echo "** Process rpmlint option"
322
323   local PREVIOUS_RPMLINT="!rpmlint"
324   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
325     # Never built before
326     PREVIOUS_RPMLINT=""
327   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
328     # Once built with rpmlint
329     PREVIOUS_RPMLINT="rpmlint"
330   fi
331
332   # Disable rpmlint
333   if [ "$RPMLINT" == 0 ]; then
334     echo "** Disable rpmlint"
335     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
336     rm -rf $BUILD_CONF_DIR
337     mkdir $BUILD_CONF_DIR
338     URL_TARGET=$(echo $PROFILE | sed -e 's#.*\.[0-9]*_\([-a-zA-Z0-9]*\).*#\1#;s/tz_//g')
339     # The latest version doesn't have tizen version in snapshot repository url.
340     if [ "$(echo $DEFAULT_TIZEN_VERSION)" == "" ]; then
341       URL_TIZEN_VERSION=
342     else
343       URL_TIZEN_VERSION=$DEFAULT_TIZEN_VERSION-
344     fi
345     REPO=http://download.tizen.org/snapshots/tizen/$URL_TIZEN_VERSION$platform/latest/repos/$URL_TARGET/packages/repodata/
346     echo "** Repo : $REPO"
347     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
348     BUILD_CONF_GZ=$(grep "build.conf.gz" $BUILD_CONF_DIR/index.html | sed -e 's#.*\=\"\(.*\)\".*#\1#')
349     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
350     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
351     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
352       echo "It's failed to donwload build.conf. Please contact system administrator."
353       exit 1
354     fi
355     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
356     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
357     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
358     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
359       echo "** Once built with rpmlint"
360       BUILD_CONF_OPTS+=" --clean"
361     fi
362   else # Enable rpmlint
363     echo "** Enable rpmlint"
364     BUILD_CONF_OPTS=""
365     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
366       BUILD_CONF_OPTS="--clean"
367     fi
368   fi
369 }