summaryrefslogtreecommitdiff
path: root/yoctorc
blob: 20e095e732516a016252ed1ed0f1530430a81c5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Yocto shortcut functions
#
# source this file manually or from bashrc

# ----- customize here ----------

#YOCTODIR="${HOME}"
YOCTODIR=${YOCTODIR:-$HOME}

#OEDIR=${YOCTODIR}/oe-core
OEDIR=${OEDIR:-$YOCTODIR/yoctoTizen_IVI}

#EDITOR="gview -p"
EDITOR=${EDITOR:-kate}

# --------------------------------

if [[ ! "$PATH" =~ "$YOCTODIR/bin:" ]]; then
    echo "Adding path"
    export PATH=$YOCTODIR/bin:$PATH
fi

function yinit () {
    cd $OEDIR
    YOCTO_BUILDDIR=$OEDIR/${1:-build}
    init=no
    if [[ ! -d $YOCTO_BUILDDIR ]]; then 
	init=yes
    fi

    . ./oe-init-build-env $1 >/dev/null 2>&1
    cd $YOCTO_BUILDDIR

    if [[ x$init == xyes ]]; then
	cp -v ../meta-tizen-ivi/conf/bblayers.conf.sample conf/bblayers.conf
	cp -v ../meta-tizen-ivi/conf/local.conf.sample conf/local.conf
	${EDITOR} conf/local.conf
    fi
}

function ycheck() {
    if [[ -z "$YOCTO_BUILDDIR" ]]; then
	echo "yinit must be called first" >&2
	return 1
    fi

    return 0
}

function ystatus() {
    if [[ -z "$YOCTO_BUILDDIR" ]]; then
	echo "yinit not called" >&2
	return 1
    fi

    echo "YOCTODIR=$YOCTODIR"
    echo "OEDIR=$OEDIR"
    echo "YOCTO_BUILDDIR=$YOCTO_BUILDDIR"
    echo "YOCTO_LAST_PKG=$YOCTO_LAST_PKG"

    return 0
}

function ycd () {
    ycheck || return 1

    cd $YOCTO_BUILDDIR

    pkg=$1
    if [[ "$pkg" == "-" ]]; then
	pkg=$YOCTO_LAST_PKG
    fi
    if [[ -n "$pkg" ]]; then
	subdir=${2:-src}

	case "$subdir" in
	    bb)
		pkgdir=$(ls -tr -d ../meta-tizen-ivi/recipes-tizen/$pkg 2>/dev/null | tail -1)
		;;
	    *)
		pkgdir=$(ls -tr -d tmp*/work/*/$pkg 2>/dev/null | tail -1)
		;;
	esac
	[[ -z "$pkgdir" ]] && { echo "Unable to find package dir" >&2; return 1; }

	cd $pkgdir
	case "$subdir" in
	    temp|tmp) cd */temp || return 1 ;;
	    src) cd git-*/git 2>/dev/null || cd */[0-9]* 2>/dev/null ;;
	    *) ;;
	esac

	YOCTO_LAST_PKG=$pkg
    fi
}

function ybb () {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    [[ -z "pkg" ]] && { echo "Usage: ybb <pkg>" >&2; return 1; }
    ycd $pkg bb
}

function ysrc () {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    [[ -z "pkg" ]] && { echo "Usage: ysrc <pkg>" >&2; return 1; }
    ycd $pkg src
}

function ytmp () {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    [[ -z "pkg" ]] && { echo "Usage: ytmp <pkg>" >&2; return 1; }
    ycd $pkg temp
}

function ydep () {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    [[ -z "pkg" ]] && { echo "Usage: ydep <pkg>" >&2; return 1; }

    pushd $YOCTO_BUILDDIR >/dev/null || return
    bitbake -g -u depexp $pkg &
    popd >/dev/null
}

function yshell () {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    [[ -z "pkg" ]] && { echo "Usage: yshell <pkg>" >&2; return 1; }
    pushd $YOCTO_BUILDDIR >/dev/null || return
    bitbake -c devshell $pkg 
    popd >/dev/null
}

function bbake() {
    ycheck || return 1
    pushd $YOCTO_BUILDDIR >/dev/null || return
    bitbake "$@"
    popd >/dev/null
}


