tizen-3.0-ivi_20150201.3_atom.xml: archive manifest file
[scm/bb/tizen.git] / yoctorc
1 # Yocto shortcut functions
2 #
3 # source this file manually or from bashrc
4
5 # ----- customize here ----------
6
7 #YOCTODIR="${HOME}"
8 YOCTODIR=${YOCTODIR:-$HOME}
9
10 #OEDIR=${YOCTODIR}/oe-core
11 OEDIR=${OEDIR:-$YOCTODIR/yoctoTizen_IVI}
12
13 #EDITOR="gview -p"
14 EDITOR=${EDITOR:-kate}
15
16 # --------------------------------
17
18 if [[ ! "$PATH" =~ "$YOCTODIR/bin:" ]]; then
19     echo "Adding path"
20     export PATH=$YOCTODIR/bin:$PATH
21 fi
22
23 function yinit () {
24     cd $OEDIR
25     YOCTO_BUILDDIR=$OEDIR/${1:-build}
26     init=no
27     if [[ ! -d $YOCTO_BUILDDIR ]]; then 
28         init=yes
29     fi
30
31     . ./oe-init-build-env $1 >/dev/null 2>&1
32     cd $YOCTO_BUILDDIR
33
34     if [[ x$init == xyes ]]; then
35         cp -v ../meta-tizen-ivi/conf/bblayers.conf.sample conf/bblayers.conf
36         cp -v ../meta-tizen-ivi/conf/local.conf.sample conf/local.conf
37         ${EDITOR} conf/local.conf
38     fi
39 }
40
41 function ycheck() {
42     if [[ -z "$YOCTO_BUILDDIR" ]]; then
43         echo "yinit must be called first" >&2
44         return 1
45     fi
46
47     return 0
48 }
49
50 function ystatus() {
51     if [[ -z "$YOCTO_BUILDDIR" ]]; then
52         echo "yinit not called" >&2
53         return 1
54     fi
55
56     echo "YOCTODIR=$YOCTODIR"
57     echo "OEDIR=$OEDIR"
58     echo "YOCTO_BUILDDIR=$YOCTO_BUILDDIR"
59     echo "YOCTO_LAST_PKG=$YOCTO_LAST_PKG"
60
61     return 0
62 }
63
64 function ycd () {
65     ycheck || return 1
66
67     cd $YOCTO_BUILDDIR
68
69     pkg=$1
70     if [[ "$pkg" == "-" ]]; then
71         pkg=$YOCTO_LAST_PKG
72     fi
73     if [[ -n "$pkg" ]]; then
74         subdir=${2:-src}
75
76         case "$subdir" in
77             bb)
78                 pkgdir=$(ls -tr -d ../meta-tizen-ivi/recipes-tizen/$pkg 2>/dev/null | tail -1)
79                 ;;
80             *)
81                 pkgdir=$(ls -tr -d tmp*/work/*/$pkg 2>/dev/null | tail -1)
82                 ;;
83         esac
84         [[ -z "$pkgdir" ]] && { echo "Unable to find package dir" >&2; return 1; }
85
86         cd $pkgdir
87         case "$subdir" in
88             temp|tmp) cd */temp || return 1 ;;
89             src) cd git-*/git 2>/dev/null || cd */[0-9]* 2>/dev/null ;;
90             *) ;;
91         esac
92
93         YOCTO_LAST_PKG=$pkg
94     fi
95 }
96
97 function ybb () {
98     ycheck || return 1
99
100     pkg=${1:-$YOCTO_LAST_PKG}
101     [[ -z "pkg" ]] && { echo "Usage: ybb <pkg>" >&2; return 1; }
102     ycd $pkg bb
103 }
104
105 function ysrc () {
106     ycheck || return 1
107
108     pkg=${1:-$YOCTO_LAST_PKG}
109     [[ -z "pkg" ]] && { echo "Usage: ysrc <pkg>" >&2; return 1; }
110     ycd $pkg src
111 }
112
113 function ytmp () {
114     ycheck || return 1
115
116     pkg=${1:-$YOCTO_LAST_PKG}
117     [[ -z "pkg" ]] && { echo "Usage: ytmp <pkg>" >&2; return 1; }
118     ycd $pkg temp
119 }
120
121 function ydep () {
122     ycheck || return 1
123
124     pkg=${1:-$YOCTO_LAST_PKG}
125     [[ -z "pkg" ]] && { echo "Usage: ydep <pkg>" >&2; return 1; }
126
127     pushd $YOCTO_BUILDDIR >/dev/null || return
128     bitbake -g -u depexp $pkg &
129     popd >/dev/null
130 }
131
132 function yshell () {
133     ycheck || return 1
134
135     pkg=${1:-$YOCTO_LAST_PKG}
136     [[ -z "pkg" ]] && { echo "Usage: yshell <pkg>" >&2; return 1; }
137     pushd $YOCTO_BUILDDIR >/dev/null || return
138     bitbake -c devshell $pkg 
139     popd >/dev/null
140 }
141
142 function bbake() {
143     ycheck || return 1
144     pushd $YOCTO_BUILDDIR >/dev/null || return
145     bitbake "$@"
146     popd >/dev/null
147 }
148
149
150 function yed() {
151     ycheck || return 1
152
153     pkg=${1:-$YOCTO_LAST_PKG}
154     shift
155     what=${@:-configure log spec}
156
157     [[ -z "$pkg" ]] && { echo "Usage: yed <pkgname> [configure|log|spec]" >&2; return 2; }
158
159     pushd $YOCTO_BUILDDIR >/dev/null || return
160
161     for x in $(ls -d tmp*/work/*/$pkg); do
162         echo "$pkg: $x"
163         files=
164
165         pushd $x >/dev/null
166
167         # find log files
168         if [[ "$what" =~ "log" ]]; then
169             for tmpdir in $(ls -d */temp); do 
170                 echo "tmpdir: $tmpdir"
171
172                 files+=$(awk '{print "log." $1}' $tmpdir/log.task_order | tac | sed "s|^| $tmpdir/|g") 
173                 files+=" $tmpdir"
174             done
175         fi
176
177         # find run files
178         if [[ "$what" =~ "run" ]]; then
179             for tmpdir in $(ls -d */temp); do 
180                 echo "tmpdir: $tmpdir"
181
182                 files+=$(ls $tmpdir/run*)
183                 files+=" $tmpdir"
184             done
185         fi
186
187         # find spec files
188         if [[ "$what" =~ "spec" ]]; then
189             for spec in $(ls */*/packaging/*.spec 2>/dev/null); do
190                 files+=" $spec"
191                 files+=" $(dirname $(dirname $spec))"
192             done
193         fi
194
195         # find autoconf files
196         if [[ "$what" =~ "configure" ]]; then
197             for p in configure.ac configure.in config.log configure; do 
198                 for f in $(ls */*/$p 2>/dev/null); do
199                     files+=" $f"
200                 done
201             done
202         fi
203
204         ${EDITOR:-xdg-open} $files
205
206         popd >/dev/null
207     done
208
209
210     popd >/dev/null
211 }
212
213 function ymount_work() {
214     ycheck || return 1
215
216     pushd $YOCTO_BUILDDIR >/dev/null || return
217
218     workdir=$(ls -d tmp-*/work 2>/dev/null)
219     [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }
220
221     realwdir=$(cd $workdir && pwd -P)
222     if grep $realwdir /proc/mounts >/dev/null; then
223         echo "$workdir already mounted"
224         popd >/dev/null
225         return 1
226     fi
227
228     mv $workdir ${workdir}.old
229     mkdir -p $workdir
230     sudo mount tmpfs -t tmpfs $workdir || return 2
231     mv ${workdir}.old/* $workdir/ 
232     rmdir ${workdir}.old
233
234     popd >/dev/null
235 }
236
237 function yumount_work() {
238     ycheck || return 1
239
240     pushd $YOCTO_BUILDDIR >/dev/null || return
241
242     workdir=$(ls -d tmp-*/work 2>/dev/null)
243     [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }
244
245     realwdir=$(cd $workdir && pwd -P)
246     if ! grep $realwdir /proc/mounts >/dev/null; then
247         echo "$workdir already unmounted"
248         popd >/dev/null
249         return 1
250     fi
251
252     mkdir -p ${workdir}.new
253     mv $workdir/* ${workdir}.new
254     sudo umount $workdir 
255     rmdir $workdir
256     mv ${workdir}.new $workdir
257
258     popd >/dev/null
259 }
260
261 function yreport() {
262     ycheck || return 1
263
264     pushd $YOCTO_BUILDDIR >/dev/null || return
265
266     workdir=$(ls -d tmp-* 2>/dev/null)
267     [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }
268
269     pushd $workdir/stamps >/dev/null || return 2
270
271     echo "Architecture;Package;Version;State"
272     for arch in $(ls -d * 2>/dev/null); do
273         pushd $arch >/dev/null || return 3
274         for pkg in $(ls -d * 2>/dev/null); do 
275             data=$(ls -tr $pkg | grep -v ".sigdata." | tail -1 | awk '{ x=$0; gsub(/\.do_.+$/,"",x); y=substr($0,length(x)+5); gsub(/\..+$/,"",y); printf("%s;%s",x,y); }')
276
277             ver=$(cut -f1 -d';' <<<$data)
278             step=$(cut -f2 -d';' <<<$data)
279
280             state=$(egrep "^$step:" <<EOF 
281 :UNKNOWN
282 fetch:FAIL
283 unpack:FAIL
284 patch:FAIL
285 configure:FAIL
286 compile:FAIL
287 build :FAIL
288 populate_lic:FAIL
289 populate_sysroot:FAIL
290 populate_sysroot_setscene:FAIL
291 packagedata:OK
292 packagedata_setscene:OK
293 package_setscene:OK
294 package_write:OK
295 package_write_rpm:OK
296 package_write_rpm_setscene:OK
297 EOF
298 )
299             state=$(cut -f2 -d':' <<<$state)
300
301             echo "$arch;$pkg;$ver;$step;$state"
302         done
303         popd >/dev/null
304     done
305
306     popd >/dev/null
307     popd >/dev/null
308 }
309
310 if [[ "$PS1" ]]; then
311     echo "Sourced ~/.yoctorc"
312 fi