Merge "Fix scroll bar to draw in the overlay mode" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / scripts / tcbuild.sh
1 #!/bin/bash
2
3 #---------- DEBUG_BEGIN ----------
4 #ARG="-d" # debug-on flag, might be set as $1
5 # keyprompt "introductory message" -- wait until any key pressed
6 function keyprompt { echo -ne "\n\e[1;31m$1 -- " && read -n 1 && echo -e "\n\e[0m"; }
7 # d_bp -- breakpoint at which user need to press any key to proceed
8 function d_bp { if [[ "$ARG" == "-d" ]]; then keyprompt "d >> Press any key"; fi }
9 # d_showVar VARNAME -- print bash variable name
10 function d_showVar { if [ "$ARG" == "-d" -a -n "$1" ]; then echo "d >> ${1} = ${!1}"; fi }
11 # d_print "message" -- print a debug message
12 function d_print { if [ "$ARG" == "-d" -a -n "$1" ]; then echo -e "d >> $1"; fi }
13 #----------  DEBUG_END  ----------
14
15 PROJECT_DIR="$(cd "$(dirname $0)" && pwd)"
16 d_showVar PROJECT_DIR
17
18 function gbs_profile {
19 perl -e "
20 use Config::Tiny;
21 my \$Config = Config::Tiny->read( \"\$ENV{HOME}/.gbs.conf\" );
22 my \$profile = \$Config->{general}->{profile};
23 \$profile =~ s/profile.//;
24 print \$profile;"
25 }
26
27 PROFILE=`gbs_profile`
28 RPM_DIR="$HOME/GBS-ROOT/local/repos/$PROFILE/armv7l/RPMS"
29 d_showVar RPM_DIR
30
31 function add_module {
32     # argument check
33     if [ -z "$1" ]; then echo "Usage: `basename $0` addmod <module_name> [module_lib_name]"; exit 1; fi
34
35     MODULE_NAME=$1
36     d_showVar MODULE_NAME
37     MODULE_NAME_C=$(echo $MODULE_NAME | sed -e 's/-\([a-z]\)/\U\1/' -e 's/^\([a-z]\)/\U\1/')
38     d_showVar MODULE_NAME_C
39     MODULE_NAME_U=$(echo $MODULE_NAME | sed -e 's/-/_/')
40     d_showVar MODULE_NAME_U
41 #    MODULE_LIBNAME=${2:-capi-$MODULE_NAME}
42     MODULE_LIBNAME=$1
43     d_showVar MODULE_LIBNAME
44
45     echo "Adding $MODULE_NAME module to project..."
46     d_bp
47     cd $PROJECT_DIR
48     # prepare .spec file
49     echo "-- Generating packaging/core-$MODULE_NAME-tests.spec file"
50     if [ ! -d packaging ]; then mkdir packaging; fi
51     sed -e "s:\[MODULE_NAME\]:$MODULE_NAME:g" -e "s:\[MODULE_LIBNAME\]:$MODULE_LIBNAME:g" \
52         templates/core-\[module_name\]-tests.spec > packaging/core-$MODULE_NAME-tests.spec
53     # prepare src directory
54     mkdir src/$MODULE_NAME
55     echo "-- Generating src/$MODULE_NAME/CMakeLists.txt file"
56     sed -e "s:%{MODULE_NAME}:$MODULE_NAME:g" -e "s:%{MODULE_LIBNAME}:$MODULE_LIBNAME:g" \
57         templates/src-directory/CMakeLists.txt > src/$MODULE_NAME/CMakeLists.txt
58     echo "-- Generating src/$MODULE_NAME/tct-$MODULE_NAME-core.c file"
59     sed -e "s:%{MODULE_NAME}:$MODULE_NAME:g" \
60         templates/src-directory/tct-\[module_name\]-core.c > src/$MODULE_NAME/tct-$MODULE_NAME-core.c
61     echo "-- Generating src/$MODULE_NAME/utc-$MODULE_NAME.c file"
62     sed -e "s:%{MODULE_NAME_U}:$MODULE_NAME_U:g" -e "s:%{MODULE_NAME_C}:$MODULE_NAME_C:g" \
63         templates/src-directory/utc-\[module_name\].c > src/$MODULE_NAME/utc-$MODULE_NAME.c
64     echo "Task finished successfully"
65 }
66
67 function rm_module {
68     # argument check
69     if [ -z "$1" ]; then echo "Usage: `basename $0` rmmod <module_name>"; exit 1; fi
70
71     MODULE_NAME=$1
72     d_showVar MODULE_NAME
73
74     echo "Removing $MODULE_NAME module from project..."
75     d_bp
76     echo "---- Updating /opt/tct/packages/package_list.xml"
77     scripts/tcpackageslistsgen.sh $MODULE_NAME /opt/tct/packages/package_list.xml 1
78     if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
79    # echo "---- Updating test plans"
80    # scripts/tcpackageslistsgen.sh $MODULE_NAME /opt/tct/manager/plan/*.xml 1
81    # if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
82
83     cd $PROJECT_DIR
84     echo "-- Removing packaging/core-$MODULE_NAME-tests.spec file"
85     rm packaging/core-$MODULE_NAME-tests.spec
86     echo "-- Removing src/$MODULE_NAME directory"
87     rm -r src/$MODULE_NAME
88     echo "Task finished successfully"
89 }
90
91 function build {
92     if [ -n "$1" ]; then
93         (cd src/$1; ../../scripts/tcheadgen.sh tct-$1-core.h)
94         if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
95         cp packaging/core-$1-tests.spec ../packaging
96         cp .gitignore-without-autogenerated-files .gitignore
97         gbs build -A armv7l --spec core-$1-tests.spec --include-all --keep-packs | \
98             tee build.log | stdbuf -o0 sed -e 's/error:/\x1b[1;91m&\x1b[0m/' \
99                                            -e 's/warning:/\x1b[93m&\x1b[0m/'
100         rm ../packaging/core-$1-tests.spec
101         cp .gitignore-with-autogenerated-files .gitignore
102     else
103         echo "Build requires a module name"
104         exit 1
105     fi
106 }
107
108 function inst {
109     if [ -z "$1" ]
110     then
111         for mod in `ls -1 src/ | grep -v CMakeLists`
112         do
113
114         if [ $mod != 'common' ] && [ $mod != 'manual' ]; then
115
116             PKG_NAME="core-$mod-tests"
117             d_showVar PKG_NAME
118             VER=$(cat packaging/$PKG_NAME.spec | awk '/^Version:/ { print $2; exit; }')
119             d_showVar VER
120             PKG_VNAME="$PKG_NAME-$VER"
121             d_showVar PKG_VNAME
122             PKG_FNAME="$PKG_VNAME-0.armv7l.rpm"
123             d_showVar PKG_FNAME
124
125             if [ -f "$RPM_DIR/$PKG_FNAME" ]
126             then
127                 inst $mod
128                 echo ""
129             fi
130         fi
131         done
132     else
133         cd $PROJECT_DIR
134         # setting variables
135         MOD_NAME="$1"
136         d_showVar MOD_NAME
137         PKG_NAME="core-$MOD_NAME-tests"
138         d_showVar PKG_NAME
139         VER=$(cat packaging/$PKG_NAME.spec | awk '/^Version:/ { print $2; exit; }')
140         d_showVar VER
141         PKG_VNAME="$PKG_NAME-$VER"
142         d_showVar PKG_VNAME
143         PKG_FNAME="$PKG_VNAME-0.armv7l.rpm"
144         d_showVar PKG_FNAME
145         TCT_DIR="opt/tct-$MOD_NAME-core-tests"
146         d_showVar TCT_DIR
147
148         echo "Deploying $MOD_NAME suite to tct-mgr..."
149         d_bp
150         # prepare tct directory and files
151         echo "-- Preparing suite .zip file..."
152         echo "---- Creating /tmp/$TCT_DIR directory"
153         rm -r /tmp/opt > /dev/null 2>&1
154         mkdir -p /tmp/$TCT_DIR
155         # README
156         echo "---- Copying /tmp/$TCT_DIR"
157         cp templates/tct-package/README /tmp/$TCT_DIR
158         # rpm
159         echo "---- Copying /tmp/$TCT_DIR package"
160         cp $RPM_DIR/$PKG_FNAME /tmp/$TCT_DIR
161         if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
162         # inst.sh
163         echo "---- Generating /tmp/$TCT_DIR/inst.sh file"
164         sed -e "s:%{PKG_NAME}:\"$PKG_NAME\":g" -e "s:%{PKG_FULLNAME}:\"$PKG_FNAME\":g" \
165             -e "s:%{PKG_DIR}:\"/opt/usr/media/tct/$TCT_DIR\":g" \
166             templates/tct-package/inst.sh > /tmp/$TCT_DIR/inst.sh
167         chmod a+x /tmp/$TCT_DIR/inst.sh
168         # tests.xml
169         echo "---- Generating /tmp/$TCT_DIR"
170         scripts/tctestsgen.sh $MOD_NAME /tmp/$TCT_DIR target
171         if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
172         # zip
173         echo "---- Preparing /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip file"
174         # clear old zips
175         rm -r /tmp/tct/packages > /dev/null 2>&1
176         mkdir -p /tmp/tct/packages
177         # create new zip
178         ( cd /tmp; zip -r /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip opt > /dev/null 2>&1; )
179         # deployment
180         echo "-- Suite deployment..."
181         echo "---- Copying /opt/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip"
182         cp /tmp/tct/packages/tct-$MOD_NAME-core-tests-2.2.1-1.zip /opt/tct/packages/
183         echo "---- Updating /opt/tct/packages/package_list.xml"
184         scripts/tcpackageslistsgen.sh $MOD_NAME /opt/tct/packages/package_list.xml 0
185         if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
186        # echo "---- Updating test plans"
187        # for file in `grep -r tct-$MOD_NAME-core-tests /opt/tct/manager/plan/ | cut -d: -f1 | uniq`
188        # do
189        #     scripts/tcpackageslistsgen.sh $MOD_NAME $file
190        # done
191        # scripts/tcpackageslistsgen.sh $MOD_NAME /opt/tct/manager/plan/Full_test.xml
192        # if [ $? -ne 0 ]; then echo "Aborting..."; exit 1; fi
193         echo "Task finished successfully"
194     fi
195 }
196
197 if [ -z "$1" ]; then
198     # usage note
199     echo "Usage: `basename $0` <addmod|rmmod|build|install> <module_name> [module_lib_name]"
200     exit 1
201 elif [ "addmod" == "$1" ]; then
202     # add new module
203     add_module $2 $3
204 elif [ "rmmod" == "$1" ]; then
205     # remove module
206     rm_module $2
207 elif [ "build" == "$1" ]; then
208     # build the binary
209     build $2
210 elif [ "install" == "$1" ]; then
211     # install
212     inst $2
213 else
214     echo "Invalid subcommand: $1"
215 fi