| 1 | #!/bin/bash -e |
| 2 | |
| 3 | # Copyright (c) 2014-2022, The Monero Project |
| 4 | # |
| 5 | # All rights reserved. |
| 6 | # |
| 7 | # Redistribution and use in source and binary forms, with or without modification, are |
| 8 | # permitted provided that the following conditions are met: |
| 9 | # |
| 10 | # 1. Redistributions of source code must retain the above copyright notice, this list of |
| 11 | # conditions and the following disclaimer. |
| 12 | # |
| 13 | # 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 14 | # of conditions and the following disclaimer in the documentation and/or other |
| 15 | # materials provided with the distribution. |
| 16 | # |
| 17 | # 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 18 | # used to endorse or promote products derived from this software without specific |
| 19 | # prior written permission. |
| 20 | # |
| 21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 22 | # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 23 | # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 24 | # THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 28 | # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 29 | # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | # Include What You Use analyses the complexity of your header hierarchy and proposes optimisations. |
| 32 | # User documentation: |
| 33 | # https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md |
| 34 | |
| 35 | # Build variables |
| 36 | PROG="include-what-you-use" |
| 37 | PROG_SHORT="iwyu" |
| 38 | DIR_BUILD="build/clang-$PROG_SHORT" |
| 39 | |
| 40 | RESULT="$PROG_SHORT-result.txt" |
| 41 | |
| 42 | if hash "$PROG"; then |
| 43 | echo "Found: $PROG" |
| 44 | else |
| 45 | echo "Couldn't find: $PROG" |
| 46 | echo "Please run the below command to install $PROG:" |
| 47 | echo "sudo apt install $PROG_SHORT" |
| 48 | exit 1 |
| 49 | fi |
| 50 | |
| 51 | mkdir -p "$DIR_BUILD" && cd "$DIR_BUILD" |
| 52 | rm `find . -name "CMakeCache.txt"` || true |
| 53 | |
| 54 | UWYU_COMMAND="$PROG;-Xiwyu;any;-Xiwyu;iwyu;-Xiwyu;args" # Copy-pasted from the user docs. |
| 55 | |
| 56 | cmake ../.. \ |
| 57 | -DCMAKE_C_COMPILER=clang \ |
| 58 | -DCMAKE_CXX_COMPILER=clang++ \ |
| 59 | -DUSE_CCACHE=ON \ |
| 60 | -DCMAKE_C_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ |
| 61 | -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \ |
| 62 | -DBUILD_SHARED_LIBS=ON \ |
| 63 | -DBUILD_TESTS=ON |
| 64 | |
| 65 | make clean # Clean up to generate the full report |
| 66 | time make -k 2>&1 | tee "$RESULT" # Run the scan. -k means: ignore errors |
| 67 | #time make -k easylogging 2>&1 | tee $RESULT # Quick testing: build a single target |
| 68 | KPI=$(cat "$RESULT" | wc -l) |
| 69 | tar -cJvf "$RESULT.txz" "$RESULT" # Zip the result, because it's huge. |
| 70 | rm -v "$RESULT" |
| 71 | |
| 72 | echo "" |
| 73 | echo "Readable result stored in: $DIR_BUILD/$RESULT.gz" |
| 74 | |
| 75 | echo "$KPI" > "kpis.txt" |