From 76dc51bb224b1ca89db387f6d48a6bfb5293f64a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= <karel.koci@nic.cz>
Date: Tue, 18 Feb 2020 14:56:36 +0100
Subject: [PATCH] compile_pkgs: verify generated config against our preferences

This checks generated config after Kconfig pass if it still contains
preferences we have in files in configs directory.

This also drops some of the options in our config that are obsolete or
invalid.

CONFIG_VERSION_REPO is overwritten by setting pushed dynamically in
config by compile_pkgs so it makes no sense to have it here.

CONFIG_BUSYBOX_DEFAULT_CROND seems to be impossible to change and is
also default value that we later override with
CONFIG_BUSYBOX_CONFIG_CROND.

All PACKAGE options are not necessary. They are all enabled to 'm' but
getting them to 'y' would require a lot of works with gain that build
would in some cases failed instead of passed without that package. Not
worth it.

CONFIG_DEFAULT_TARGET_OPTIMIZATION is not applies so it is dropped here
without replacement. Same as one occurrence of CONFIG_CPU_TYPE.
---
 compile_pkgs                      | 20 ++++++++++++++++++++
 configs/common/branding           |  1 -
 configs/common/busybox            |  2 --
 configs/common/essential_packages | 26 --------------------------
 configs/mox/base                  |  1 -
 configs/omnia/base                |  2 --
 configs/turris1x/base             |  1 -
 7 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/compile_pkgs b/compile_pkgs
index e636f4860..08f6fb8fb 100755
--- a/compile_pkgs
+++ b/compile_pkgs
@@ -14,6 +14,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
+shopt -s nullglob
 
 # Step list that is run when no commands are specified
 DEFAULT_STEPS=( "prepare" "compile" "sign" "store_hash" "pkgsrepo" "stats" "gen_junit" )
@@ -189,6 +190,25 @@ configure() {
 		echo "CONFIG_VERSION_CODE=\"$(_git_remote_hash)\""
 	} >> .config
 	_make defconfig diffconfig
