forked from milianw/shell-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash_setup_kde4_programming
More file actions
405 lines (354 loc) · 10.4 KB
/
bash_setup_kde4_programming
File metadata and controls
405 lines (354 loc) · 10.4 KB
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/bin/bash
###############################################################
# KDE 4 DEVELOPMENT
#
# If you just want to setup your environment for kde4
# development, download this file and save it somewhere
# now put the following line (with the path pointing to
# your just downloaded file) into your ~/.bashrc:
#
# . ~/path/to/this/file
#
# Example (the leading # has to be ommitted of course!)
# . ~/.bash_setup_kde4_programming
###############################################################
# you might have to change the actual filename in the path below
# in my git repo the file is called kde4_setup_build_environment.sh
# NOTE: it's important this lies in ~/.kde/env so it gets
# called at KDE startup. This makes compiled applications
# available via KRunner etc.
. ~/.bin/kde4_setup_build_environment.sh
# Use makeobj instead of make, to automatically switch to the build dir.
# If you don't have makeobj, install the package named kdesdk-scripts or
# kdesdk, or check out kdesdk/scripts from svn.
# use -rR for speed
alias make='makeobj -rR'
# Uncomment the following lines if DBus does not work. DBus is not
# working if, when you run `dbus-uuidgen --ensure && qdbus`, you get an error.
#
# alias dbusstart="eval `PATH=$DBUSDIR/bin \
# $DBUSDIR/bin/dbus-launch --auto-syntax`"
# A function to easily build the project in the current directory
#
# builds in the dir depending on what you set OBJ_REPLACEMENT to
# installs to "install" folder in the project folder
#
# cd ~/projects/...
# cmakeproject
function cmakeproject {
local srcdir builddir installdir
srcdir=$(pwd)
installdir="$srcdir/install"
builddir=$(echo $srcdir | sed -e "$OBJ_REPLACEMENT")
mkdir -p "$builddir"
cd "$builddir"
cmake "$srcdir" -DCMAKE_INSTALL_PREFIX="$installdir" \
-DCMAKE_BUILD_TYPE=debugfull \
-DKDE4_BUILD_TESTS=ON
nice make install
cd "$srcdir"
}
# A function to easily build the current directory of KDE.
#
# This builds only the sources in the current ~/{src,build}/KDE subdirectory.
# Usage: cs KDE/kdebase && cmakekde
# will build/rebuild the sources in ~/src/KDE/kdebase
function cmakekde {
local srcFolder current switched fail
switched=0
if test -n "$1"; then
# srcFolder is defined via command line argument
srcFolder="$1"
else
# get srcFolder for current dir
srcFolder=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
fi
# we are in the src folder, change to build directory
# Alternatively, we could just use makeobj in the commands below...
current=`pwd`
if [ "$srcFolder" = "$current" ]; then
cb
switched=1
fi
fail=0
# to enable tests, add -DKDE4_BUILD_TESTS=ON to the next line.
# you can also change "debugfull" to "debug" to save disk space.
cmake "$srcFolder" -DCMAKE_INSTALL_PREFIX=$KDEDIR \
-DCMAKE_BUILD_TYPE=debugfull \
-DKDE4_AUTH_POLICY_FILES_INSTALL_DIR=$KDEDIR/share/polkit-1/actions \
-DKDE4_BUILD_TESTS=ON || fail=1
# uncomment the following two lines to make builds wait after
# configuration step, so that the user can check configure output
echo "Press <ENTER> to continue..."
read userinput
if [[ $fail == 1 ]]; then
return 1
fi
nice make && \
make install
kbuildsycoca4
if test $switched -eq 1; then
cs
fi
}
export -f cmakekde
# for the lazy ones, add/comment other directories
function cmakekdeall {
local directories
directories=(
kate
kdevplatform
kdevelop
php
)
for i in `seq 1 ${#directories[@]}`; do
echo "############## ${directories[$i-1]} ##############";
if [[ "$1" == "" ]]; then
cs ${directories[$i-1]} && update_cs && cb && make install;
else
cs ${directories[$i-1]} && update_cs && cmakekde;
fi
done
}
# update the source code which is either in git or in svn
# TODO: return not-0 when nothing got updated, i.e parse output
function update_cs {
local output
if [[ -d ".git" || -d "../.git" ]]; then
output=$(git svn rebase)
elif [[ -d ".svn" || -d "../.svn" ]]; then
output=$(svn up)
fi
return 0
}
# A function to easily change to the build directory.
# Usage: cb KDE/kdebase
# will change to $KDE_BUILD/KDE/kdebase
# Usage: cb
# will simply go to the build folder if you are currently in a src folder
# Example:
# $ pwd
# /home/user/src/KDE/kdebase
# $ cb && pwd
# /home/user/build/KDE/kdebase
function cb {
local dest
# Make sure build directory exists.
mkdir -p "$KDE_BUILD"
# command line argument
if test -n "$1"; then
cd "$KDE_BUILD/$1"
return
fi
# substitute src dir with build dir
dest=`pwd | sed -e $OBJ_REPLACEMENT`
if test ! -d "$dest"; then
# build directory does not exist, create
mkdir -p "$dest"
fi
cd "$dest"
}
export -f cb
# Change to the source directory. Same as cb, except this
# switches to $KDE_SRC instead of $KDE_BUILD.
# Usage: cs KDE/kdebase
# will change to $KDE_SRC/KDE/kdebase
# Usage: cs
# will simply go to the source folder if you are currently in a build folder
# Example:
# $ pwd
# /home/user/build/KDE/kdebase
# $ cs && pwd
# /home/user/src/KDE/kdebase
function cs {
local dest current
# Make sure source directory exists.
mkdir -p "$KDE_SRC"
# command line argument
if test -n "$1"; then
cd "$KDE_SRC/$1"
else
# substitute build dir with src dir
dest=`pwd | sed -e s,$KDE_BUILD,$KDE_SRC,`
current=`pwd`
if [ "$dest" = "$current" ]; then
cd "$KDE_SRC"
else
cd "$dest"
fi
fi
}
export -f cs
# Add autocompletion to cs function
function _cs_scandir
{
local base ext
base=$1
ext=$2
if [ -d $base ]; then
for d in `ls $base`; do
if [ -d $base/$d ]; then
dirs="$dirs $ext$d/"
fi
done
fi
}
function _cs()
{
local cur dirs
_cs_scandir "$KDE_SRC"
_cs_scandir "$KDE_SRC/KDE" "KDE/"
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
}
# Remove comment on next line to enable cs autocompletion
complete -F _cs cs
# run a given unit-test or all via ctest
function kdetest
{
local tests test args old_pwd tmpfile debug;
debug=
old_pwd=$(pwd)
cb
if [[ "$1" == "--debug" ]]; then
debug=$1
shift 1
fi
if [[ -d "$1" ]]; then
cd $1
shift 1
fi
tests=$(getTests $debug)
if [[ "$tests" == "" ]]; then
echo "this directory does not contain any unit tests!"
echo
cd "$old_pwd"
return 1
fi
tmpfile=/tmp/testoutput_$$
KDEHOME_backup=$KDEHOME
KDEHOME=~/.kde-unit-test
if [[ "$1" != "" ]]; then
test=$1
if [[ "$debug" == "--debug" ]]; then
test=${test/.shell/}
fi
shift 1
args=$@
if [ ! -f "$test" ] || ! in_array "$test" $tests ; then
if in_array "$test.shell" $tests; then
test="$test".shell
else
echo "could not find unittest '$test'. available are:"
echo $tests
echo
cd "$old_pwd"
return 1
fi
fi
if [[ "$debug" != "" ]]; then
gdb --eval-command="run" --args ./$test -maxwarnings 0 $args 2>&1 | tee -a "$tmpfile"
else
./$test -maxwarnings 0 $args 2>&1 | tee -a "$tmpfile"
fi
echo
else
# run all tests
for test in $tests; do
if [[ "$debug" != "" ]]; then
gdb --eval-command="run" --args ./$test -maxwarnings 0 2>&1 | tee -a "$tmpfile"
else
./$test -maxwarnings 0 2>&1 | tee -a "$tmpfile"
fi
done
fi
KDEHOME=$KDEHOME_backup
if [[ "$(grep -c "^RESULT " "$tmpfile")" != 0 ]]; then
echo
echo " --- BENCHMARKS --- "
grep --color=never -A 1 "^RESULT " "$tmpfile"
echo
fi
echo
echo " --- ALL PASSED TESTS --- "
grep --color=never "^PASS " "$tmpfile"
echo
echo $(grep -c "^PASS " "$tmpfile")" passed tests in total"
if [[ "$(grep -c "^XFAIL " "$tmpfile")" != 0 ]]; then
echo
echo " --- EXPECTED FAILURES --- "
perl -ne '(/^^XFAIL/../^ Loc:/) && print' "$tmpfile"
echo
echo $(grep -c "^XFAIL" "$tmpfile")" expected failed tests in total"
echo
fi
if [[ "$(grep -c "^XPASS " "$tmpfile")" != 0 ]]; then
echo
echo " --- UNEXPECTED PASSES --- "
perl -ne '(/^^XPASS/../^ Loc:/) && print' "$tmpfile"
echo
echo $(grep -c "^XPASS" "$tmpfile")" unexpected passed tests in total"
echo
fi
echo
echo " --- ALL FAILED TESTS --- "
perl -ne '(/^^FAIL!/../^ Loc:/) && print' "$tmpfile"
echo
echo $(grep -c "^FAIL!" "$tmpfile")" failed tests in total"
echo
grep --color=never "^QFATAL : " "$tmpfile"
grep --color=never -B 5 "^Segmentation fault" "$tmpfile"
rm "$tmpfile"
cd "$old_pwd"
}
# completion for kdetest
function _kdetest
{
local tests;
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
old_pwd=$(pwd)
cb
tests=$(getTests ${COMP_WORDS[1]})
if [[ "$prev" == "kdetest" || "$prev" == "--debug" ]]; then
# completion of tests
COMPREPLY=( $(compgen -W "${tests}" -- ${cur}) )
elif in_array "$prev" $tests; then
# completion of available functions
COMPREPLY=( $(compgen -W "$(./$prev -functions 2>/dev/null | cut -f 1 -d \( )" -- ${cur}) )
fi
cd "$old_pwd"
}
# removes .shell from the end of each test file
function getTests {
local tests;
tests=""
tests=$(LANG=en_US.UTF-8 ctest -N -V | grep "Test command:" | egrep -o ' [^ ]+$' | cut -c $(echo " "$(pwd)"/" | wc -c)-)
if [[ "$1" == "--debug" ]]; then
# remove trailing .shell
for t in $tests; do
echo -n ${t/.shell/}" "
done
echo
else
echo $tests
fi
}
complete -F _kdetest kdetest
# see http://ftp.hu.freebsd.org/pub/linux/distributions/frugalware/frugalware-testing/t/functions.sh
function in_array
{
local i
needle=$1
shift 1
# array() undefined
[ -z "$1" ] && return 1
for i in $*
do
[ "$i" == "$needle" ] && return 0
done
return 1
}
export -f in_array