Skip to content

Commit 26ac8bd

Browse files
committed
Refactor SASL support checking, move "unnecessary" things to private header, move travis script to .travis dir
1 parent 5c02928 commit 26ac8bd

13 files changed

+565
-386
lines changed

.travis.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
language: php
22
php:
33
- 5.5
4-
- 5.4
5-
- 5.3
4+
#- 5.4
5+
#- 5.3
66
env:
77
- LIBMEMCACHED_VERSION=1.0.17
88
- LIBMEMCACHED_VERSION=1.0.16
99
- LIBMEMCACHED_VERSION=1.0.15
1010
- LIBMEMCACHED_VERSION=1.0.14
1111
- LIBMEMCACHED_VERSION=1.0.10
1212
- LIBMEMCACHED_VERSION=1.0.8
13+
- LIBMEMCACHED_VERSION=1.0.7
14+
- LIBMEMCACHED_VERSION=1.0.6
1315
- LIBMEMCACHED_VERSION=1.0.2
1416
- LIBMEMCACHED_VERSION=0.53
1517
- LIBMEMCACHED_VERSION=0.44
1618

19+
services:
20+
- memcached # will start memcached
21+
1722
before_script:
18-
- ./travis.sh before_script $LIBMEMCACHED_VERSION
23+
- ./.travis/travis.sh before_script $LIBMEMCACHED_VERSION
1924

2025
script:
21-
- ./travis.sh script $LIBMEMCACHED_VERSION
26+
- ./.travis/travis.sh script $LIBMEMCACHED_VERSION

.travis/travis.sh

