XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

402 lines
8.0 KiB

  1. #!/bin/bash
  2. # this script is for developers only
  3. set -e
  4. MAKE=/usr/bin/make
  5. true() { # {{{1
  6. return 0
  7. }
  8. hi() { # {{{1
  9. local colors=(4 2 3 5 6 7 8 9)
  10. local re=()
  11. local i=0
  12. for r in "$@"; do
  13. ((color=$i % ${#colors[@]})) || true
  14. color=${colors[$color]}
  15. r="${r/\#/\\#}"
  16. r="s#$r#[4${color}m\0#g"
  17. re[$i]="-e$r"
  18. ((i=i+1))
  19. done
  20. sed -ur "${re[@]}"
  21. }
  22. hiecho() { # {{{1
  23. echo """$@"""
  24. }
  25. # }}}
  26. stopfpm() { # {{{1
  27. if [[ -f $1 ]]; then
  28. local pid=`cat $1 2>/dev/null || true`
  29. if [[ $pid -gt 0 ]]; then
  30. hiecho Stopping fpm $pid @ $1
  31. kill $pid || true
  32. fi
  33. fi
  34. }
  35. xtest() { # {{{1
  36. $MAKE ${MAKEOPTS} -f devel/test.mak clean all
  37. }
  38. prep() { # {{{1
  39. $MAKE ${MAKEOPTS} -f devel/prepare.mak "$@"
  40. }
  41. mergepo() { # {{{1
  42. prep
  43. local i
  44. find htdocs -iname '*.po' | while read -r i; do
  45. if [[ -f $i-merged ]]; then
  46. mv $i-merged $i
  47. fi
  48. done
  49. }
  50. po2php() { # {{{1
  51. mergepo
  52. local phpfile
  53. find htdocs -iname '*.po' | while read -r i; do
  54. phpfile=${i/.po/.php}
  55. devel/po2php.awk < $i > $phpfile.tmp
  56. mv $phpfile.tmp $phpfile
  57. done
  58. }
  59. updatedeps() { # {{{1
  60. pwd=$(readlink -f "$(pwd)")
  61. builddir=$(readlink -f ../trunk-php5-debug-zts)
  62. if [[ -z $builddir ]]; then
  63. hiecho required ../trunk-php5-debug-zts not found
  64. return 1
  65. fi
  66. find . -iname \*.c | LANG=C sort | while read -r sourceFile; do
  67. sourceFile=${sourceFile#./}
  68. {
  69. case "$sourceFile" in
  70. includes.c)
  71. echo '$(XCACHE_INCLUDES_I)'
  72. ;;
  73. esac
  74. echo ${sourceFile%.c}.lo '$(builddir)/'${sourceFile%.c}.lo:
  75. hiecho "Checking $sourceFile ..." >&2
  76. for dependency in $(gcc -DHAVE_XCACHE_TEST -DHAVE_XCACHE_DPRINT -DXCACHE_DEBUG -MM $sourceFile -I$PHPSDIR/$phpbasename/include/php/{,main,Zend,TSRM} -I. -I${builddir} -MG | sed 's#.*:##g' | sed 's#\\##g'); do
  77. dependency=$(readlink -f "$dependency")
  78. case "$dependency" in
  79. $pwd/*)
  80. dependency=${dependency#$pwd/}
  81. ;;
  82. $builddir/*)
  83. dependency="\$(builddir)/"${dependency#$builddir/}
  84. ;;
  85. esac
  86. case "$dependency" in
  87. *xc_const_string_opcodes_php*)
  88. for dependency in xcache/xc_const_string_*.h; do
  89. echo '$(srcdir)/'$dependency
  90. done
  91. ;;
  92. /*) ;;
  93. $sourceFile) ;;
  94. xc_processor.h|\$\(builddir\)/xc_processor.h)
  95. echo '$(XCACHE_PROC_H)'
  96. ;;
  97. xc_processor.c.h|\$\(builddir\)/xc_processor.c.h)
  98. echo '$(XCACHE_PROC_C)'
  99. ;;
  100. *)
  101. if [[ -r $dependency ]]; then
  102. echo '$(srcdir)/'$dependency
  103. else
  104. hiecho "$dependency not found" >&2
  105. fi
  106. esac
  107. done | LANG=C sort | uniq
  108. } | xargs
  109. done > Makefile.frag.deps
  110. }
  111. # }}}1
  112. hiecho "Loading config devel/run.cfg"
  113. . devel/run.cfg
  114. PHPSDIR=${PHPSDIR:-$HOME/test}
  115. if [[ $# -eq 0 ]]; then
  116. set -- "${args[@]}"
  117. fi
  118. basename=$(basename $(pwd))
  119. case "$basename" in
  120. *-*)
  121. # in build dir, starts from src dir
  122. dirs="${basename#*-}"
  123. xcachesrcdir=../${basename%%-*}
  124. cd $xcachesrcdir
  125. ;;
  126. *)
  127. # in src dir
  128. dirs=${dirs:-php5-debug-zts}
  129. xcachesrcdir=../$basename
  130. ;;
  131. esac
  132. touch devel.pid
  133. svn propget svn:ignore . > .svnignore
  134. # ==========================
  135. do_phpize() { # {{{1
  136. if [[ ! -x $PHPSDIR/$phpbasename/bin/phpize ]]; then
  137. hiecho $PHPSDIR/$phpbasename/bin/phpize not found
  138. exit
  139. fi
  140. export PATH=$PHPSDIR/$phpbasename/bin:$PATH
  141. local pedantic=
  142. case $phpbasename in
  143. php5|php5.4) pedantic=-pedantic-errors;;
  144. *) pedantic=-pedantic;;
  145. esac
  146. phpize --clean \
  147. && phpize \
  148. && CFLAGS="$CFLAGS -g -O0 $pedantic -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 \
  149. --enable-xcache-cacher \
  150. --enable-xcache-optimizer \
  151. --enable-xcache-encoder \
  152. --enable-xcache-decoder \
  153. --enable-xcache-disassembler \
  154. --enable-xcache-assembler \
  155. --enable-xcache-coverager \
  156. --enable-xcache-test \
  157. --enable-xcache-dprint \
  158. --enable-xcache-constant
  159. }
  160. do_make() { # {{{1
  161. if [[ ! -f Makefile ]]; then
  162. do_phpize
  163. fi
  164. LANG=C $MAKE $MAKEOPTS "$@" 2>&1 \
  165. | sed -ur \
  166. -e 's#Werror=implicit-function-declaration#We/rror=i/mplicit-function-declaration#' \
  167. -e 's#-pedantic-errors#-pedantic-e/rrors#' \
  168. -e 's#\./xc_processor\.h#'$PWD'/xc_processor.h#' \
  169. -e 's#\./xc_processor\.c\.h#'$PWD'/xc_processor.c.h#' \
  170. | hi error implicit warn FAIL
  171. ret=${PIPESTATUS[0]}
  172. if [[ $ret -ne 0 ]]; then
  173. exit $ret
  174. fi
  175. }
  176. cleanfpm() { # {{{1
  177. echo
  178. stopfpm $pidfile
  179. }
  180. # }}}
  181. run() {
  182. pidfile=$xcachesrcdir/devel.pid
  183. # prepare {{{1
  184. case "$1" in
  185. phpize)
  186. if [[ -r Makefile ]]; then
  187. $MAKE $MAKEOPTS xcachesvnclean || true
  188. fi
  189. ;;
  190. esac
  191. rm -f php-src
  192. find -L . -type d -print0 | xargs -0 rmdir -p 2>/dev/null || true
  193. find -L . -type l -print0 | xargs -0 rm -fv
  194. lndir "$xcachesrcdir" >/dev/null || true
  195. find . -iname .\*.swp -print0 | xargs -0 rm -f
  196. ln -snf ~/src/php/${phpbasename%%-*} php-src
  197. for i in ~/src/php/$phpbasename/sapi/cgi/php{,-cgi}; do
  198. if [[ -r $i ]]; then
  199. ln -snf "$i" php-cgi
  200. fi
  201. done
  202. ln -snf ~/src/php/$phpbasename/sapi/cli/php php-cli
  203. f=~/src/php/$phpbasename/sapi/cli/php; [ -f "$f" ] && ln -snf "$f" php-cli
  204. f=~/src/php/$phpbasename/sapi/fpm/php-fpm; [ -f "$f" ] && ln -snf "$f" php-fpm
  205. case "$1" in
  206. phpized) CFLAGS=-DXCACHE_DEBUG do_phpize; return $?;;
  207. phpize) do_phpize; return $?;;
  208. make) shift; do_make "$@"; return $?;;
  209. *) do_make;;
  210. esac
  211. # }}}1
  212. if [[ -z $1 ]]; then
  213. set -- devel/sample.cpp.php
  214. fi
  215. cmd=()
  216. phpApp=()
  217. tracer=()
  218. # run utils {{{1
  219. case "$1" in
  220. retest)
  221. shift
  222. lastResult=$(ls php_test_results_*.txt | LANG=C sort | tail -n1)
  223. $MAKE $MAKEOPTS xcachetest "$@" TESTS="$(grep '^/.*\.phpt$' $lastResult | uniq | xargs)"
  224. return
  225. ;;
  226. test)
  227. shift
  228. case "$1" in
  229. *.phpt)
  230. $MAKE $MAKEOPTS xcachetest TEST_ARGS=-v TESTS="$*"
  231. return
  232. ;;
  233. */)
  234. $MAKE $MAKEOPTS xcachetest TESTS="$*"
  235. return
  236. ;;
  237. *)
  238. $MAKE $MAKEOPTS xcachetest
  239. return
  240. ;;
  241. esac
  242. ;;
  243. esac
  244. # }}}
  245. # pick tracer {{{1
  246. case "$1" in
  247. ltr*)
  248. shift
  249. export USE_ZEND_ALLOC=0
  250. tracer=(ltrace -s1024 -e malloc,realloc,free,write)
  251. ;;
  252. str*)
  253. shift
  254. tracer=(strace -s1024 -T)
  255. ;;
  256. gdb)
  257. shift
  258. #USE_ZEND_ALLOC=0
  259. tracer=(gdb --args)
  260. ;;
  261. val*)
  262. shift
  263. export USE_ZEND_ALLOC=0
  264. export ZEND_DONT_UNLOAD_MODULES=1
  265. tracer=(valgrind -v --gen-suppressions=all)
  266. ;;
  267. esac
  268. # pick sapi {{{1
  269. case "$phpbasename" in
  270. *-apache1*)
  271. cmd=($HOME/apache1/bin/httpd -X)
  272. ;;
  273. *-apache*)
  274. echo "Don't know how to run apache"
  275. exit 1
  276. ;;
  277. *)
  278. case "$1" in
  279. dc)
  280. shift
  281. cmd=(./php-cli -c devel.ini)
  282. phpApp=(./bin/phpdc.phpr)
  283. ;;
  284. dop)
  285. shift
  286. cmd=(./php-cli -c devel.ini)
  287. phpApp=(./bin/phpdop.phpr)
  288. ;;
  289. fcgi)
  290. shift
  291. cmd=(./php-cgi -q -c devel.ini)
  292. set -- -b 1026
  293. ;;
  294. fpm)
  295. shift
  296. cmd=(./php-fpm -c devel.ini -y devel.fpm -g $(readlink -f $pidfile))
  297. set --
  298. ;;
  299. *)
  300. cmd=(./php-cgi -q -c devel.ini)
  301. ;;
  302. esac
  303. "${cmd[@]}" -v || true
  304. esac
  305. # hack sample.cpp.php {{{1
  306. case "$1" in
  307. *.cpp.php)
  308. < "$1" \
  309. sed -r -e 's#__#____#g' \
  310. | cpp -C -P -traditional-cpp -DPHP_VERSION=$phpVersion \
  311. | sed -r -e 's#^ +##g' -e 's#\t +#\t#g' -e 's#____#__#g' > devel.php || exit $?
  312. shift
  313. set -- devel.php "$@"
  314. ;;
  315. esac
  316. # run {{{1
  317. set -- "${tracer[@]}" "${cmd[@]}" "${phpApp[@]}" "$@"
  318. case "${cmd[0]}" in
  319. *php-fpm*)
  320. stopfpm
  321. hiecho Starting fpm "$@" ...
  322. "$@" | tee output.php
  323. echo -n "Ctrl-C to stop"
  324. trap cleanfpm SIGINT SIGTERM exit
  325. cat > /dev/null || true
  326. stopfpm
  327. return
  328. ;;
  329. *)
  330. hiecho "$@"
  331. case "${tracer[@]}" in
  332. gdb*|val*)
  333. "$@"
  334. ;;
  335. *)
  336. "$@" | tee output.php
  337. return ${PIPESTATUS[0]}
  338. ;;
  339. esac
  340. ;;
  341. esac
  342. # }}}
  343. }
  344. for phpbasename in "${dirs[@]}"; do
  345. phpVersion=${phpbasename%%-*}
  346. phpVersion=${phpVersion##php}
  347. phpVersion=${phpVersion/./}
  348. case "$phpVersion" in
  349. ??) phpVersion="${phpVersion}0";;
  350. ?) phpVersion="${phpVersion}00";;
  351. esac
  352. # devel actions
  353. case "$1" in
  354. prep*) shift; prep "$@"; exit;;
  355. tags) shift; rm -f tags; prep tags "$@"; exit;;
  356. po2php) po2php; exit;;
  357. mergepo) mergepo; exit;;
  358. dep*) updatedeps; exit;;
  359. xtest) xtest; exit;;
  360. stopfpm) stopfpm devel.pid; exit;;
  361. esac
  362. mkdir -p ${xcachesrcdir}-${phpbasename}
  363. cd ${xcachesrcdir}-${phpbasename} || exit
  364. lndir ${xcachesrcdir} >/dev/null || true
  365. pwd
  366. run "$@"
  367. done