2012-07-17 08:35:45 +00:00
#!/bin/bash
# this script is for developers only
2012-08-04 03:06:15 +00:00
2012-08-04 03:44:07 +00:00
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 [31m\0 [0m#g"
re[$i]="-e$r"
((i=i+1))
done
sed -ur "${re[@]}"
}
hiecho() { # {{{1
echo " [32m""$@"" [0m"
}
# }}}
2012-08-04 03:06:15 +00:00
stopfpm() { # {{{1
2012-08-04 03:44:07 +00:00
if [[ -f $1 ]]; then
local pid=`cat $1 2>/dev/null || true`
2012-08-04 02:19:15 +00:00
if [[ $pid -gt 0 ]]; then
2012-08-04 03:44:07 +00:00
hiecho Stopping fpm $pid @ $1
2012-08-04 02:19:15 +00:00
kill $pid || true
fi
fi
}
2012-08-04 03:06:15 +00:00
xtest() { # {{{1
$MAKE -f devel/test.mak
}
2012-07-17 08:35:45 +00:00
2012-08-04 03:06:15 +00:00
prep() { # {{{1
$MAKE -f devel/prepare.mak "$@"
}
2012-08-01 04:26:43 +00:00
2012-08-04 03:06:15 +00:00
mergepo() { # {{{1
prep
local i
2012-08-01 08:00:21 +00:00
find htdocs -iname '*.po' | while read -r i; do
if [[ -f $i-merged ]]; then
mv $i-merged $i
fi
done
2012-08-04 03:06:15 +00:00
}
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
2012-07-20 03:26:55 +00:00
pwd=$(readlink -f "$(pwd)")
2012-07-31 16:25:21 +00:00
builddir=$(readlink -f ../trunk-php5-debug-zts)
2012-07-20 03:26:55 +00:00
if [[ -z $builddir ]]; then
2012-08-04 03:44:07 +00:00
hiecho required ../trunk-php5-debug-zts not found
2012-07-20 03:26:55 +00:00
return 1
fi
2012-07-20 16:21:44 +00:00
find . -iname \*.c | sort | while read -r sourceFile; do
2012-07-20 03:26:55 +00:00
sourceFile=${sourceFile#./}
2012-07-20 06:16:51 +00:00
case "$sourceFile" in
includes.c)
echo -n "\$(XCACHE_INCLUDES_I) "
;;
esac
2012-07-20 03:26:55 +00:00
echo -n "\$(builddir)/${sourceFile%.c}.lo:"
2012-07-31 16:25:21 +00:00
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
2012-07-20 03:26:55 +00:00
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
2012-08-04 03:44:07 +00:00
hiecho "$dependency not found" >&2
2012-07-20 03:26:55 +00:00
fi
esac
done
echo
done > Makefile.frag.deps
2012-08-04 03:06:15 +00:00
}
# }}}1
2012-08-04 03:44:07 +00:00
hiecho "Loading config devel/run.cfg"
2012-08-04 03:06:15 +00:00
. devel/run.cfg
PHPSDIR=${PHPSDIR:-$HOME/test}
if [[ $# -eq 0 ]]; then
2012-08-09 12:57:07 +00:00
set -- $action "${args[@]}"
2012-08-04 03:06:15 +00:00
fi
# devel actions
2012-08-09 02:51:46 +00:00
case "$1" in
prep*) shift; prep "$@"; exit;;
tags) shift; rm -f tags; prep tags "$@"; exit;;
2012-08-04 03:06:15 +00:00
po2php) po2php; exit;;
mergepo) mergepo; exit;;
dep*) updatedeps; exit;;
xtest) xtest; exit;;
2012-08-09 02:51:46 +00:00
stopfpm) stopfpm devel.pid; exit;;
2012-07-18 06:38:45 +00:00
esac
2012-08-09 02:51:46 +00:00
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
;;
2012-08-04 02:19:15 +00:00
esac
2012-08-09 02:51:46 +00:00
touch devel.pid
svn propget svn:ignore . > .svnignore
# ==========================
2012-08-04 03:44:07 +00:00
do_phpize() { # {{{1
2012-08-04 03:06:15 +00:00
if [[ ! -x $PHPSDIR/$phpbasename/bin/phpize ]]; then
2012-08-04 03:44:07 +00:00
hiecho $PHPSDIR/$phpbasename/bin/phpize not found
2012-08-04 03:06:15 +00:00
exit
fi
export PATH=$PHPSDIR/$phpbasename/bin:$PATH
2012-08-04 03:57:00 +00:00
local pedantic=
case $phpbasename in
php5|php5.4) pedantic=-pedantic-errors;;
*) pedantic=-pedantic;;
esac
2012-08-04 03:06:15 +00:00
phpize --clean \
&& phpize \
2012-08-04 03:57:00 +00:00
&& 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 \
2012-08-04 03:06:15 +00:00
--enable-xcache-cacher \
--enable-xcache-optimizer \
--enable-xcache-encoder \
--enable-xcache-decoder \
--enable-xcache-disassembler \
--enable-xcache-coverager \
--enable-xcache-test \
--enable-xcache-constant
}
2012-08-04 03:44:07 +00:00
do_make() { # {{{1
if [[ ! -f Makefile ]]; then
do_phpize
fi
2012-08-04 03:06:15 +00:00
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
}
2012-08-09 02:51:46 +00:00
cleanfpm() { # {{{1
echo
stopfpm $pidfile
}
2012-08-04 03:06:15 +00:00
# }}}
2012-08-04 03:44:07 +00:00
run() {
pidfile=$xcachesrcdir/devel.pid
2012-07-19 02:27:53 +00:00
2012-08-04 03:44:07 +00:00
# prepare {{{1
2012-08-09 02:51:46 +00:00
case "$1" in
2012-08-04 03:44:07 +00:00
phpize)
if [[ -r Makefile ]]; then
$MAKE xcachesvnclean || true
fi
;;
esac
2012-07-19 03:57:56 +00:00
2012-08-04 03:44:07 +00:00
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
2012-07-19 03:57:56 +00:00
2012-08-09 02:51:46 +00:00
case "$1" in
2012-08-04 03:44:07 +00:00
phpize) do_phpize; exit;;
2012-08-09 03:37:26 +00:00
make) shift; do_make "$@"; exit;;
2012-08-04 03:44:07 +00:00
*) do_make;;
esac
# }}}1
2012-07-17 08:35:45 +00:00
2012-08-04 03:44:07 +00:00
if [[ -z $1 ]]; then
set -- devel.php
fi
2012-08-01 04:29:42 +00:00
2012-08-04 03:44:07 +00:00
cmd=()
tracer=()
2012-08-04 03:06:15 +00:00
2012-08-04 03:44:07 +00:00
# run utils {{{1
2012-08-09 02:51:46 +00:00
case "$1" in
2012-08-04 03:44:07 +00:00
dc)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
./php-cli -c devel.ini ./bin/phpdc.phpr $@ | tee decompiled.php
return
2012-08-04 03:06:15 +00:00
;;
2012-08-04 03:44:07 +00:00
dop)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
./php-cli -c devel.ini ./bin/phpdop.phpr $@
return
2012-08-04 03:06:15 +00:00
;;
2012-08-04 03:44:07 +00:00
retest)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
$MAKE xcachetest "$@" TESTS="`grep '^/.*\.phpt$' php_test_results_*.txt | uniq | xargs`"
return
;;
test)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
case "$1" in
*.phpt)
$MAKE xcachetest TEST_ARGS=-v TESTS="$*"
return
;;
*/)
$MAKE xcachetest TESTS="$*"
return
;;
*)
$MAKE xcachetest
return
;;
esac
2012-08-04 03:06:15 +00:00
;;
esac
2012-08-04 03:44:07 +00:00
# }}}
2012-08-09 02:51:46 +00:00
# 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
2012-08-04 03:44:07 +00:00
# pick sapi {{{1
case "$basename" in
*-apache1*)
cmd=($HOME/apache1/bin/httpd -X)
2012-07-25 13:34:12 +00:00
;;
2012-08-04 03:44:07 +00:00
*-apache*)
2012-08-09 02:51:46 +00:00
echo "Don't know how to run apache"
2012-08-04 03:44:07 +00:00
exit 1
2012-07-25 13:34:12 +00:00
;;
*)
2012-08-04 03:44:07 +00:00
case "$1" in
fcgi)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
cmd=(./php-cgi -q -c devel.ini)
set -- -b 1026
;;
fpm)
2012-08-09 02:51:46 +00:00
shift
2012-08-04 03:44:07 +00:00
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
2012-07-17 08:35:45 +00:00
2012-08-04 03:44:07 +00:00
# run {{{1
commandLine=("${tracer[@]}" "${cmd[@]}" "$@")
2012-07-17 08:35:45 +00:00
2012-08-04 03:44:07 +00:00
case "${cmd[0]}" in
*php-fpm*)
2012-08-09 02:51:46 +00:00
stopfpm
2012-08-09 12:57:07 +00:00
hiecho Starting fpm "${commandLine[@]}" ...
2012-08-04 03:44:07 +00:00
"${commandLine[@]}"
2012-08-09 02:51:46 +00:00
echo -n "Ctrl-C to stop"
trap cleanfpm SIGINT SIGTERM exit
cat > /dev/null || true
stopfpm
2012-08-04 03:44:07 +00:00
;;
*)
2012-08-09 12:57:07 +00:00
hiecho "${commandLine[@]}"
2012-08-04 03:44:07 +00:00
"${commandLine[@]}"
;;
esac
# }}}
}
2012-08-04 02:19:15 +00:00
2012-08-09 02:51:46 +00:00
for phpbasename in "${dirs[@]}"; do
mkdir -p ../${basename}-${phpbasename}
cd ../${basename}-${phpbasename} || exit
lndir ${xcachesrcdir} >/dev/null || true
2012-08-04 03:44:07 +00:00
2012-08-09 02:51:46 +00:00
pwd
run "$@"
done