Commit 235c01b3 authored by Florian Fischer's avatar Florian Fischer
Browse files

initial commit

parents
Pipeline #49085 failed with stages
in 54 seconds
#!/usr/bin/env bash
set -euo pipefail
# Meson issue regarding iwyu integration: https://github.com/mesonbuild/meson/issues/2637
# Pretty fancy method to get reliable the absolute path of a shell
# script, *even if it is sourced*. Credits go to GreenFox on
# stackoverflow: http://stackoverflow.com/a/12197518/194894
pushd . > /dev/null
SCRIPTDIR="${BASH_SOURCE[0]}";
while([ -h "${SCRIPTDIR}" ]); do
cd "`dirname "${SCRIPTDIR}"`"
SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")";
done
cd "`dirname "${SCRIPTDIR}"`" > /dev/null
SCRIPTDIR="`pwd`";
popd > /dev/null
SOURCEDIR="${SCRIPTDIR}/../src"
set +u
if [[ -n "${MESON_BUILD_ROOT}" ]]; then
MESON_BUILD_ROOT_SET=true
else
MESON_BUILD_ROOT_SET=false
fi
set -u
if ! ${MESON_BUILD_ROOT_SET}; then
ROOTDIR=$(readlink -f "${SCRIPTDIR}/..")
make -C "${ROOTDIR}"
MESON_BUILD_ROOT="${ROOTDIR}/build"
exec ninja -C "${MESON_BUILD_ROOT}" iwyu
fi
readonly IWYU_LOG="${MESON_BUILD_ROOT}/iwyu.log"
NPROC=$(nproc)
for POSSIBLE_CMD in iwyu_tool iwyu-tool iwyu_tool.py; do
if command -v ${POSSIBLE_CMD} >/dev/null; then
IWYU_TOOL=${POSSIBLE_CMD}
break
fi
done
if [[ -z "${IWYU_TOOL}" ]]; then
echo "iwyu_tool not found"
exit 1
fi
${IWYU_TOOL} -p "${MESON_BUILD_ROOT}" --jobs "${NPROC}" "${SOURCEDIR}" -- \
-Xiwyu --mapping_file="${MESON_SOURCE_ROOT}/iwyu-mappings.imp" \
> "${IWYU_LOG}"
# Sadly, iwyu_tool.py does not (yet) return an non-zero exit value if
# there are include issues, so we have to check the output manually.
# See https://github.com/include-what-you-use/include-what-you-use/issues/790
# Also note that the output contains "error: nos uch file or
# directory: 'cc'" if ccache is used (which meson does by default if
# ccache is available).
# See https://github.com/include-what-you-use/include-what-you-use/issues/789
ERROR_STRINGS=()
ERROR_STRINGS+=("should add these lines:")
ERROR_STRINGS+=("fatal error:")
for ERROR_STRING in "${ERROR_STRINGS[@]}"; do
if grep -q "${ERROR_STRING}" "${IWYU_LOG}"; then
echo "IWYU found errors!"
cat "${IWYU_LOG}"
exit 1
fi
done
#!/usr/bin/env bash
set -euo pipefail
# Pretty fancy method to get reliable the absolute path of a shell
# script, *even if it is sourced*. Credits go to GreenFox on
# stackoverflow: http://stackoverflow.com/a/12197518/194894
pushd . > /dev/null
SCRIPTDIR="${BASH_SOURCE[0]}";
while([ -h "${SCRIPTDIR}" ]); do
cd "`dirname "${SCRIPTDIR}"`"
SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")";
done
cd "`dirname "${SCRIPTDIR}"`" > /dev/null
SCRIPTDIR="`pwd`";
popd > /dev/null
ROOTDIR=$(readlink -f "${SCRIPTDIR}/..")
# Safly call bash function from xargs
# https://stackoverflow.com/questions/11003418/calling-shell-functions-with-xargs/11003457#11003457
check_license() {
LICENSE_IDENTIFIER=".*SPDX-License-Identifier: LGPL-3.0-or-later"
COPYRIGHT_REGEX=".*Copyright\s.*[0-9]{4}\s.*\w.*"
SED_CMD="{N; N; /^${LICENSE_IDENTIFIER}\n${COPYRIGHT_REGEX}\n.+$/!{q1}}"
if ! head -3 "$1" | sed -En "${SED_CMD}" >/dev/null
then
echo "$1": missing or invalid license header
return 1
fi
}
export -f check_license
MAX_PROCS=$(nproc)
CHECKED_FILES_FILE=$(mktemp)
trap 'rm "${CHECKED_FILES_FILE}"' EXIT
cd "${ROOTDIR}"
find . \( -path '*/\.*' -o -path "./build*" -o -path "./test/3rd-party*" \) -prune -o \
-type f -regextype posix-extended -regex '.*\.(c|h|cpp)' -print0 |\
tee >"${CHECKED_FILES_FILE}" |\
xargs --null --max-args=1 --max-procs="${MAX_PROCS}" -I {} \
bash -c 'check_license "$@"' _ "{}"
FILE_COUNT=$(<"${CHECKED_FILES_FILE}" tr -cd '\0' | wc -c)
echo "Checked ${FILE_COUNT} files for license headers"
#!/usr/bin/env bash
set -euo pipefail
# Pretty fancy method to get reliable the absolute path of a shell
# script, *even if it is sourced*. Credits go to GreenFox on
# stackoverflow: http://stackoverflow.com/a/12197518/194894
pushd . > /dev/null
SCRIPTDIR="${BASH_SOURCE[0]}";
while([ -h "${SCRIPTDIR}" ]); do
cd "`dirname "${SCRIPTDIR}"`"
SCRIPTDIR="$(readlink "`basename "${SCRIPTDIR}"`")";
done
cd "`dirname "${SCRIPTDIR}"`" > /dev/null
SCRIPTDIR="`pwd`";
popd > /dev/null
QUIET=false
while getopts :dq OPT; do
case $OPT in
d)
set -x
;;
q)
QUIET=true
;;
*)
echo "usage: ${0##*/} [-dq} [--] ARGS..."
exit 2
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1
ROOTDIR=$(readlink -f "${SCRIPTDIR}/..")
set +u
if [[ ! ${BUILDTYPE} ]]; then
BUILDTYPE="debugoptimized"
echo "BUILDTYPE not explicitly set via environment variable, defaulting to ${BUILDTYPE}"
fi
if [[ ! ${BUILDDIR} ]]; then
BUILDDIR="build-${BUILDTYPE}"
fi
set -u
readonly ABSOLUTE_BUILDDIR="${ROOTDIR}/${BUILDDIR}"
readonly ABSOLUTE_BUILDDIR_SYMLINK="${ROOTDIR}/build"
if [[ ! -d "${ABSOLUTE_BUILDDIR}" ]]; then
mkdir "${ABSOLUTE_BUILDDIR}"
fi
if [[ ! -d "${ABSOLUTE_BUILDDIR_SYMLINK}"
|| $(realpath "${ABSOLUTE_BUILDDIR}") != $(realpath "${ABSOLUTE_BUILDDIR_SYMLINK}") ]]; then
if [[ -e "${ABSOLUTE_BUILDDIR_SYMLINK}" ]]; then
if [[ ! -L "${ABSOLUTE_BUILDDIR_SYMLINK}" ]]; then
echo "${ABSOLUTE_BUILDDIR_SYMLINK} is not a symlink"
exit 1
fi
rm "${ABSOLUTE_BUILDDIR_SYMLINK}"
fi
ln -rs "${ABSOLUTE_BUILDDIR}" "${ABSOLUTE_BUILDDIR_SYMLINK}"
fi
# Now filter the environment variables for speedymalloc configuration
# arguments.
readonly VARIABLE_PREFIX="EMPER_ECHO_SERVER_"
MESON_ARGS=()
for var in $(compgen -e); do
if [[ ${var} != ${VARIABLE_PREFIX}* ]]; then
continue;
fi
# Strip the variable prefix from the build option environment variable.
MESON_BUILD_OPTION_NAME="${var#${VARIABLE_PREFIX}}"
# Lowercase the build option name.
MESON_BUILD_OPTION_NAME="${MESON_BUILD_OPTION_NAME,,}"
MESON_BUILD_OPTION_VALUE="${!var}"
if [[ -z $MESON_BUILD_OPTION_VALUE ]]; then
echo "Environment variable ${var} is empty"
exit 1
fi
MESON_ARGS+=("-D${MESON_BUILD_OPTION_NAME}=${MESON_BUILD_OPTION_VALUE}")
done
if ! $QUIET; then
set -x
fi
exec meson --buildtype=${BUILDTYPE} \
${MESON_ARGS[@]} \
"${ABSOLUTE_BUILDDIR}"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment