From abb04622f7667cf10af3399a104b62bf409244d6 Mon Sep 17 00:00:00 2001
From: Corey Farrell <git@cfware.com>
Date: Sun, 26 Aug 2018 14:18:42 -0400
Subject: [PATCH] Create --disable-binary-modules option.

This new option can be passed for ./configure or
./tests/CI/buildAsterisk.sh to prevent download/install of binary
modules.

Normally enabling the categories MENUSELECT_CODECS or MENUSELECT_RES
will result in binary modules being enabled even if the build target is
incompatible with those modules.  This includes CI scripts which enable
categories before disabling specific modules.

If more binary modules are offered in the future this will help avoid
accidentally downloading them if unwanted or incompatible.  Adding a
binary module will only require creating a new menuselect entry similar
to the existing ones, it will not be necessary to modify the CI scripts.

Change-Id: I6b1bd1c75a2e48f05b8b8a45b7a7a2d00a079166
---
 build_tools/menuselect-deps.in |  1 +
 codecs/codecs.xml              |  5 +++++
 configure                      | 16 ++++++++++++++++
 configure.ac                   | 11 +++++++++++
 res/res.xml                    |  1 +
 tests/CI/buildAsterisk.sh      |  7 ++++++-
 6 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/build_tools/menuselect-deps.in b/build_tools/menuselect-deps.in
index 2c2bd532b2..f1cd20df2e 100644
--- a/build_tools/menuselect-deps.in
+++ b/build_tools/menuselect-deps.in
@@ -77,3 +77,4 @@ HAVE_ADDRESS_SANITIZER=@AST_ADDRESS_SANITIZER@
 HAVE_LEAK_SANITIZER=@AST_LEAK_SANITIZER@
 HAVE_THREAD_SANITIZER=@AST_THREAD_SANITIZER@
 HAVE_UNDEFINED_SANITIZER=@AST_UNDEFINED_SANITIZER@
+NO_BINARY_MODULES=@PBX_NO_BINARY_MODULES@
diff --git a/codecs/codecs.xml b/codecs/codecs.xml
index 0b4e2a4740..996a3559b7 100644
--- a/codecs/codecs.xml
+++ b/codecs/codecs.xml
@@ -1,5 +1,6 @@
 <member name="codec_opus" displayname="Download the Opus codec from Digium.  See http://downloads.digium.com/pub/telephony/codec_opus/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<depend>res_format_attr_opus</depend>
@@ -7,24 +8,28 @@
 </member>
 <member name="codec_silk" displayname="Download the SILK codec from Digium.  See http://downloads.digium.com/pub/telephony/codec_silk/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<defaultenabled>no</defaultenabled>
 </member>
 <member name="codec_siren7" displayname="Download the Siren7 codec from Digium.  See http://downloads.digium.com/pub/telephony/codec_siren7/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<defaultenabled>no</defaultenabled>
 </member>
 <member name="codec_siren14" displayname="Download the Siren14 codec from Digium.  See http://downloads.digium.com/pub/telephony/codec_siren14/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<defaultenabled>no</defaultenabled>
 </member>
 <member name="codec_g729a" displayname="Download the g729a codec from Digium.  A license must be purchased for this codec.  See http://downloads.digium.com/pub/telephony/codec_g729/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<defaultenabled>no</defaultenabled>
diff --git a/configure b/configure
index 41faa876ae..f3440e5cb1 100755
--- a/configure
+++ b/configure
@@ -1187,6 +1187,7 @@ AST_DOWNLOAD_CACHE
 AST_DEVMODE_STRICT
 AST_DEVMODE
 NOISY_BUILD
+PBX_NO_BINARY_MODULES
 PTHREAD_CFLAGS
 PTHREAD_LIBS
 PTHREAD_CC
@@ -1337,6 +1338,7 @@ ac_subst_files=''
 ac_user_opts='
 enable_option_checking
 with_gnu_ld
+enable_binary_modules
 enable_dev_mode
 with_download_cache
 with_sounds_cache
