Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

dist/tools/buildsystem_sanity_check: make shellcheck happy #20721

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 14 additions & 34 deletions dist/tools/buildsystem_sanity_check/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,30 @@
: "${RIOTBASE:="$(cd "$(dirname "$0")/../../../" || exit; pwd)"}"

: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
# not running shellcheck with -x in the CI --> disable SC1091
# shellcheck disable=SC1091
. "${RIOTTOOLS}"/ci/github_annotate.sh

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() {
while read INPUT; do
while read -r INPUT; do
MESSAGE="${1}"
if github_annotate_is_on; then
MESSAGE="${1}"
FILE=$(echo "${INPUT}" | cut -d: -f1)
LINE=$(echo "${INPUT}" | cut -d: -f2)
MATCH=$(echo "${INPUT}" | cut -d: -f3)
if [[ $var =~ ^[0-9]+$ ]] || [ -z "$MATCH" ]; then
if [[ ! $LINE =~ ^[0-9]+$ ]] || [ -z "$MATCH" ]; then
# line is not provided in grep pattern
LINE=0
fi
github_annotate_error "$FILE" "$LINE" "$MESSAGE"
fi
# We need to generate non GitHub annotations for this script to fail.
# Also, the pure annotate output is not very helpful on its own ;-)
echo "${INPUT}" | tab_indent | prepend "${1}:"

printf "%s:\n\t%s\n\n" "${MESSAGE}" "${INPUT}"
done
}


# Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL
# Handling specific behaviors/dependencies should by checking the content of:
# * `USEMODULE`
Expand Down Expand Up @@ -172,7 +159,7 @@ check_not_exporting_variables() {
# Only run if there are patterns, otherwise it matches everything
if [ ${#patterns[@]} -ne 0 ]; then
git -C "${RIOTBASE}" grep -n "${patterns[@]}" -- "${pathspec[@]}" \
| error_with_message 'Variables must only be exported in `makefiles/vars.inc.mk`'
| error_with_message "Variables must only be exported in \`makefiles/vars.inc.mk\`"
fi
}

Expand Down Expand Up @@ -201,9 +188,7 @@ check_board_do_not_include_cpu_features_dep() {
local patterns=()
local pathspec=()

# shellcheck disable=SC2016
# Single quotes are used to not expand expressions
patterns+=(-e 'include $(RIOTCPU)/.*/Makefile\..*')
patterns+=(-e "include \$(RIOTCPU)/.*/Makefile\..*")

pathspec+=('boards/')

Expand Down Expand Up @@ -287,14 +272,14 @@ check_files_in_boards_not_reference_board_var() {
local patterns=()
local pathspec=()

patterns+=(-e '/$(BOARD)/')
patterns+=(-e "/\$(BOARD)/")

pathspec+=('boards/')
# boards/common/nrf52 uses a hack to resolve dependencies early
pathspec+=(':!boards/common/nrf52/Makefile.include')

git -C "${RIOTBASE}" grep -n "${patterns[@]}" -- "${pathspec[@]}" \
| error_with_message 'Code in boards/ should not use $(BOARDS) to reference files since this breaks external BOARDS changing BOARDSDIR"'
| error_with_message "Code in boards/ should not use \$(BOARDS) to reference files since this breaks external BOARDS changing BOARDSDIR"
}

check_no_pseudomodules_in_makefile_dep() {
Expand Down Expand Up @@ -413,15 +398,10 @@ all_checks() {
check_tests_application_path
}

main() {
all_checks | prepend 'Invalid build system patterns found by '"${0}:" | error_on_input >&2
exit $?
}


if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
github_annotate_setup
main
all_checks | error_on_input
result="$?"
github_annotate_teardown
github_annotate_report_last_run
exit "${result}"
fi
Loading