From 2e45d4ada6664dd47733c87d1495a960683a87ff Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 9 Nov 2018 18:08:45 +0100 Subject: [PATCH] build: check that the list of supported config options is up to date Add a script run during 'make check' to verify that all config options are in the list of supported ones. --- Makefile.am | 6 ++++++ src/meson.build | 6 ++++++ src/nm-config.c | 6 ++++++ src/nm-config.h | 4 ++-- tools/check-config-options.sh | 28 ++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100755 tools/check-config-options.sh diff --git a/Makefile.am b/Makefile.am index 03cad16a92..d298e54d91 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1486,6 +1486,11 @@ noinst_LTLIBRARIES += \ src/libNetworkManager.la \ src/libsystemd-nm.la +check-config-options: + $(srcdir)/tools/check-config-options.sh "$(srcdir)" + +check_local += check-config-options + ############################################################################### src_libsystemd_nm_la_cppflags = \ @@ -5158,6 +5163,7 @@ EXTRA_DIST += \ shared/nm-version-macros.h.in \ shared/meson.build \ \ + tools/check-config-options.sh \ tools/check-docs.sh \ tools/check-exports.sh \ tools/create-exports-NetworkManager.sh \ diff --git a/src/meson.build b/src/meson.build index ca9919f65a..8575f58868 100644 --- a/src/meson.build +++ b/src/meson.build @@ -309,3 +309,9 @@ if enable_tests env: ['LD_BIND_NOW=1', 'LD_PRELOAD=' + plugin.full_path()]) endforeach endif + +test( + 'check-config-options', + find_program(join_paths(meson.source_root(), 'tools', 'check-config-options.sh')), + args: [meson.source_root()] +) diff --git a/src/nm-config.c b/src/nm-config.c index 0bb615cd3f..4f060d335b 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -743,6 +743,9 @@ typedef struct { bool is_connection:1; } ConfigGroup; +/* The following comment is used by check-config-options.sh, don't remove it. */ +/* START OPTION LIST */ + static const ConfigGroup config_groups[] = { { .group = NM_CONFIG_KEYFILE_GROUP_MAIN, @@ -837,6 +840,9 @@ static const ConfigGroup config_groups[] = { { } /* sentinel */ }; +/* The following comment is used by check-config-options.sh, don't remove it. */ +/* END OPTION LIST */ + static gboolean check_config_key (const char *group, const char *key) { diff --git a/src/nm-config.h b/src/nm-config.h index 53cc8dd0f1..66f1b69c09 100644 --- a/src/nm-config.h +++ b/src/nm-config.h @@ -105,8 +105,8 @@ #define NM_CONFIG_KEYFILE_KEY_MATCH_DEVICE "match-device" #define NM_CONFIG_KEYFILE_KEY_STOP_MATCH "stop-match" -#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was" -#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable" +#define NM_CONFIG_KEYFILE_KEY_ATOMIC_SECTION_WAS ".was" /* check-config-options skip */ +#define NM_CONFIG_KEYFILE_KEY_CONFIG_ENABLE "enable" /* check-config-options skip */ #define NM_CONFIG_KEYFILE_KEYPREFIX_WAS ".was." #define NM_CONFIG_KEYFILE_KEYPREFIX_SET ".set." diff --git a/tools/check-config-options.sh b/tools/check-config-options.sh new file mode 100755 index 0000000000..171b25e39b --- /dev/null +++ b/tools/check-config-options.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +srcdir=${1:-.} + +get_supported_options() +{ + awk '/START OPTION LIST/{flag=1;next}/END OPTION LIST/{flag=0}flag' "$srcdir/src/nm-config.c" | + grep -o 'NM_CONFIG_KEYFILE_KEY_\w*' +} + +get_missing() +{ + grep -v '/\* check-config-options skip \*/' "$srcdir/src/nm-config.h" | + grep -o 'NM_CONFIG_KEYFILE_KEY_\w*' | + grep -v -Fx -f <(get_supported_options) +} + +missing=$(get_missing) + +if [ -n "$missing" ]; then + echo "***" + echo "*** Error: the following configuration options are defined but not present in the list of supported options" + echo "***" + echo "$missing" + exit 1 +fi + +exit 0