File: run-iwyu.sh

package info (click to toggle)
cryfs 0.10.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 33,424 kB
  • sloc: cpp: 198,087; python: 9,581; sh: 8,060; asm: 5,120; makefile: 520; xml: 7
file content (33 lines) | stat: -rwxr-xr-x 1,061 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

# Note: Call this from a cmake build directory (e.g. cmake/) for out-of-source builds
# Examples:
# mkdir cmake && cd cmake && ../run-iwqu.sh
# mkdir cmake && cd cmake && ../run-iwqu.sh -fix

set -e

export NUMCORES=`nproc` && if [ ! -n "$NUMCORES" ]; then export NUMCORES=`sysctl -n hw.ncpu`; fi
echo Using ${NUMCORES} cores

# Run cmake in current working directory, but on source that is in the same directory as this script file
cmake -DBUILD_TESTING=on -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${0%/*}"

# Filter all third party code from the compilation database
cat compile_commands.json|jq "map(select(.file | test(\"^$(realpath ${0%/*})/(src|test)/.*$\")))" > compile_commands2.json
rm compile_commands.json
mv compile_commands2.json compile_commands.json

if [ "$1" = "-fix" ]; then
  TMPFILE=/tmp/iwyu.`cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8`.out

  function cleanup {
    rm ${TMPFILE}
  }
  trap cleanup EXIT

  iwyu_tool -j${NUMCORES} -p. ${@:2} | tee ${TMPFILE}
  fix_include < ${TMPFILE}
else
  iwyu_tool -j${NUMCORES} -p. $@
fi