diff --git a/dist/tools/buildsystem_sanity_check/check.sh b/dist/tools/buildsystem_sanity_check/check.sh index 9d0a7bbaa8..63952705df 100755 --- a/dist/tools/buildsystem_sanity_check/check.sh +++ b/dist/tools/buildsystem_sanity_check/check.sh @@ -17,6 +17,24 @@ SCRIPT_PATH=dist/tools/buildsystem_sanity_check/check.sh + +tab_indent() { + # Ident using 'bashism' to to the tab compatible with 'bsd-sed' + sed 's/^/\'$'\t/' +} + +prepend() { + # 'i' needs 'i\{newline}' and a newline after for 'bsd-sed' + sed '1i\ +'"$1"' +' +} + +error_with_message() { + tab_indent | prepend "${1}" +} + + # Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL # Handling specific behaviors/dependencies should by checking the content of: # * `USEMODULE` @@ -28,6 +46,7 @@ check_not_parsing_features() { patterns+=(-e 'if.*filter.*FEATURES_PROVIDED') patterns+=(-e 'if.*filter.*FEATURES_REQUIRED') patterns+=(-e 'if.*filter.*FEATURES_OPTIONAL') + patterns+=(-e 'if.*filter.*FEATURES_USED') # Not a real one, it is just to show the error # Pathspec with exclude should start by an inclusive pathspec in git 2.7.4 pathspec+=('*') @@ -38,7 +57,8 @@ check_not_parsing_features() { # 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[@]}" + git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}" \ + | error_with_message 'Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL' } # Some variables do not need to be exported and even cause issues when being @@ -59,8 +79,11 @@ UNEXPORTED_VARIABLES+=('DEBUG_ADAPTER' 'DEBUG_ADAPTER_ID') UNEXPORTED_VARIABLES+=('PROGRAMMER_SERIAL') UNEXPORTED_VARIABLES+=('STLINK_VERSION') UNEXPORTED_VARIABLES+=('PORT_LINUX' 'PORT_DARWIN') +UNEXPORTED_VARIABLES+=('APPDEPS') + EXPORTED_VARIABLES_ONLY_IN_VARS=() +EXPORTED_VARIABLES_ONLY_IN_VARS+=('CC') check_not_exporting_variables() { local patterns=() local pathspec=() @@ -69,7 +92,8 @@ check_not_exporting_variables() { patterns+=(-e "export[[:blank:]]\+${variable}") done - git -C "${RIOTBASE}" grep "${patterns[@]}" + git -C "${RIOTBASE}" grep "${patterns[@]}" \ + | error_with_message 'Variables must not be exported:' # Some variables may still be exported in 'makefiles/vars.inc.mk' as the # only place that should export commont variables @@ -83,24 +107,24 @@ check_not_exporting_variables() { # Only run if there are patterns, otherwise it matches everything if [ ${#patterns[@]} -ne 0 ]; then - git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}" + git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}" \ + | error_with_message 'Variables must only be exported in `makefiles/vars.inc.mk`:' fi } +error_on_input() { + grep '' && return 1 +} + +all_checks() { + check_not_parsing_features + check_not_exporting_variables +} + 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 + all_checks | prepend 'Invalid build system patterns found by '"${0}:" || error_on_input >&2 + exit $? }