1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/dist/tools/buildsystem_sanity_check/check.sh
Gaëtan Harter 42b3cd5903
dist/tools/buildsystem_sanity_check: add an export variable check
Check that some variables are not exported in the build system.
This should track variables that managed to not be exported anymore so
that they do not reappear in a BSP.

It is not a whitelist but just a way to keep things cleaned in the
future.
2019-05-06 13:36:46 +02:00

90 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (C) 2018 Gaëtan Harter <gaetan.harter@fu-berlin.de>
#
# 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[@]}"
}
# Some variables do not need to be exported and even cause issues when being
# exported because they are evaluated even when not needed.
#
# Currently this blacklists exported variables instead of whitelisting or
# providing a mechanism for handling it.
# It just keep things not exported anymore in the future.
UNEXPORTED_VARIABLES=()
UNEXPORTED_VARIABLES+=('FLASHFILE')
UNEXPORTED_VARIABLES+=('TERMPROG' 'TERMFLAGS')
check_not_exporting_variables() {
local patterns=()
local pathspec=()
for variable in "${UNEXPORTED_VARIABLES[@]}"; do
patterns+=(-e "export[[:blank:]]\+${variable}")
done
pathspec+=('*')
# Ignore `makefiles/vars.inc.mk` as it currently is the only place that
# should export common variables.
pathspec+=(':!makefiles/vars.inc.mk')
git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}"
}
main() {
local errors=''
errors+="$(check_not_parsing_features)"
errors+="$(check_not_exporting_variables)"
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