@@ -2074,6 +2076,8 @@ Optional Features:
   --disable-option-checking  ignore unrecognized --enable/--with options
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
+  --disable-binary-modules
+                          Block installation of binary modules.
   --enable-dev-mode       Turn on developer mode
   --enable-coverage       Turn on code coverage tracking (for gcov)
   --disable-xmldoc        Explicitly disable XML documentation
@@ -8896,6 +8900,18 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
+PBX_NO_BINARY_MODULES=0
+# Check whether --enable-binary-modules was given.
+if test "${enable_binary_modules+set}" = set; then :
+  enableval=$enable_binary_modules; case "${enableval}" in
+	      y|ye|yes) PBX_NO_BINARY_MODULES=0 ;;
+	      n|no)  PBX_NO_BINARY_MODULES=1 ;;
+	      *) as_fn_error $? "bad value ${enableval} for --disable-binary-modules" "$LINENO" 5  ;;
+	esac
+fi
+
+
+
 # Check whether --enable-dev-mode was given.
 if test "${enable_dev_mode+set}" = set; then :
   enableval=$enable_dev_mode; case "${enableval}" in
diff --git a/configure.ac b/configure.ac
index caab39dad5..0823e1de4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -386,6 +386,17 @@ AX_PTHREAD
 
 AC_LANG(C)
 
+PBX_NO_BINARY_MODULES=0
+AC_ARG_ENABLE([binary-modules],
+	[AS_HELP_STRING([--disable-binary-modules],
+		[Block installation of binary modules.])],
+	[case "${enableval}" in
+	      y|ye|yes) PBX_NO_BINARY_MODULES=0 ;;
+	      n|no)  PBX_NO_BINARY_MODULES=1 ;;
+	      *) AC_MSG_ERROR(bad value ${enableval} for --disable-binary-modules)  ;;
+	esac])
+AC_SUBST(PBX_NO_BINARY_MODULES)
+
 AC_ARG_ENABLE([dev-mode],
 	[AS_HELP_STRING([--enable-dev-mode],
 		[Turn on developer mode])],
diff --git a/res/res.xml b/res/res.xml
index a340cc2fdc..ace1792650 100644
--- a/res/res.xml
+++ b/res/res.xml
@@ -1,5 +1,6 @@
 <member name="res_digium_phone" displayname="Download the Digium Phone Module for Asterisk.  See http://downloads.digium.com/pub/telephony/res_digium_phone/README.">
 	<support_level>external</support_level>
+	<conflict>no_binary_modules</conflict>
 	<depend>xmlstarlet</depend>
 	<depend>bash</depend>
 	<defaultenabled>no</defaultenabled>
diff --git a/tests/CI/buildAsterisk.sh b/tests/CI/buildAsterisk.sh
index b3266bdac8..b36e7de6c4 100755
--- a/tests/CI/buildAsterisk.sh
+++ b/tests/CI/buildAsterisk.sh
@@ -3,6 +3,7 @@
 CIDIR=$(dirname $(readlink -fn $0))
 COVERAGE=0
 REF_DEBUG=0
+DISABLE_BINARY_MODULES=0
 source $CIDIR/ci.functions
 
 gen_cats() {
@@ -76,6 +77,10 @@ common_config_args+=" --enable-dev-mode"
 if [ $COVERAGE -eq 1 ] ; then
 	common_config_args+=" --enable-coverage"
 fi
+if [ "$BRANCH_NAME" == "master" -o $DISABLE_BINARY_MODULES -eq 1 ] ; then
+	common_config_args+=" --disable-binary-modules"
+fi
+
 export WGET_EXTRA_ARGS="--quiet"
 
 runner ./configure ${common_config_args} > ${OUTPUT_DIR:+${OUTPUT_DIR}/}configure.txt
@@ -120,7 +125,7 @@ if [ $REF_DEBUG -eq 1 ] ; then
 	# To test for reference leaks with realtime usage you must test against Asterisk 16+.
 	mod_disables+=" res_odbc"
 fi
-[ "$BRANCH_NAME" == "master" ] && mod_disables+=" codec_opus codec_silk codec_g729a codec_siren7 codec_siren14"
+
 runner menuselect/menuselect `gen_mods disable $mod_disables` menuselect.makeopts
 
 mod_enables="app_voicemail app_directory FILE_STORAGE"
-- 
GitLab