| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | CIDIR=$(dirname $(readlink -fn $0)) |
| 4 | COVERAGE=0 |
| 5 | REF_DEBUG=0 |
| 6 | DISABLE_BINARY_MODULES=0 |
| 7 | NO_CONFIGURE=0 |
| 8 | NO_MENUSELECT=0 |
| 9 | NO_MAKE=0 |
| 10 | NO_ALEMBIC=0 |
| 11 | NO_DEV_MODE=0 |
| 12 | source $CIDIR/ci.functions |
| 13 | |
| 14 | set -e |
| 15 | |
| 16 | if [ -z $BRANCH_NAME ]; then |
| 17 | BRANCH_NAME=$(git config -f .gitreview --get gerrit.defaultbranch) |
| 18 | fi |
| 19 | |
| 20 | if [[ "$BRANCH_NAME" =~ devel(opment)?/([0-9]+)/.+ ]] ; then |
| 21 | export MAINLINE_BRANCH="${BASH_REMATCH[2]}" |
| 22 | fi |
| 23 | |
| 24 | gen_cats() { |
| 25 | set +x |
| 26 | action=$1 |
| 27 | shift |
| 28 | cats=$@ |
| 29 | |
| 30 | for x in $cats ; do |
| 31 | echo " --${action}-category ${x}" |
| 32 | done |
| 33 | } |
| 34 | |
| 35 | gen_mods() { |
| 36 | set +x |
| 37 | action=$1 |
| 38 | shift |
| 39 | mods=$@ |
| 40 | |
| 41 | for x in $mods ; do |
| 42 | echo " --${action} ${x}" |
| 43 | done |
| 44 | } |
| 45 | |
| 46 | run_alembic() { |
| 47 | pushd contrib/ast-db-manage >/dev/null |
| 48 | runner alembic $@ |
| 49 | RC=$? |
| 50 | popd > /dev/null |
| 51 | return $RC |
| 52 | } |
| 53 | |
| 54 | [ x"$OUTPUT_DIR" != x ] && mkdir -p "$OUTPUT_DIR" 2> /dev/null |
| 55 | |
| 56 | if [ -z $TESTED_ONLY ]; then |
| 57 | # Skip building untested modules by default if coverage is enabled. |
| 58 | TESTED_ONLY=$COVERAGE |
| 59 | fi |
| 60 | |
| 61 | if [ -z $LCOV_DIR ]; then |
| 62 | LCOV_DIR="${OUTPUT_DIR:+${OUTPUT_DIR}/}lcov" |
| 63 | fi |
| 64 | |
| 65 | if [ x"$CACHE_DIR" != x ] ; then |
| 66 | mkdir -p $CACHE_DIR/sounds $CACHE_DIR/externals 2> /dev/null |
| 67 | fi |
| 68 | |
| 69 | if [ ${CCACHE_DISABLE:-0} -ne 1 ] ; then |
| 70 | if [ x"$CACHE_DIR" != x ] ; then |
| 71 | mkdir -p $CACHE_DIR/ccache |
| 72 | export CCACHE_UMASK=002 |
| 73 | export CCACHE_DIR=$CACHE_DIR/ccache |
| 74 | fi |
| 75 | case ":${PATH:-}:" in |
| 76 | *:/usr/lib*/ccache:*) |
| 77 | echo "Enabling ccache at $CCACHE_DIR" |
| 78 | ;; |
| 79 | *) |
| 80 | if [ -d /usr/lib64/ccache ] ; then |
| 81 | echo "Enabling ccache at /usr/lib64/ccache with $CCACHE_DIR" |
| 82 | export PATH="/usr/lib64/ccache${PATH:+:$PATH}" |
| 83 | elif [ -d /usr/lib/ccache ] ; then |
| 84 | echo "Enabling ccache at /usr/lib/ccache with $CCACHE_DIR" |
| 85 | export PATH="/usr/lib/ccache${PATH:+:$PATH}" |
| 86 | fi |
| 87 | ;; |
| 88 | esac |
| 89 | fi |
| 90 | |
| 91 | runner ccache -s |
| 92 | runner ulimit -a |
| 93 | |
| 94 | MAKE=`which make` |
| 95 | PKGCONFIG=`which pkg-config` |
| 96 | _libdir=`${CIDIR}/findLibdir.sh` |
| 97 | |
| 98 | _version=$(./build_tools/make_version .) |
| 99 | for var in BRANCH_NAME MAINLINE_BRANCH OUTPUT_DIR CACHE_DIR CCACHE_DISABLE CCACHE_DIR _libdir _version ; do |
| 100 | declare -p $var || : |
| 101 | done |
| 102 | |
| 103 | common_config_args="--prefix=/usr ${_libdir:+--libdir=${_libdir}} --sysconfdir=/etc --with-pjproject-bundled" |
| 104 | $PKGCONFIG 'jansson >= 2.11' || common_config_args+=" --with-jansson-bundled" |
| 105 | common_config_args+=" ${CACHE_DIR:+--with-sounds-cache=${CACHE_DIR}/sounds --with-externals-cache=${CACHE_DIR}/externals}" |
| 106 | if [ $NO_DEV_MODE -eq 0 ] ; then |
| 107 | common_config_args+=" --enable-dev-mode" |
| 108 | fi |
| 109 | if [ $COVERAGE -eq 1 ] ; then |
| 110 | common_config_args+=" --enable-coverage" |
| 111 | fi |
| 112 | if [ "$BRANCH_NAME" == "master" -o $DISABLE_BINARY_MODULES -eq 1 ] ; then |
| 113 | common_config_args+=" --disable-binary-modules" |
| 114 | fi |
| 115 | |
| 116 | export WGET_EXTRA_ARGS="--quiet" |
| 117 | |
| 118 | if [ $NO_CONFIGURE -eq 0 ] ; then |
| 119 | runner ./configure ${common_config_args} > ${OUTPUT_DIR:+${OUTPUT_DIR}/}configure.txt |
| 120 | fi |
| 121 | |
| 122 | if [ $NO_MENUSELECT -eq 0 ] ; then |
| 123 | runner ${MAKE} menuselect.makeopts |
| 124 | |
| 125 | runner menuselect/menuselect `gen_mods enable DONT_OPTIMIZE BETTER_BACKTRACES` menuselect.makeopts |
| 126 | if [ $NO_DEV_MODE -eq 0 ] ; then |
| 127 | runner menuselect/menuselect `gen_mods enable MALLOC_DEBUG DO_CRASH TEST_FRAMEWORK` menuselect.makeopts |
| 128 | fi |
| 129 | runner menuselect/menuselect `gen_mods disable COMPILE_DOUBLE BUILD_NATIVE` menuselect.makeopts |
| 130 | if [ $REF_DEBUG -eq 1 ] ; then |
| 131 | runner menuselect/menuselect --enable REF_DEBUG menuselect.makeopts |
| 132 | fi |
| 133 | |
| 134 | cat_enables="" |
| 135 | |
| 136 | if [[ ! "${BRANCH_NAME}" =~ ^certified ]] ; then |
| 137 | cat_enables+=" MENUSELECT_BRIDGES MENUSELECT_CEL MENUSELECT_CDR" |
| 138 | cat_enables+=" MENUSELECT_CHANNELS MENUSELECT_CODECS MENUSELECT_FORMATS MENUSELECT_FUNCS" |
| 139 | cat_enables+=" MENUSELECT_PBX MENUSELECT_RES MENUSELECT_UTILS" |
| 140 | fi |
| 141 | |
| 142 | if [ $NO_DEV_MODE -eq 0 ] ; then |
| 143 | cat_enables+=" MENUSELECT_TESTS" |
| 144 | fi |
| 145 | runner menuselect/menuselect `gen_cats enable $cat_enables` menuselect.makeopts |
| 146 | |
| 147 | mod_disables="res_digium_phone" |
| 148 | if [ $TESTED_ONLY -eq 1 ] ; then |
| 149 | # These modules are not tested at all. They are loaded but nothing is ever done |
| 150 | # with them, no testsuite tests depend on them. |
| 151 | mod_disables+=" app_adsiprog app_alarmreceiver app_celgenuserevent app_db app_dictate" |
| 152 | mod_disables+=" app_dumpchan app_externalivr app_festival app_getcpeid" |
| 153 | mod_disables+=" app_jack app_milliwatt app_minivm app_morsecode app_mp3 app_privacy" |
| 154 | mod_disables+=" app_readexten app_sms app_speech_utils app_test app_waitforring" |
| 155 | mod_disables+=" app_waitforsilence app_waituntil app_zapateller" |
| 156 | mod_disables+=" cdr_adaptive_odbc cdr_custom cdr_manager cdr_odbc cdr_pgsql cdr_radius" |
| 157 | mod_disables+=" cdr_tds" |
| 158 | mod_disables+=" cel_odbc cel_pgsql cel_radius cel_sqlite3_custom cel_tds" |
| 159 | mod_disables+=" chan_console chan_motif chan_rtp chan_unistim" |
| 160 | mod_disables+=" func_frame_trace func_pitchshift func_speex func_volume func_dialgroup" |
| 161 | mod_disables+=" func_periodic_hook func_sprintf func_enum func_extstate func_sysinfo func_iconv" |
| 162 | mod_disables+=" func_callcompletion func_version func_rand func_sha1 func_module func_md5" |
| 163 | mod_disables+=" pbx_dundi pbx_loopback" |
| 164 | mod_disables+=" res_ael_share res_calendar res_config_ldap res_config_pgsql res_corosync" |
| 165 | mod_disables+=" res_http_post res_rtp_multicast res_snmp res_xmpp" |
| 166 | fi |
| 167 | |
| 168 | runner menuselect/menuselect `gen_mods disable $mod_disables` menuselect.makeopts |
| 169 | |
| 170 | mod_enables="app_voicemail app_directory" |
| 171 | mod_enables+=" res_mwi_external res_ari_mailboxes res_mwi_external_ami res_stasis_mailbox" |
| 172 | mod_enables+=" CORE-SOUNDS-EN-GSM MOH-OPSOUND-GSM EXTRA-SOUNDS-EN-GSM" |
| 173 | runner menuselect/menuselect `gen_mods enable $mod_enables` menuselect.makeopts |
| 174 | fi |
| 175 | |
| 176 | if [ $NO_MAKE -eq 0 ] ; then |
| 177 | runner ${MAKE} -j8 full || runner ${MAKE} -j1 NOISY_BUILD=yes full |
| 178 | fi |
| 179 | |
| 180 | runner rm -f ${LCOV_DIR}/*.info |
| 181 | if [ $COVERAGE -eq 1 ] ; then |
| 182 | runner mkdir -p ${LCOV_DIR} |
| 183 | |
| 184 | # Zero counter data |
| 185 | runner lcov --quiet --directory . --zerocounters |
| 186 | |
| 187 | # Branch coverage is not supported by --initial. Disable to suppresses a notice |
| 188 | # printed if it was enabled in lcovrc. |
| 189 | # This initial capture ensures any module which was built but never loaded is |
| 190 | # reported with 0% coverage for all sources. |
| 191 | runner lcov --quiet --directory . --no-external --capture --initial --rc lcov_branch_coverage=0 \ |
| 192 | --output-file ${LCOV_DIR}/initial.info |
| 193 | fi |
| 194 | |
| 195 | if [ $NO_ALEMBIC -eq 0 ] ; then |
| 196 | ALEMBIC=$(which alembic 2>/dev/null || : ) |
| 197 | if [ x"$ALEMBIC" = x ] ; then |
| 198 | >&2 echo "Alembic not installed" |
| 199 | exit 1 |
| 200 | fi |
| 201 | |
| 202 | find contrib/ast-db-manage -name *.pyc -delete |
| 203 | out=$(run_alembic -c config.ini.sample branches) |
| 204 | if [ "x$out" != "x" ] ; then |
| 205 | >&2 echo "Alembic branches were found for config" |
| 206 | >&2 echo $out |
| 207 | exit 1 |
| 208 | fi |
| 209 | run_alembic -c config.ini.sample upgrade head --sql > "${OUTPUT_DIR:+${OUTPUT_DIR}/}alembic-config.sql" || exit 1 |
| 210 | echo "Alembic for 'config' OK" |
| 211 | |
| 212 | out=$(run_alembic -c cdr.ini.sample branches) |
| 213 | if [ "x$out" != "x" ] ; then |
| 214 | >&2 echo "Alembic branches were found for cdr" |
| 215 | >&2 echo $out |
| 216 | exit 1 |
| 217 | fi |
| 218 | run_alembic -c cdr.ini.sample upgrade head --sql > "${OUTPUT_DIR:+${OUTPUT_DIR}/}alembic-cdr.sql" || exit 1 |
| 219 | echo "Alembic for 'cdr' OK" |
| 220 | |
| 221 | out=$(run_alembic -c voicemail.ini.sample branches) |
| 222 | if [ "x$out" != "x" ] ; then |
| 223 | >&2 echo "Alembic branches were found for voicemail" |
| 224 | >&2 echo $out |
| 225 | exit 1 |
| 226 | fi |
| 227 | run_alembic -c voicemail.ini.sample upgrade head --sql > "${OUTPUT_DIR:+${OUTPUT_DIR}/}alembic-voicemail.sql" || exit 1 |
| 228 | echo "Alembic for 'voicemail' OK" |
| 229 | fi |
| 230 | |
| 231 | if [ -f "doc/core-en_US.xml" ] ; then |
| 232 | runner ${MAKE} validate-docs || ${MAKE} NOISY_BUILD=yes validate-docs |
| 233 | fi |