1
0
Fork 0
xcache/devel/run

357 lines
6.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# this script is for developers only
set -e
MAKE=/usr/bin/make
true() { # {{{1
return 0
}
hi() { # {{{1
colors=(4 2 3 5 6 7 8 9)
re=()
i=0
for r in "$@"; do
((color=$i % ${#colors[@]})) || true
color=${colors[$color]}
r="${r/\#/\\#}"
r="s#$r#[4${color}m\0#g"
re[$i]="-e$r"
((i=i+1))
done
sed -ur "${re[@]}"
}
hiecho() { # {{{1
echo """$@"""
}
# }}}
stopfpm() { # {{{1
if [[ -f $1 ]]; then
local pid=`cat $1 2>/dev/null || true`
if [[ $pid -gt 0 ]]; then
hiecho Stopping fpm $pid @ $1
kill $pid || true
fi
fi
}
xtest() { # {{{1
$MAKE -f devel/test.mak
}
prep() { # {{{1
$MAKE -f devel/prepare.mak "$@"
}
mergepo() { # {{{1
prep
local i
find htdocs -iname '*.po' | while read -r i; do
if [[ -f $i-merged ]]; then
mv $i-merged $i
fi
done
}
po2php() { # {{{1
mergepo
local phpfile
find htdocs -iname '*.po' | while read -r i; do
phpfile=${i/.po/.php}
devel/po2php.awk < $i > $phpfile.tmp
mv $phpfile.tmp $phpfile
done
}
updatedeps() { # {{{1
pwd=$(readlink -f "$(pwd)")
builddir=$(readlink -f ../trunk-php5-debug-zts)
if [[ -z $builddir ]]; then
hiecho required ../trunk-php5-debug-zts not found
return 1
fi
find . -iname \*.c | sort | while read -r sourceFile; do
sourceFile=${sourceFile#./}
case "$sourceFile" in
includes.c)
echo -n "\$(XCACHE_INCLUDES_I) "
;;
esac
echo -n "\$(builddir)/${sourceFile%.c}.lo:"
for dependency in $(gcc -M $sourceFile -I$HOME/test/php5-debug-zts/include/php/{,main,Zend,TSRM} -I. -I${builddir} -MG | sed 's#.*:##g' | sed 's#\\##g'); do
dependency=$(readlink -f "$dependency")
case "$dependency" in
$pwd/*)
dependency=${dependency#$pwd/}
;;
$builddir/*)
dependency="\$(builddir)/"${dependency#$builddir/}
;;
esac
case "$dependency" in
/*) ;;
$sourceFile) ;;
\$\(builddir\)/xc_processor.h)
echo -n " \$(XCACHE_PROC_H)"
;;
\$\(builddir\)/xc_processor.c.h)
echo -n " \$(XCACHE_PROC_C)"
;;
*)
if [[ -r $dependency ]]; then
echo -n " \$(srcdir)/$dependency"
else
hiecho "$dependency not found" >&2
fi
esac
done
echo
done > Makefile.frag.deps
}
# }}}1
hiecho "Loading config devel/run.cfg"
. devel/run.cfg
PHPSDIR=${PHPSDIR:-$HOME/test}
if [[ $# -eq 0 ]]; then
set -- $action "${args[@]}"
fi
# devel actions
case "$1" in
prep*) shift; prep "$@"; exit;;
tags) shift; rm -f tags; prep tags "$@"; exit;;
po2php) po2php; exit;;
mergepo) mergepo; exit;;
dep*) updatedeps; exit;;
xtest) xtest; exit;;
stopfpm) stopfpm devel.pid; exit;;
esac
basename=$(basename $(pwd))
case "$basename" in
*-*)
# in build dir, starts from src dir
dirs="$basename"
xcachesrcdir=../${basename%%-*}
cd $xcachesrcdir
;;
*)
# in src dir
dirs=${dirs:-php5-debug-zts}
xcachesrcdir=../$basename
;;
esac
touch devel.pid
svn propget svn:ignore . > .svnignore
# ==========================
do_phpize() { # {{{1
if [[ ! -x $PHPSDIR/$phpbasename/bin/phpize ]]; then
hiecho $PHPSDIR/$phpbasename/bin/phpize not found
exit
fi
export PATH=$PHPSDIR/$phpbasename/bin:$PATH
local pedantic=
case $phpbasename in
php5|php5.4) pedantic=-pedantic-errors;;
*) pedantic=-pedantic;;
esac
phpize --clean \
&& phpize \
&& CFLAGS="-g -O0 $pedanti -Wno-variadic-macros -Wno-long-long -Wall -Wno-unused-parameter -Wno-unused-function -W -Wshadow -Werror=implicit-function-declaration -std=c89 -D_GNU_SOURCE -D_POSIX_SOURCE -Dinline=" ./configure \
--enable-xcache-cacher \
--enable-xcache-optimizer \
--enable-xcache-encoder \
--enable-xcache-decoder \
--enable-xcache-disassembler \
--enable-xcache-coverager \
--enable-xcache-test \
--enable-xcache-constant
}
do_make() { # {{{1
if [[ ! -f Makefile ]]; then
do_phpize
fi
LANG=C $MAKE $MAKEOPTS "$@" 2>&1 \
| sed -ur \
-e 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \
-e 's#-pedantic-errors#-pedantic-e/rrors#' \
-e 's#\./xc_processor\.h#'$PWD'/xc_processor.h#' \
-e 's#\./xc_processor\.c\.h#'$PWD'/xc_processor.c.h#' \
| hi error implicit warn FAIL
ret=${PIPESTATUS[0]}
if [[ $ret -ne 0 ]]; then
exit $ret
fi
}
cleanfpm() { # {{{1
echo
stopfpm $pidfile
}
# }}}
run() {
pidfile=$xcachesrcdir/devel.pid
# prepare {{{1
case "$1" in
phpize)
if [[ -r Makefile ]]; then
$MAKE xcachesvnclean || true
fi
;;
esac
rm -f php-src
find -L . -type l | xargs rm -fv
lndir "$xcachesrcdir" >/dev/null || true
find . -iname .\*.swp | xargs rm -f
ln -snf ~/src/php/$phpbasename php-src
for i in ~/src/php/$phpbasename/sapi/cgi/php{,-cgi}; do
if [[ -r $i ]]; then
ln -snf "$i" php-cgi
fi
done
ln -snf ~/src/php/$phpbasename/sapi/cli/php php-cli
ln -snf ~/src/php/$phpbasename/sapi/fpm/php-fpm php-fpm
case "$1" in
phpize) do_phpize; exit;;
make) shift; do_make "$@"; exit;;
*) do_make;;
esac
# }}}1
if [[ -z $1 ]]; then
set -- devel.php
fi
cmd=()
tracer=()
# run utils {{{1
case "$1" in
dc)
shift
./php-cli -c devel.ini ./bin/phpdc.phpr $@ | tee decompiled.php
return
;;
dop)
shift
./php-cli -c devel.ini ./bin/phpdop.phpr $@
return
;;
retest)
shift
$MAKE xcachetest "$@" TESTS="`grep '^/.*\.phpt$' php_test_results_*.txt | uniq | xargs`"
return
;;
test)
shift
case "$1" in
*.phpt)
$MAKE xcachetest TEST_ARGS=-v TESTS="$*"
return
;;
*/)
$MAKE xcachetest TESTS="$*"
return
;;
*)
$MAKE xcachetest
return
;;
esac
;;
esac
# }}}
# pick tracer {{{1
case "$1" in
ltr*)
shift
export USE_ZEND_ALLOC=0
tracer=(ltrace -s1024 -e malloc,realloc,free,write)
;;
str*)
shift
tracer=(strace -s1024 -T)
;;
gdb)
shift
#USE_ZEND_ALLOC=0
tracer=(gdb --args)
;;
val*)
shift
export USE_ZEND_ALLOC=0
tracer=(valgrind --gen-suppressions=all)
;;
esac
# pick sapi {{{1
case "$basename" in
*-apache1*)
cmd=($HOME/apache1/bin/httpd -X)
;;
*-apache*)
echo "Don't know how to run apache"
exit 1
;;
*)
case "$1" in
fcgi)
shift
cmd=(./php-cgi -q -c devel.ini)
set -- -b 1026
;;
fpm)
shift
cmd=(./php-fpm -c devel.ini -y devel.fpm -g $(readlink -f $pidfile))
set --
;;
*)
cmd=(./php-cgi -q -c devel.ini)
;;
esac
"${cmd[@]}" -v || true
esac
# run {{{1
commandLine=("${tracer[@]}" "${cmd[@]}" "$@")
case "${cmd[0]}" in
*php-fpm*)
stopfpm
hiecho Starting fpm "${commandLine[@]}" ...
"${commandLine[@]}"
echo -n "Ctrl-C to stop"
trap cleanfpm SIGINT SIGTERM exit
cat > /dev/null || true
stopfpm
;;
*)
hiecho "${commandLine[@]}"
"${commandLine[@]}"
;;
esac
# }}}
}
for phpbasename in "${dirs[@]}"; do
mkdir -p ../${basename}-${phpbasename}
cd ../${basename}-${phpbasename} || exit
lndir ${xcachesrcdir} >/dev/null || true
pwd
run "$@"
done