|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +source /usr/share/annyung-release/functions.d/bash/functions |
| 4 | +setAnsi |
| 5 | +tcolor="${bblack}${bgwhite}" |
| 6 | + |
| 7 | +errmsg () { |
| 8 | + echo "$*" 1>&2 |
| 9 | +} |
| 10 | + |
| 11 | +usage () { |
| 12 | + echo "${bwhite}Usage:${normal} $0 [clean|pack|test [php-version]]" |
| 13 | + exit 1 |
| 14 | +} |
| 15 | + |
| 16 | +mod_name="$( grep "^ZEND_GET_MODULE" *.c | grep -Po '(?<=\()[a-z]+(?=\))' )" |
| 17 | + |
| 18 | +opts=$(getopt -u -o h -l help -- "$@") |
| 19 | +[ $? != 0 ] && usage |
| 20 | + |
| 21 | +set -- ${opts} |
| 22 | +for i |
| 23 | +do |
| 24 | + case "$i" in |
| 25 | + -h|--help) |
| 26 | + usage |
| 27 | + shift |
| 28 | + ;; |
| 29 | + --) |
| 30 | + shift |
| 31 | + break |
| 32 | + ;; |
| 33 | + esac |
| 34 | +done |
| 35 | + |
| 36 | +mode="${1}" |
| 37 | + |
| 38 | +case "${mode}" in |
| 39 | + clean) |
| 40 | + cat <<-EOL |
| 41 | + ${bwhite}[ -f Makefile ] && make distclean |
| 42 | + rm -rf autom4te.cache build include modules |
| 43 | + rm -f .deps Makefile* ac*.m4 dyn*.m4 compile *.loT |
| 44 | + rm -f config.h* config.nice configure* config.sub config.guess |
| 45 | + rm -f install-sh ltmain.sh missing mkinstalldirs run-tests.php |
| 46 | +
|
| 47 | + rm -f package.xml |
| 48 | + rm -f tests/*.{diff,exp,log,out,php,sh,mem} |
| 49 | + #rm -f ${mod_name}_arginfo.h && git checkout -- ${mod_name}_arginfo.h |
| 50 | + ${normal}-----> |
| 51 | + EOL |
| 52 | + |
| 53 | + [ -f Makefile ] && make distclean |
| 54 | + rm -rf autom4te.cache build include modules |
| 55 | + rm -f .deps Makefile* ac*.m4 dyn*.m4 compile *.loT |
| 56 | + rm -f config.h* config.nice configure* config.sub config.guess |
| 57 | + rm -f install-sh ltmain.sh missing mkinstalldirs run-tests.php |
| 58 | + |
| 59 | + rm -f package.xml |
| 60 | + rm -f tests/*.{diff,exp,log,out,php,sh,mem} |
| 61 | + #rm -f ${mod_name}_arginfo.h && git checkout -- ${mod_name}_arginfo.h |
| 62 | + ;; |
| 63 | + pack) |
| 64 | + cp -af package.xml.tmpl package.xml |
| 65 | + list=$(grep "md5sum" ./package.xml | sed -r 's/.*"@|@".*//g') |
| 66 | + |
| 67 | + for i in ${list} |
| 68 | + do |
| 69 | + md5s=$(md5sum "$i" | awk '{print $1}') |
| 70 | + perl -pi -e "s!\@${i}\@!${md5s}!g" ./package.xml |
| 71 | + done |
| 72 | + |
| 73 | + curdate=$(date +'%Y-%m-%d') |
| 74 | + curtime=$(date +'%H:%M:%S') |
| 75 | + |
| 76 | + perl -pi -e "s!\@curdate\@!${curdate}!g" ./package.xml |
| 77 | + perl -pi -e "s!\@curtime\@!${curtime}!g" ./package.xml |
| 78 | + |
| 79 | + pecl package |
| 80 | + rm -f package.xml |
| 81 | + ;; |
| 82 | + test) |
| 83 | + # support PHP 4.3 and after |
| 84 | + |
| 85 | + PHPBIN=/opt/php-qa/php${2}/bin/php |
| 86 | + PHPIZE=/opt/php-qa/php${2}/bin/phpize |
| 87 | + PHPCONFIG=/opt/php-qa/php${2}/bin/php-config |
| 88 | + PHP_OPT="-n" |
| 89 | + LEGACY_TEST=0 |
| 90 | + |
| 91 | + if [[ $# == 2 ]]; then |
| 92 | + ./manage.sh clean |
| 93 | + echo "${PHPIZE} && ./configure" |
| 94 | + ${PHPIZE} && ./configure && make -j8 || exit 0 |
| 95 | + fi |
| 96 | + |
| 97 | + if [[ ! -f ./run-tests.php ]]; then |
| 98 | + LEGACY_TEST=1 |
| 99 | + PHP_OPT="-d 'enable_dl=1' -d 'safe_mode=0' -d 'disable_error=0'" |
| 100 | + fi |
| 101 | + PHP_OPT+=" -d 'extension_dir=./modules/' -d 'extension=${mod_name}.so'" |
| 102 | + |
| 103 | + if [[ -f tests/${3}.php ]]; then |
| 104 | + cat <<-EOL |
| 105 | + ${bgreen}------------------------------------------------------------------------ |
| 106 | + Sample code execution: |
| 107 | +
|
| 108 | + ${bcyan}${PHPBIN} ${PHP_OPT} test/${3}.php |
| 109 | + ${bgreen}------------------------------------------------------------------------${normal} |
| 110 | +
|
| 111 | + EOL |
| 112 | + |
| 113 | + ${PHPBIN} ${PHP_OPT} test/${3}.php |
| 114 | + exit $? |
| 115 | + elif [[ -f ${3} ]]; then |
| 116 | + cat <<-EOL |
| 117 | + ${bgreen}------------------------------------------------------------------------ |
| 118 | + Sample code execution: |
| 119 | +
|
| 120 | + ${bcyan}${PHPBIN} ${PHP_OPT} ${3} |
| 121 | + ${bgreen}------------------------------------------------------------------------${normal} |
| 122 | +
|
| 123 | + EOL |
| 124 | + |
| 125 | + eval "${PHPBIN} ${PHP_OPT} ${3}" |
| 126 | + exit $? |
| 127 | + fi |
| 128 | + |
| 129 | + grep "^PHP_DEPRECATED_DIRECTIVES_REGEX =" Makefile | grep -q "safe_mode" |
| 130 | + [[ $? == 0 ]] && { |
| 131 | + perl -pi -e 's/safe_mode\|//g' Makefile |
| 132 | + } |
| 133 | + |
| 134 | + cat <<-EOL |
| 135 | + ${bwhite}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 136 | + ${tcolor}** MAKE test:: ${normal} |
| 137 | + ${bwhite}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 138 | +
|
| 139 | + ${bcyan}make test PHP_EXECUTABLE=${PHPBIN} |
| 140 | + ${bwhite}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~${normal} |
| 141 | +
|
| 142 | + EOL |
| 143 | + |
| 144 | + (( LEGACY_TEST == 1 )) \ |
| 145 | + && PHP_EXECUTABLE=${PHPBIN} bash /opt/php-qa/TEST-ENV/legacy-test.sh \ |
| 146 | + || make test PHP_EXECUTABLE=${PHPBIN} <<< n |
| 147 | + |
| 148 | + exit $? |
| 149 | + ;; |
| 150 | + *) |
| 151 | + errmsg "Unsupport mode '${1}'" |
| 152 | + exit 1 |
| 153 | +esac |
| 154 | + |
| 155 | +exit 0 |
0 commit comments