#!/bin/bash
# Wrapper around the opensource clang meant to work around various path or library
# issues occurring when one tries to substitute Apple's version of clang with
# a different version.
# The wrapper tries to mitigate version discrepancies in clang's fatal warnings.

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

CLANG_COMPILER="${SCRIPT_DIR}/../../../../facebook-clang-plugin/clang/bin/clang"

if [ "${0%++}" != "$0" ]; then XX="++"; else XX=""; fi

COMMAND=("${CLANG_COMPILER}${XX}")

# Remove command line options not supported by the opensource compiler or the plugins.
for X in "$@"
do
    if [ "$X" != "-fapplication-extension" ] && [ "$X" != "-fmodules" ]
    then
        COMMAND+=("$X")
    fi
done

# Never error on warnings. Clang is often more strict than Apple's version.
# These arguments are appended to override previous opposite settings.
COMMAND+=(-Wno-error -Qunused-arguments)

"${COMMAND[@]}"