+250
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
#!/bin/bash
2+
3+
function version_compare() {
4+
DPKG=`which dpkg`
5+
6+
if [ "x$DPKG" = "x" ]; then
7+
echo "dpkg not found, cannot compare versions"
8+
exit 1
9+
fi
10+
11+
$DPKG --compare-versions "$1" "$2" "$3"
12+
return $?
13+
}
14+
15+
function check_protocol_support() {
16+
version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15
17+
if [ $? = 0 ]; then
18+
ENABLE_PROTOOCOL=yes
19+
else
20+
ENABLE_PROTOOCOL=no
21+
fi
22+
}
23+
24+
function check_sasl_support() {
25+
version_compare "$LIBMEMCACHED_VERSION" gt 1.0.15
26+
if [ $? = 0 ]; then
27+
ENABLE_SASL=yes
28+
else
29+
ENABLE_SASL=no
30+
fi
31+
}
32+
33+
function validate_package_xml() {
34+
retval=0
35+
for file in tests/*.phpt; do
36+
grep $(basename $file) package.xml >/dev/null
37+
if [ $? != 0 ]; then
38+
echo "Missing $file from package.xml"
39+
retval=1;
40+
fi
41+
done
42+
return $retval
43+
}
44+
45+
function install_libmemcached() {
46+
47+
wget "https://launchpad.net/libmemcached/1.0/${LIBMEMCACHED_VERSION}/+download/libmemcached-${LIBMEMCACHED_VERSION}.tar.gz" -O libmemcached-${LIBMEMCACHED_VERSION}.tar.gz
48+
49+
tar xvfz libmemcached-${LIBMEMCACHED_VERSION}.tar.gz
50+
pushd "libmemcached-${LIBMEMCACHED_VERSION}"
51+
52+
local protocol_flag=""
53+
if test "x$ENABLE_PROTOOCOL" = "xyes"; then
54+
protocol_flag="--enable-libmemcachedprotocol"
55+
fi
56+
57+
./configure --prefix="$LIBMEMCACHED_PREFIX" $protocol_flag LDFLAGS="-lpthread"
58+
make
59+
make install
60+
popd
61+
}
62+
63+
function install_igbinary() {
64+
git clone https://github.com/igbinary/igbinary.git
65+
pushd igbinary
66+
phpize
67+
./configure
68+
make
69+
make install
70+
popd
71+
}
72+
73+
function install_msgpack() {
74+
git clone https://github.com/msgpack/msgpack-php.git
75+
pushd msgpack-php
76+
phpize
77+
./configure
78+
make
79+
make install
80+
popd
81+
}
82+
83+
function install_sasl() {
84+
85+
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz -O memcached-1.4.15.tar.gz
86+
tar xfz memcached-1.4.15.tar.gz
87+
88+
pushd memcached-1.4.15
89+
./configure --enable-sasl --prefix="${HOME}/memcached"
90+
make
91+
make install
92+
popd
93+
94+
sudo apt-get install sasl2-bin
95+
export SASL_CONF_PATH="${HOME}/sasl2"
96+
97+
# Create config path
98+
mkdir "${SASL_CONF_PATH}"
99+
100+
# Create configuration
101+
cat<<EOF > "${SASL_CONF_PATH}/memcached.conf"
102+
mech_list: PLAIN
103+
plainlog_level: 5
104+
sasldb_path: ${SASL_CONF_PATH}/sasldb2
105+
EOF
106+
107+
# Create password
108+
echo "test" | /usr/sbin/saslpasswd2 -c memcached -a memcached -f "${SASL_CONF_PATH}/sasldb2"
109+
110+
# Run memcached on port 11212 with SASL support
111+
"${HOME}/memcached/bin/memcached" -S -d -p 11212
112+
}
113+
114+
function build_php_memcached() {
115+
pear package
116+
mkdir "$PHP_MEMCACHED_BUILD_DIR"
117+
tar xfz "memcached-${PHP_MEMCACHED_VERSION}.tgz" -C "$PHP_MEMCACHED_BUILD_DIR"
118+
pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}"
119+
phpize
120+
121+
local protocol_flag=""
122+
if test "x$ENABLE_PROTOCOL" = "xyes"; then
123+
protocol_flag="--enable-memcached-protocol"
124+
fi
125+
126+
local sasl_flag="--disable-memcached-sasl"
127+
if test "x$ENABLE_SASL" = "xyes"; then
128+
protocol_flag="--enable-memcached-sasl"
129+
fi
130+
131+
./configure --with-libmemcached-dir="$LIBMEMCACHED_PREFIX" $protocol_flag $sasl_flag --enable-memcached-json --enable-memcached-igbinary --enable-memcached-msgpack
132+
make
133+
make install
134+
popd
135+
}
136+
137+
function create_memcached_test_configuration() {
138+
cat<<EOF > "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}/tests/config.inc.local"
139+
<?php
140+
define ("MEMC_SERVER_HOST", "127.0.0.1");
141+
define ("MEMC_SERVER_PORT", 11211);
142+
143+
define ("MEMC_SASL_SERVER_HOST", "127.0.0.1");
144+
define ("MEMC_SASL_SERVER_PORT", 11212);
145+
146+
define ('MEMC_SASL_USER', 'memcached');
147+
define ('MEMC_SASL_PASS', 'test');
148+
EOF
149+
}
150+
151+
function run_memcached_tests() {
152+
export NO_INTERACTION=1
153+
export REPORT_EXIT_STATUS=1
154+
export TEST_PHP_EXECUTABLE=`which php`
155+
156+
pushd "${PHP_MEMCACHED_BUILD_DIR}/memcached-${PHP_MEMCACHED_VERSION}"
157+
# We have one xfail test, we run it separately
158+
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/expire.phpt
159+
rm ./tests/expire.phpt
160+
161+
# Run normal tests
162+
php run-tests.php -d extension=msgpack.so -d extension=igbinary.so -d extension=memcached.so -n ./tests/*.phpt
163+
retval=$?
164+
for i in `ls tests/*.out 2>/dev/null`; do
165+
echo "-- START ${i}";
166+
cat $i;
167+
echo "";
168+
echo "-- END";
169+
done
170+
popd
171+
172+
return $retval;
173+
}
174+
175+
# Command line arguments
176+
ACTION=$1
177+
LIBMEMCACHED_VERSION=$2
178+
179+
if test "x$ACTION" = "x"; then
180+
echo "Usage: $0 <action> <libmemcached version>"
181+
exit 1
182+
fi
183+
184+
if test "x$LIBMEMCACHED_VERSION" = "x"; then
185+
echo "Usage: $0 <action> <libmemcached version>"
186+
exit 1
187+
fi
188+
189+
# the extension version
190+
PHP_MEMCACHED_VERSION=$(php -r '$sxe = simplexml_load_file ("package.xml"); echo (string) $sxe->version->release;')
191+
192+
# Libmemcached install dir
193+
LIBMEMCACHED_PREFIX="${HOME}/libmemcached-${LIBMEMCACHED_VERSION}"
194+
195+
# Where to do the build
196+
PHP_MEMCACHED_BUILD_DIR="/tmp/php-memcached-build"
197+
198+
# Check whether to enable building with protoocol and sasl support
199+
check_protocol_support
200+
check_sasl_support
201+
202+
echo "Enable protocol: $ENABLE_PROTOOCOL"
203+
echo "Enable sasl: $ENABLE_SASL"
204+
205+
set -e
206+
207+
case $ACTION in
208+
before_script)
209+
# validate the package.xml
210+
validate_package_xml || exit 1
211+
212+
# Install libmemcached version
213+
install_libmemcached
214+
215+
# Install igbinary extension
216+
install_igbinary
217+
218+
# install msgpack
219+
install_msgpack
220+
221+
# install SASL
222+
if test "x$ENABLE_SASL" = "xyes"; then
223+
install_sasl
224+
fi
225+
;;
226+
227+
script)
228+
# Build the extension
229+
build_php_memcached
230+
231+
# Create configuration
232+
if test "x$ENABLE_SASL" = "xyes"; then
233+
create_memcached_test_configuration
234+
fi
235+
236+
# Run tests
237+
set +e
238+
run_memcached_tests || exit 1
239+
;;
240+
241+
*)
242+
echo "Unknown action. Valid actions are: before_script and script"
243+
exit 1
244+
;;
245+
esac
246+
247+
248+
249+
250+

config.m4

+35-7
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,6 @@ if test "$PHP_MEMCACHED" != "no"; then
268268
AC_MSG_RESULT([disabled])
269269
fi
270270

271-
272-
if test "$PHP_MEMCACHED_SASL" != "no"; then
273-
AC_CHECK_HEADERS([sasl/sasl.h], [memcached_enable_sasl="yes"], [memcached_enable_sasl="no"])
274-
AC_MSG_CHECKING([whether to enable sasl support])
275-
AC_MSG_RESULT([$memcached_enable_sasl])
276-
fi
277-
278271
AC_MSG_CHECKING([for libmemcached location])
279272
export ORIG_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
280273

@@ -362,6 +355,41 @@ if test "$PHP_MEMCACHED" != "no"; then
362355
)
363356
])
364357

358+
AC_MSG_CHECKING([whether to enable sasl support])
359+
if test "$PHP_MEMCACHED_SASL" != "no"; then
360+
AC_MSG_RESULT(yes)
361+
362+
AC_CHECK_HEADERS([sasl/sasl.h], [ac_cv_have_memc_sasl_h="yes"], [ac_cv_have_memc_sasl_h="no"])
363+
364+
if test "$ac_cv_have_memc_sasl_h" = "yes"; then
365+
366+
AC_CACHE_CHECK([whether libmemcached supports sasl], ac_cv_memc_sasl_support, [
367+
AC_TRY_COMPILE(
368+
[ #include <libmemcached/memcached.h> ],
369+
[
370+
#if LIBMEMCACHED_WITH_SASL_SUPPORT
371+
/* yes */
372+
#else
373+
# error "no sasl support"
374+
#endif
375+
],
376+
[ ac_cv_memc_sasl_support="yes" ],
377+
[ ac_cv_memc_sasl_support="no" ]
378+
)
379+
])
380+
381+
if test "$ac_cv_memc_sasl_support" = "yes"; then
382+
AC_DEFINE(HAVE_MEMCACHED_SASL, 1, [Have SASL support])
383+
else
384+
AC_MSG_ERROR([no, libmemcached sasl support is not enabled. Run configure with --disable-memcached-sasl to disable this check])
385+
fi
386+
else
387+
AC_MSG_ERROR([no, sasl.h is not available. Run configure with --disable-memcached-sasl to disable this check])
388+
fi
389+
else
390+
AC_MSG_RESULT([no])
391+
fi
392+
365393
CFLAGS="$ORIG_CFLAGS"
366394
LIBS="$ORIG_LIBS"
367395

