Home | History | Annotate | Line # | Download | only in dist
apply-clang-tidy.sh revision 1.1.1.1.2.2
      1  1.1.1.1.2.2  martin #! /usr/bin/env bash
      2  1.1.1.1.2.2  martin #                          __  __            _
      3  1.1.1.1.2.2  martin #                       ___\ \/ /_ __   __ _| |_
      4  1.1.1.1.2.2  martin #                      / _ \\  /| '_ \ / _` | __|
      5  1.1.1.1.2.2  martin #                     |  __//  \| |_) | (_| | |_
      6  1.1.1.1.2.2  martin #                      \___/_/\_\ .__/ \__,_|\__|
      7  1.1.1.1.2.2  martin #                               |_| XML parser
      8  1.1.1.1.2.2  martin #
      9  1.1.1.1.2.2  martin # Copyright (c) 2024-2026 Sebastian Pipping <sebastian (at] pipping.org>
     10  1.1.1.1.2.2  martin # Licensed under the MIT license:
     11  1.1.1.1.2.2  martin #
     12  1.1.1.1.2.2  martin # Permission is  hereby granted,  free of charge,  to any  person obtaining
     13  1.1.1.1.2.2  martin # a  copy  of  this  software   and  associated  documentation  files  (the
     14  1.1.1.1.2.2  martin # "Software"),  to  deal in  the  Software  without restriction,  including
     15  1.1.1.1.2.2  martin # without  limitation the  rights  to use,  copy,  modify, merge,  publish,
     16  1.1.1.1.2.2  martin # distribute, sublicense, and/or sell copies of the Software, and to permit
     17  1.1.1.1.2.2  martin # persons  to whom  the Software  is  furnished to  do so,  subject to  the
     18  1.1.1.1.2.2  martin # following conditions:
     19  1.1.1.1.2.2  martin #
     20  1.1.1.1.2.2  martin # The above copyright  notice and this permission notice  shall be included
     21  1.1.1.1.2.2  martin # in all copies or substantial portions of the Software.
     22  1.1.1.1.2.2  martin #
     23  1.1.1.1.2.2  martin # THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
     24  1.1.1.1.2.2  martin # EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
     25  1.1.1.1.2.2  martin # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
     26  1.1.1.1.2.2  martin # NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
     27  1.1.1.1.2.2  martin # DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
     28  1.1.1.1.2.2  martin # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     29  1.1.1.1.2.2  martin # USE OR OTHER DEALINGS IN THE SOFTWARE.
     30  1.1.1.1.2.2  martin 
     31  1.1.1.1.2.2  martin set -e -u -o pipefail
     32  1.1.1.1.2.2  martin 
     33  1.1.1.1.2.2  martin cd "$(dirname "$(type -P "$0")")"
     34  1.1.1.1.2.2  martin 
     35  1.1.1.1.2.2  martin checks_to_enable=(
     36  1.1.1.1.2.2  martin     bugprone-narrowing-conversions
     37  1.1.1.1.2.2  martin     bugprone-suspicious-string-compare
     38  1.1.1.1.2.2  martin     misc-no-recursion
     39  1.1.1.1.2.2  martin     readability-avoid-const-params-in-decls
     40  1.1.1.1.2.2  martin     readability-named-parameter
     41  1.1.1.1.2.2  martin )
     42  1.1.1.1.2.2  martin checks_to_enable_flat="${checks_to_enable[*]}"  # i.e. flat string separated by spaces
     43  1.1.1.1.2.2  martin 
     44  1.1.1.1.2.2  martin checks_to_disable=(
     45  1.1.1.1.2.2  martin     # Would need a closer look before any adjustments
     46  1.1.1.1.2.2  martin     clang-analyzer-optin.performance.Padding
     47  1.1.1.1.2.2  martin 
     48  1.1.1.1.2.2  martin     # Used only in xmlwf, manually checked to be good enough for now
     49  1.1.1.1.2.2  martin     clang-analyzer-security.insecureAPI.strcpy
     50  1.1.1.1.2.2  martin )
     51  1.1.1.1.2.2  martin checks_to_disable_flat="${checks_to_disable[*]}"  # i.e. flat string separated by spaces
     52  1.1.1.1.2.2  martin 
     53  1.1.1.1.2.2  martin checks="${checks_to_enable_flat// /,},-${checks_to_disable_flat// /,-}"
     54  1.1.1.1.2.2  martin 
     55  1.1.1.1.2.2  martin args=(
     56  1.1.1.1.2.2  martin     --checks="${checks}"
     57  1.1.1.1.2.2  martin     --header-filter='.*'  # .. to display errors from all non-system headers
     58  1.1.1.1.2.2  martin     --warnings-as-errors=\*
     59  1.1.1.1.2.2  martin )
     60  1.1.1.1.2.2  martin 
     61  1.1.1.1.2.2  martin flags=(
     62  1.1.1.1.2.2  martin     -std=c99
     63  1.1.1.1.2.2  martin 
     64  1.1.1.1.2.2  martin     -Ilib/
     65  1.1.1.1.2.2  martin 
     66  1.1.1.1.2.2  martin     -DENCODING_FOR_FUZZING=UTF-8
     67  1.1.1.1.2.2  martin     -DXML_ATTR_INFO
     68  1.1.1.1.2.2  martin     -DXML_CLANG_TIDY
     69  1.1.1.1.2.2  martin     -DXML_DTD
     70  1.1.1.1.2.2  martin     -DXML_GE
     71  1.1.1.1.2.2  martin     -DXML_NS
     72  1.1.1.1.2.2  martin     -DXML_TESTING
     73  1.1.1.1.2.2  martin )
     74  1.1.1.1.2.2  martin 
     75  1.1.1.1.2.2  martin if [[ $# -gt 0 ]]; then
     76  1.1.1.1.2.2  martin     files=( "$@" )
     77  1.1.1.1.2.2  martin else
     78  1.1.1.1.2.2  martin     # For the list of excluded files please note:
     79  1.1.1.1.2.2  martin     # https://github.com/libexpat/libexpat/issues/119
     80  1.1.1.1.2.2  martin     files=( $(
     81  1.1.1.1.2.2  martin         git ls-files -- \*.c | grep -v \
     82  1.1.1.1.2.2  martin         -e '^lib/xcsinc\.c$' \
     83  1.1.1.1.2.2  martin         -e '^xmlwf/ct\.c$' \
     84  1.1.1.1.2.2  martin         -e '^xmlwf/xmlmime\.c$' \
     85  1.1.1.1.2.2  martin         -e '^xmlwf/win32filemap\.c$' \
     86  1.1.1.1.2.2  martin     ) )
     87  1.1.1.1.2.2  martin fi
     88  1.1.1.1.2.2  martin 
     89  1.1.1.1.2.2  martin set -x
     90  1.1.1.1.2.2  martin 
     91  1.1.1.1.2.2  martin type -P clang-tidy
     92  1.1.1.1.2.2  martin 
     93  1.1.1.1.2.2  martin clang-tidy --version
     94  1.1.1.1.2.2  martin 
     95  1.1.1.1.2.2  martin clang-tidy --checks="${checks}" --verify-config
     96  1.1.1.1.2.2  martin 
     97  1.1.1.1.2.2  martin clang-tidy --checks="${checks}" --list-checks
     98  1.1.1.1.2.2  martin 
     99  1.1.1.1.2.2  martin # These are the checks clang-tidy has *more* that so far we are missing out on,
    100  1.1.1.1.2.2  martin # for good and for bad
    101  1.1.1.1.2.2  martin clang-tidy --checks=\* --list-checks \
    102  1.1.1.1.2.2  martin     | grep -v -f <(clang-tidy --checks="${checks}" --list-checks | xargs -n1) \
    103  1.1.1.1.2.2  martin     | sed 's,\(\s*\)\([^-]\+\)-[^ ]\+,\1\2-*,' \
    104  1.1.1.1.2.2  martin     | sort -u \
    105  1.1.1.1.2.2  martin     | sed 's/^$/Disabled checks (simplified):/'
    106  1.1.1.1.2.2  martin 
    107  1.1.1.1.2.2  martin pwd
    108  1.1.1.1.2.2  martin 
    109  1.1.1.1.2.2  martin exec clang-tidy "${args[@]}" "${files[@]}" -- "${flags[@]}"
    110