summaryrefslogtreecommitdiffstats
path: root/tools/check-directives.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
commitb750101eb236130cf056c675997decbac904cc49 (patch)
treea5df1a06754bdd014cb975c051c83b01c9a97532 /tools/check-directives.sh
parentInitial commit. (diff)
downloadsystemd-b750101eb236130cf056c675997decbac904cc49.tar.xz
systemd-b750101eb236130cf056c675997decbac904cc49.zip
Adding upstream version 252.22.upstream/252.22upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/check-directives.sh')
-rwxr-xr-xtools/check-directives.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/tools/check-directives.sh b/tools/check-directives.sh
new file mode 100755
index 0000000..7678332
--- /dev/null
+++ b/tools/check-directives.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eu
+set -o pipefail
+
+SOURCE_ROOT="${1:?}"
+BUILD_ROOT="${2:?}"
+
+command -v gawk &>/dev/null || exit 77
+
+function generate_directives() {
+ gawk -v sec_rx="${2:-""}" -v unit_type="${3:-""}" '
+ match($0, /^([^ \t\.]+)\.([^ \t\.,]+)/, m) {
+ # res[section][directive] = 1
+ res[m[1]][m[2]] = 1;
+ }
+ END {
+ if (unit_type)
+ print unit_type
+
+ for (section in res) {
+ if (sec_rx && section !~ sec_rx)
+ continue
+
+ print "[" section "]";
+ for (directive in res[section]) {
+ print directive "=";
+ }
+ }
+ }
+ ' "$1"
+}
+
+ret=0
+if ! diff \
+ <(generate_directives "$SOURCE_ROOT"/src/network/networkd-network-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-network-parser/directives); then
+ echo "Looks like test/fuzz/fuzz-network-parser/directives hasn't been updated"
+ ret=1
+fi
+
+if ! diff \
+ <(generate_directives "$SOURCE_ROOT"/src/network/netdev/netdev-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-netdev-parser/directives.netdev); then
+ echo "Looks like test/fuzz/fuzz-netdev-parser/directives.netdev hasn't been updated"
+ ret=1
+fi
+
+if ! diff \
+ <(generate_directives "$SOURCE_ROOT"/src/udev/net/link-config-gperf.gperf | sort) \
+ <(sort "$SOURCE_ROOT"/test/fuzz/fuzz-link-parser/directives.link) ; then
+ echo "Looks like test/fuzz/fuzz-link-parser/directives.link hasn't been updated"
+ ret=1
+fi
+
+for section in Automount Mount Path Scope Slice Socket Swap Timer; do
+ if ! diff \
+ <(generate_directives "$BUILD_ROOT"/src/core/load-fragment-gperf.gperf "$section" "${section,,}" | sort) \
+ <(sort "$SOURCE_ROOT/test/fuzz/fuzz-unit-file/directives.${section,,}") ; then
+ echo "Looks like test/fuzz/fuzz-unit-file/directives.${section,,} hasn't been updated"
+ ret=1
+ fi
+done
+
+if ! diff \
+ <(generate_directives "$BUILD_ROOT"/src/core/load-fragment-gperf.gperf "(Service|Unit|Install)" "service" | sort) \
+ <(sort "$SOURCE_ROOT/test/fuzz/fuzz-unit-file/directives.service") ; then
+ echo "Looks like test/fuzz/fuzz-unit-file/directives.service hasn't been updated"
+ ret=1
+fi
+
+exit $ret