function yed() {
    ycheck || return 1

    pkg=${1:-$YOCTO_LAST_PKG}
    shift
    what=${@:-configure log spec}

    [[ -z "$pkg" ]] && { echo "Usage: yed <pkgname> [configure|log|spec]" >&2; return 2; }

    pushd $YOCTO_BUILDDIR >/dev/null || return

    for x in $(ls -d tmp*/work/*/$pkg); do
	echo "$pkg: $x"
	files=

	pushd $x >/dev/null

	# find log files
	if [[ "$what" =~ "log" ]]; then
	    for tmpdir in $(ls -d */temp); do 
		echo "tmpdir: $tmpdir"

		files+=$(awk '{print "log." $1}' $tmpdir/log.task_order | tac | sed "s|^| $tmpdir/|g") 
		files+=" $tmpdir"
	    done
	fi

	# find run files
	if [[ "$what" =~ "run" ]]; then
	    for tmpdir in $(ls -d */temp); do 
		echo "tmpdir: $tmpdir"

		files+=$(ls $tmpdir/run*)
		files+=" $tmpdir"
	    done
	fi

	# find spec files
	if [[ "$what" =~ "spec" ]]; then
	    for spec in $(ls */*/packaging/*.spec 2>/dev/null); do
		files+=" $spec"
		files+=" $(dirname $(dirname $spec))"
	    done
	fi

	# find autoconf files
	if [[ "$what" =~ "configure" ]]; then
	    for p in configure.ac configure.in config.log configure; do 
		for f in $(ls */*/$p 2>/dev/null); do
		    files+=" $f"
		done
	    done
	fi

	${EDITOR:-xdg-open} $files

	popd >/dev/null
    done


    popd >/dev/null
}

function ymount_work() {
    ycheck || return 1

    pushd $YOCTO_BUILDDIR >/dev/null || return

    workdir=$(ls -d tmp-*/work 2>/dev/null)
    [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }

    realwdir=$(cd $workdir && pwd -P)
    if grep $realwdir /proc/mounts >/dev/null; then
	echo "$workdir already mounted"
	popd >/dev/null
	return 1
    fi

    mv $workdir ${workdir}.old
    mkdir -p $workdir
    sudo mount tmpfs -t tmpfs $workdir || return 2
    mv ${workdir}.old/* $workdir/ 
    rmdir ${workdir}.old

    popd >/dev/null
}

function yumount_work() {
    ycheck || return 1

    pushd $YOCTO_BUILDDIR >/dev/null || return

    workdir=$(ls -d tmp-*/work 2>/dev/null)
    [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }

    realwdir=$(cd $workdir && pwd -P)
    if ! grep $realwdir /proc/mounts >/dev/null; then
	echo "$workdir already unmounted"
	popd >/dev/null
	return 1
    fi

    mkdir -p ${workdir}.new
    mv $workdir/* ${workdir}.new
    sudo umount $workdir 
    rmdir $workdir
    mv ${workdir}.new $workdir

    popd >/dev/null
}

function yreport() {
    ycheck || return 1

    pushd $YOCTO_BUILDDIR >/dev/null || return

    workdir=$(ls -d tmp-* 2>/dev/null)
    [[ -z "$workdir" ]] && { echo "Unable to find work dir"; return 1; }

    pushd $workdir/stamps >/dev/null || return 2

    echo "Architecture;Package;Version;State"
    for arch in $(ls -d * 2>/dev/null); do
	pushd $arch >/dev/null || return 3
	for pkg in $(ls -d * 2>/dev/null); do 
	    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); }')

	    ver=$(cut -f1 -d';' <<<$data)
	    step=$(cut -f2 -d';' <<<$data)

	    state=$(egrep "^$step:" <<EOF 
:UNKNOWN
fetch:FAIL
unpack:FAIL
patch:FAIL
configure:FAIL
compile:FAIL
build :FAIL
populate_lic:FAIL
populate_sysroot:FAIL
populate_sysroot_setscene:FAIL
packagedata:OK
packagedata_setscene:OK
package_setscene:OK
package_write:OK
package_write_rpm:OK
package_write_rpm_setscene:OK
EOF
)
	    state=$(cut -f2 -d':' <<<$state)

	    echo "$arch;$pkg;$ver;$step;$state"
	done
	popd >/dev/null
    done

    popd >/dev/null
    popd >/dev/null
}

if [[ "$PS1" ]]; then
    echo "Sourced ~/.yoctorc"
fi