package.xml

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6363
<file role='src' name='config.w32'/>
6464
<file role='src' name='php_memcached.c'/>
6565
<file role='src' name='php_memcached.h'/>
66+
<file role='src' name='php_memcached_private.h'/>
6667
<file role='src' name='php_memcached_session.c'/>
6768
<file role='src' name='php_memcached_session.h'/>
6869
<file role='src' name='php_libmemcached_compat.h'/>
@@ -147,6 +148,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
147148
<file role='test' name='keys.phpt'/>
148149
<file role='test' name='testdata.res'/>
149150
<file role='test' name='config.inc'/>
151+
<file role='test' name='sasl_basic.phpt'/>
150152
</dir>
151153
</dir>
152154
</contents>

php_libmemcached_compat.h

+6
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ memcached_st *php_memc_create_str (const char *str, size_t str_len);
3030
# define MEMCACHED_SERVER_TEMPORARILY_DISABLED (1024 << 2)
3131
#endif
3232

33+
#ifdef HAVE_MEMCACHED_INSTANCE_ST
34+
typedef const memcached_instance_st * php_memcached_instance_st;
35+
#else
36+
typedef memcached_server_instance_st php_memcached_instance_st;
37+
#endif
38+
3339
#endif

0 commit comments

Comments
 (0)