#!/bin/bash -e
# check_iwyu verifies that necessary includes are included directly, by using
# include-what-you-use and the iwyu.imp configuration file.

. "${BASH_SOURCE%/*}/common.sh"

check_iwyu_single () {
    [ "$TRAVIS" = true ] && return
    file=$1
    if [[ "$file" = *.c ]] ; then
        lang_flags=(--language=c -std=c11)
    else
        lang_flags=(--language=c++ -std=c++11)
    fi
    include-what-you-use -Xiwyu --mapping_file="$COMMONDIR/iwyu.imp" \
        "${CXXFLAGS[@]}" "${lang_flags[@]}" $file || [ $? -eq 2 ]
}

if in_main ; then
    driver check_iwyu_single :
fi
