|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (C) 2018 Gaëtan Harter <gaetan.harter@fu-berlin.de> |
| 4 | +# |
| 5 | +# This file is subject to the terms and conditions of the GNU Lesser |
| 6 | +# General Public License v2.1. See the file LICENSE in the top level |
| 7 | +# directory for more details. |
| 8 | +# |
| 9 | + |
| 10 | +# |
| 11 | +# Central test script to have sanity checks for the build system |
| 12 | +# It is run unconditionally on all files. |
| 13 | +# |
| 14 | +# |
| 15 | + |
| 16 | +: "${RIOTBASE:="$(cd "$(dirname "$0")/../../../" || exit; pwd)"}" |
| 17 | + |
| 18 | +SCRIPT_PATH=dist/tools/buildsystem_sanity_check/check.sh |
| 19 | + |
| 20 | +# Modules should not check the content of FEATURES_PROVIDED/_REQUIRED/OPTIONAL |
| 21 | +# Handling specific behaviors/dependencies should by checking the content of: |
| 22 | +# * `USEMODULE` |
| 23 | +# * maybe `FEATURES_USED` if it is not a module (== not a periph_) |
| 24 | +check_not_parsing_features() { |
| 25 | + local patterns=() |
| 26 | + local pathspec=() |
| 27 | + |
| 28 | + patterns+=(-e 'if.*filter.*FEATURES_PROVIDED') |
| 29 | + patterns+=(-e 'if.*filter.*FEATURES_REQUIRED') |
| 30 | + patterns+=(-e 'if.*filter.*FEATURES_OPTIONAL') |
| 31 | + |
| 32 | + # Pathspec with exclude should start by an inclusive pathspec in git 2.7.4 |
| 33 | + pathspec+=('*') |
| 34 | + |
| 35 | + # Ignore this file when matching as it self matches |
| 36 | + pathspec+=(":!${SCRIPT_PATH}") |
| 37 | + |
| 38 | + # These two files contain sanity checks using FEATURES_ so are allowed |
| 39 | + pathspec+=(':!Makefile.include' ':!makefiles/info-global.inc.mk') |
| 40 | + |
| 41 | + git -C "${RIOTBASE}" grep "${patterns[@]}" -- "${pathspec[@]}" |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +main() { |
| 46 | + local errors='' |
| 47 | + |
| 48 | + errors+="$(check_not_parsing_features)" |
| 49 | + |
| 50 | + if [ -n "${errors}" ] |
| 51 | + then |
| 52 | + printf 'Invalid build system patterns found by %s:\n' "${0}" |
| 53 | + printf '%s\n' "${errors}" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + exit 0 |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then |
| 61 | + main |
| 62 | +fi |
0 commit comments