buildAsterisk.sh 7.3 KB

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