~ubuntu-branches/ubuntu/vivid/xcache/vivid-proposed

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
#!/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 ${MAKEOPTS} -f devel/test.mak
}

prep() { # {{{1
	$MAKE ${MAKEOPTS} -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 | LANG=C sort | while read -r sourceFile; do
		sourceFile=${sourceFile#./}
		{
			case "$sourceFile" in
			includes.c)
				echo '$(XCACHE_INCLUDES_I)'
				;;
			esac
			echo ${sourceFile%.c}.lo '$(builddir)/'${sourceFile%.c}.lo:
			hiecho "Checking $sourceFile ..." >&2
			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
				dependency=$(readlink -f "$dependency")
				case "$dependency" in
				$pwd/*)
					dependency=${dependency#$pwd/}
					;;
				$builddir/*)
					dependency="\$(builddir)/"${dependency#$builddir/}
					;;
				esac

				case "$dependency" in
				*xc_const_string_opcodes_php*)
					for dependency in xcache/xc_const_string_*.h; do
						echo '$(srcdir)/'$dependency
					done
					;;

				/*) ;;
				$sourceFile) ;;

				xc_processor.h|\$\(builddir\)/xc_processor.h)
					echo '$(XCACHE_PROC_H)'
					;;
				xc_processor.c.h|\$\(builddir\)/xc_processor.c.h)
					echo '$(XCACHE_PROC_C)'
					;;
				*)
					if [[ -r $dependency ]]; then
						echo '$(srcdir)/'$dependency
					else
						hiecho "$dependency not found" >&2
					fi
				esac
			done | LANG=C sort | uniq
		} | xargs
	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

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="$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 \
		--enable-xcache-cacher \
		--enable-xcache-optimizer \
		--enable-xcache-encoder \
		--enable-xcache-decoder \
		--enable-xcache-disassembler \
		--enable-xcache-assembler \
		--enable-xcache-coverager \
		--enable-xcache-test \
		--enable-xcache-dprint \
		--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 $MAKEOPTS xcachesvnclean || true
		fi
		;;
	esac

	rm -f php-src
	find -L . -type d -print0 | xargs -0 rmdir -p 2>/dev/null || true
	find -L . -type l -print0 | xargs -0 rm -fv
	lndir "$xcachesrcdir" >/dev/null || true
	find . -iname .\*.swp -print0 | xargs -0 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
	f=~/src/php/$phpbasename/sapi/cli/php; [ -f "$f" ] && ln -snf "$f" php-cli
	f=~/src/php/$phpbasename/sapi/fpm/php-fpm; [ -f "$f" ] && ln -snf "$f" php-fpm

	case "$1" in
	phpize) do_phpize; return $?;;
	make) shift; do_make "$@"; return $?;;
	*) do_make;;
	esac
	# }}}1

	if [[ -z $1 ]]; then
		set -- devel.php
	fi

	cmd=()
	tracer=()

	# run utils {{{1
	case "$1" in
	dc)
		shift
		case "$1" in
		*.cpp.php)
			< "$1" \
			sed -r -e 's#__#____#g' \
			| cpp -C -P -traditional-cpp -DPHP_VERSION=$phpVersion \
			| sed -r -e 's#^ +##g' -e 's#\t +#\t#g' -e 's#____#__#g' > sample.php || exit $?
			shift
			./php-cli -c devel.ini ./bin/phpdc.phpr sample.php "$@" | tee decompiled.php
			;;
		*)
			./php-cli -c devel.ini ./bin/phpdc.phpr "$@" | tee decompiled.php
			;;
		esac
		return
		;;
	retest)
		shift
		lastResult=$(ls php_test_results_*.txt | LANG=C sort | tail -n1)
		$MAKE $MAKEOPTS xcachetest "$@" TESTS="$(grep '^/.*\.phpt$' $lastResult | uniq | xargs)"
		return
		;;
	test)
		shift
		case "$1" in
		*.phpt)
			$MAKE $MAKEOPTS xcachetest TEST_ARGS=-v TESTS="$*"
			return
			;;
		*/)
			$MAKE $MAKEOPTS xcachetest TESTS="$*"
			return
			;;
		*)
			$MAKE $MAKEOPTS 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
		export ZEND_DONT_UNLOAD_MODULES=1
		tracer=(valgrind -v --gen-suppressions=all)
		;;
	esac

	# pick sapi {{{1
	case "$phpbasename" in
	*-apache1*)
		cmd=($HOME/apache1/bin/httpd -X)
		;;
	*-apache*)
		echo "Don't know how to run apache"
		exit 1
		;;
	*)
		case "$1" in
		dop)
			shift
			cmd=(./php-cli -c devel.ini)
			set -- ./bin/phpdop.phpr "$@"
			;;
		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
	phpVersion=${phpbasename%%-*}
	phpVersion=${phpVersion##php}
	phpVersion=${phpVersion/./}
	case "$phpVersion" in
	??) phpVersion="${phpVersion}0";;
	?) phpVersion="${phpVersion}00";;
	esac

	# 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

	mkdir -p ${xcachesrcdir}-${phpbasename}
	cd ${xcachesrcdir}-${phpbasename} || exit
	lndir ${xcachesrcdir} >/dev/null || true

	pwd
	run "$@"
done