From 143e393fcd04a6b071e3fff226b6c542697c24af Mon Sep 17 00:00:00 2001 From: cladmi Date: Wed, 26 Sep 2018 17:10:12 +0200 Subject: [PATCH] dist/tools: add build system sanity check script Add a script to execute sanity checks on build system files. It should prevent bad patterns to re-appear after being cleaned. Currently adds a check for using the content of `FEATURES` instead of `USEMODULE`. Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL Handling specific behaviors/dependencies should by checking the content of: * `USEMODULE` * maybe `FEATURES_USED` if it is not a module (== not a periph_) --- dist/tools/buildsystem_sanity_check/check.sh | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 dist/tools/buildsystem_sanity_check/check.sh diff --git a/dist/tools/buildsystem_sanity_check/check.sh b/dist/tools/buildsystem_sanity_check/check.sh new file mode 100755 index 000000000000..98758ec754f0 --- /dev/null +++ b/dist/tools/buildsystem_sanity_check/check.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2018 Gaƫtan Harter +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +# +# Central test script to have sanity checks for the build system +# It is run unconditionally on all files. +# +# + +: "${RIOTBASE:="$(cd "$(dirname "$0")/../../../" || exit; pwd)"}" + +SCRIPT_PATH=dist/tools/buildsystem_sanity_check/check.sh + +# Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL +# Handling specific behaviors/dependencies should by checking the content of: +# * `USEMODULE` +# * maybe `FEATURES_USED` if it is not a module (== not a periph_) +check_not_parsing_features() { + local patterns=() + local pathspec=() + + patterns+=(-e 'if.*filter.*FEATURES_PROVIDED') + patterns+=(-e 'if.*filter.*FEATURES_REQUIRED') + patterns+=(-e 'if.*filter.*FEATURES_OPTIONAL') + + # Pathspec with exclude should start by an inclusive pathspec in git 2.7.4 + pathspec+=('*') + + # Ignore this file when matching as it self matches + pathspec+=(":!${SCRIPT_PATH}") + + # These two files contain sanity checks using FEATURES_ so are allowed + pathspec+=(':!Makefile.include' ':!makefiles/info-global.inc.mk') + + git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}" +} + + +main() { + local errors='' + + errors+="$(check_not_parsing_features)" + + if [ -n "${errors}" ] + then + printf 'Invalid build system patterns found by %s:\n' "${0}" + printf '%s\n' "${errors}" + exit 1 + fi + exit 0 +} + + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main +fi