+
+	# Verify config
+	for config in "${src_dir}/configs/common"/* "${src_dir}/configs/${TARGET_BOARD}"/*; do
+		 while IFS="=" read -r name value; do
+			 [ -z "$value" ] && continue
+			 [ "${value:0:1}" = "#" ] && continue
+			 if [ "$value" = "n" ]; then
+				 # No options can be ommited in the result so instead check it
+				 # they are not enabled by any chance.
+				 if grep -qE "^$name=y" ./.config; then
+					 die "Config option that is forced to 'n' is set to 'y': $name=$value"
+				 fi
+			else
+				 if ! grep -qE "^$name=$value$" ./.config; then
+					 die "Config option is not present in generated config: $name=$value"
+				 fi
+			 fi
+		done < "$config"
+	done
 }
 
 available_commands+=( ["update_mirror"]="Updates all local mirrors" )
diff --git a/configs/common/branding b/configs/common/branding
index 5c37f5bac..e4a7878a6 100644
--- a/configs/common/branding
+++ b/configs/common/branding
@@ -4,7 +4,6 @@ CONFIG_VERSIONOPT=y
 CONFIG_VERSION_MANUFACTURER="CZ.NIC"
 CONFIG_VERSION_MANUFACTURER_URL="https://www.turris.cz/"
 CONFIG_VERSION_DIST="TurrisOS"
-CONFIG_VERSION_REPO="https://repo.turris.cz/"
 CONFIG_VERSION_HOME_URL="https://www.turris.cz/"
 CONFIG_VERSION_BUG_URL="https://gitlab.labs.nic.cz/groups/turris/-/issues/"
 CONFIG_VERSION_SUPPORT_URL="https://www.turris.cz/support/"
diff --git a/configs/common/busybox b/configs/common/busybox
index c175e6143..560155c07 100644
--- a/configs/common/busybox
+++ b/configs/common/busybox
@@ -1,6 +1,5 @@
 # Enable most of the applets available
 CONFIG_BUSYBOX_CUSTOM=y
-CONFIG_BUSYBOX_DEFAULT_CROND=n
 CONFIG_BUSYBOX_CONFIG_CRONTAB=n
 CONFIG_BUSYBOX_CONFIG_CROND=n
 CONFIG_BUSYBOX_CONFIG_SYSLOGD=n
@@ -36,7 +35,6 @@ CONFIG_BUSYBOX_CONFIG_USE_BB_CRYPT_SHA=y
 CONFIG_BUSYBOX_CONFIG_EJECT=y
 CONFIG_BUSYBOX_CONFIG_FEATURE_EJECT_SCSI=y
 CONFIG_BUSYBOX_CONFIG_COMM=y
-CONFIG_BUSYBOX_CONFIG_FEATURE_FLOAT_SLEEP=y
 CONFIG_BUSYBOX_CONFIG_WATCHDOG=y
 CONFIG_BUSYBOX_CONFIG_DIFF=y
 CONFIG_BUSYBOX_CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
diff --git a/configs/common/essential_packages b/configs/common/essential_packages
index 1e913f01d..84aab92cf 100644
--- a/configs/common/essential_packages
+++ b/configs/common/essential_packages
@@ -5,17 +5,10 @@ CONFIG_PACKAGE_cznic-repo-keys-test=y
 CONFIG_PACKAGE_c-rehash=y
 CONFIG_PACKAGE_cert-backup=y
 CONFIG_PACKAGE_create_notification=y
-CONFIG_PACKAGE_oneshot=y
-CONFIG_PACKAGE_thermometer=y
-CONFIG_PACKAGE_nethist=y
-CONFIG_PACKAGE_server-uplink=y
 CONFIG_PACKAGE_update_mac=y
 CONFIG_PACKAGE_libatsha204=y
-CONFIG_PACKAGE_user_notify=y
 CONFIG_PACKAGE_watchdog_adjust=y
-CONFIG_PACKAGE_userspace_time_sync=y
 CONFIG_PACKAGE_start-indicator=y
-CONFIG_PACKAGE_vixie-cron=y
 
 # Turris packages
 CONFIG_PACKAGE_schnapps=y
@@ -23,18 +16,9 @@ CONFIG_PACKAGE_sentinel-certgen=y
 CONFIG_PACKAGE_dnssec-rootkey=y
 CONFIG_PACKAGE_resolver-conf=y
 CONFIG_PACKAGE_turris-utils=y
-CONFIG_PACKAGE_turris-maintain=y
 CONFIG_PACKAGE_turris-webapps=y
 CONFIG_PACKAGE_turris-version=y
 
-# Foris packages
-CONFIG_PACKAGE_foris=y
-CONFIG_PACKAGE_foris-client=y
-CONFIG_PACKAGE_foris-controller=y
-CONFIG_PACKAGE_foris-diagnostics-plugin=y
-CONFIG_PACKAGE_foris-l10n-cs=y
-CONFIG_PACKAGE_foris-ws=y
-
 # Updater packages
 CONFIG_PACKAGE_updater-ng=y
 CONFIG_PACKAGE_updater-supervisor=y
@@ -74,7 +58,6 @@ CONFIG_PACKAGE_kmod-ledtrig-heartbeat=y
 # LuCI
 CONFIG_PACKAGE_luci-base=y
 CONFIG_PACKAGE_luci=y
-CONFIG_PACKAGE_luci-lighttpd=y
 CONFIG_PACKAGE_luci-mod-admin-full=y
 CONFIG_PACKAGE_luci-mod-rpc=y
 CONFIG_PACKAGE_luci-app-firewall=y
@@ -91,15 +74,6 @@ CONFIG_PACKAGE_openssh-moduli=y
 CONFIG_PACKAGE_openssh-server=y
 CONFIG_PACKAGE_openssh-sftp-server=y
 
-# Lighttpd packages
-CONFIG_PACKAGE_lighttpd=y
-CONFIG_PACKAGE_lighttpd-luci=y
-CONFIG_PACKAGE_lighttpd-https-cert=y
-CONFIG_PACKAGE_lighttpd-mod-fastcgi=y
-CONFIG_PACKAGE_lighttpd-mod-openssl=y
-CONFIG_PACKAGE_lighttpd-mod-proxy=y
-CONFIG_PACKAGE_lighttpd-mod-redirect=y
-
 # Wireless packages
 CONFIG_PACKAGE_hostapd-common=y
 CONFIG_PACKAGE_iw-full=y
diff --git a/configs/mox/base b/configs/mox/base
index 0b833538b..f903a3dd9 100644
--- a/configs/mox/base
+++ b/configs/mox/base
@@ -1,4 +1,3 @@
 CONFIG_TARGET_mvebu=y
 CONFIG_TARGET_mvebu_cortexa53=y
 CONFIG_TARGET_mvebu_cortexa53_DEVICE_cznic-mox=y
-CONFIG_DEFAULT_TARGET_OPTIMIZATION="-O2 -pipe -mcpu=cortex-a53"
diff --git a/configs/omnia/base b/configs/omnia/base
index 4726bdf18..0c74250ed 100644
--- a/configs/omnia/base
+++ b/configs/omnia/base
@@ -1,5 +1,3 @@
 CONFIG_TARGET_mvebu=y
 CONFIG_TARGET_mvebu_cortexa9=y
 CONFIG_TARGET_mvebu_cortexa9_DEVICE_cznic_turris-omnia=y
-CONFIG_DEFAULT_TARGET_OPTIMIZATION="-O2 -pipe -mcpu=cortex-a9 -mfpu=vfpv3-d16"
-CONFIG_CPU_TYPE="cortex-a9+vfpv3"
diff --git a/configs/turris1x/base b/configs/turris1x/base
index 75f632355..2f28ed093 100644
--- a/configs/turris1x/base
+++ b/configs/turris1x/base
@@ -1,5 +1,4 @@
 CONFIG_TARGET_mpc85xx=y
 CONFIG_TARGET_mpc85xx_p2020=y
 CONFIG_TARGET_mpc85xx_p2020_DEVICE_turris1x=y
-CONFIG_DEFAULT_TARGET_OPTIMIZATION="-O2 -pipe -mcpu=8540"
 CONFIG_SOFT_FLOAT=y
-- 
GitLab