Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # It's intentional not to use `set -x`, because this script explicitly prints useful information |
| 4 | # and should not run in trace mode. |
| 5 | # It's intentional not to use `set -e`, because this script wants to check all headers |
| 6 | # (similar to running all test cases), instead of failing at the first error. |
| 7 | |
Davide Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame] | 8 | if [[ -n $DISABLE_HEADERS_CHECK ]]; then |
| 9 | echo 'Skipping headers check.' |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
Davide Pesavento | 2349e28 | 2020-03-24 14:28:03 -0400 | [diff] [blame^] | 13 | if has CentOS-8 $NODE_LABELS; then |
| 14 | export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig |
| 15 | fi |
| 16 | |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 17 | CXX=${CXX:-g++} |
Davide Pesavento | 1fd0024 | 2018-05-20 00:11:01 -0400 | [diff] [blame] | 18 | STD=-std=c++14 |
Davide Pesavento | 2349e28 | 2020-03-24 14:28:03 -0400 | [diff] [blame^] | 19 | CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx)" |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 20 | INCLUDEDIR="$(pkg-config --variable=includedir libndn-cxx)"/ndn-cxx |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 21 | |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 22 | echo "Using: $CXX $STD $CXXFLAGS" |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 23 | |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 24 | NCHECKED=0 |
| 25 | NERRORS=0 |
| 26 | while IFS= read -r -d '' H; do |
Davide Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame] | 27 | echo "Checking header ${H#${INCLUDEDIR}/}" |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 28 | "$CXX" -xc++ $STD $CXXFLAGS -c -o /dev/null "$H" |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 29 | [[ $? -eq 0 ]] || ((NERRORS++)) |
| 30 | ((NCHECKED++)) |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 31 | done < <(find "$INCLUDEDIR" -name '*.hpp' -type f -print0 2>/dev/null) |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 32 | |
| 33 | if [[ $NCHECKED -eq 0 ]]; then |
Davide Pesavento | 97242f7 | 2020-02-29 14:28:15 -0500 | [diff] [blame] | 34 | echo 'No headers found. Is ndn-cxx installed?' |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 35 | exit 1 |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 36 | else |
| 37 | echo "$NCHECKED headers checked." |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 38 | fi |
| 39 | |
| 40 | if [[ $NERRORS -gt 0 ]]; then |
Davide Pesavento | 2063952 | 2017-06-08 19:34:14 -0400 | [diff] [blame] | 41 | echo "$NERRORS headers could not be compiled." |
Junxiao Shi | 316ea71 | 2015-01-08 20:46:47 -0700 | [diff] [blame] | 42 | exit 1 |
| 43 | fi |