File: check-using-std.sh

package info (click to toggle)
herbstluftwm 0.9.5-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,164 kB
  • sloc: cpp: 20,691; python: 10,830; sh: 1,023; ansic: 622; makefile: 98
file content (38 lines) | stat: -rwxr-xr-x 1,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

###
# Searches the code for the use of "std::" prefixes in symbol reference that
# should be pulled into the namespace with "using std::…;".
#
# The list of symbols to enforce this for is assembled on-the-fly by looking
# for occurrences of "using std::…;"
###

set -o pipefail
set -o nounset

scriptdir=$(realpath "$(dirname "$0")")
reporoot=$(realpath "$scriptdir"/../)

# Assemble list of std symbols to pull in:
# (exclude some that are not enforced yet)
usethis=$(grep --no-filename 'using std::' "$reporoot/src/"*.cpp \
    | sed -r 's/^\s*using std::(.*);/\1/' \
    | sort -u \
    )

found_something=0
# set -x
for symbol in $usethis; do
    # Find offending occurrences of "std::" prefixes:
    grep -n --perl-regexp --color=auto '(?<!using )std::'"$symbol"'\b' src/*.cpp
    grepret=$?
    if [[ $grepret == 0 ]]; then
        found_something=1
    fi
done

if [[ $found_something != 0 ]]; then
    echo >&2 "Found redundant uses of std:: prefixes (see above)"
    exit 1
fi