2019-05-18 08:09:12 -04:00
|
|
|
#! /usr/bin/env bash
|
2017-05-06 17:51:42 -04:00
|
|
|
# Copyright (C) Sebastian Pipping <sebastian@pipping.org>
|
|
|
|
# Licensed under the MIT license
|
|
|
|
|
|
|
|
export PS4='# '
|
|
|
|
|
|
|
|
|
|
|
|
_get_source_dir() {
|
|
|
|
echo "source__${version}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_get_build_dir() {
|
2017-06-14 12:31:05 -04:00
|
|
|
local libbsd_part=
|
|
|
|
if ${with_libbsd}; then
|
|
|
|
libbsd_part=__libbsd
|
|
|
|
fi
|
|
|
|
|
2017-06-14 16:41:44 -04:00
|
|
|
local mingw_part=
|
|
|
|
if ${with_mingw}; then
|
|
|
|
mingw_part=__windows
|
|
|
|
fi
|
|
|
|
|
2017-08-03 15:11:37 -04:00
|
|
|
local char_part=
|
|
|
|
if ${with_unsigned_char}; then
|
|
|
|
char_part=__unsigned_char
|
|
|
|
fi
|
|
|
|
|
2019-10-07 16:31:51 -04:00
|
|
|
local xml_attr_part=
|
|
|
|
if ${xml_attr_info_enabled}; then
|
|
|
|
xml_attr_part=__attr_info
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "build__${version}__unicode_${unicode_enabled}__xml_context_${xml_context}${libbsd_part}${mingw_part}${char_part}${xml_attr_part}"
|
2017-05-06 17:51:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_get_coverage_dir() {
|
|
|
|
echo "coverage__${version}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-06 15:28:06 -04:00
|
|
|
_call_cmake() {
|
|
|
|
local cmake_args=()
|
2017-05-06 17:51:42 -04:00
|
|
|
|
|
|
|
${unicode_enabled} \
|
2019-10-06 15:28:06 -04:00
|
|
|
&& cmake_args+=( -DEXPAT_CHAR_TYPE=wchar_t )
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2019-07-03 16:50:44 -04:00
|
|
|
${xml_attr_info_enabled} \
|
2019-10-06 15:28:06 -04:00
|
|
|
&& cmake_args+=( -DEXPAT_ATTR_INFO=ON )
|
2019-06-19 05:30:47 -04:00
|
|
|
|
2017-05-06 17:51:42 -04:00
|
|
|
if [[ ${xml_context} -eq 0 ]]; then
|
2019-10-06 15:28:06 -04:00
|
|
|
cmake_args+=( -DEXPAT_CONTEXT_BYTES=OFF )
|
2017-05-06 17:51:42 -04:00
|
|
|
else
|
2019-10-06 15:28:06 -04:00
|
|
|
cmake_args+=( -DEXPAT_CONTEXT_BYTES=${xml_context} )
|
2017-05-06 17:51:42 -04:00
|
|
|
fi
|
|
|
|
|
2019-10-06 15:28:06 -04:00
|
|
|
${with_libbsd} && cmake_args+=( -DEXPAT_WITH_LIBBSD=ON )
|
|
|
|
${with_mingw} && cmake_args+=( -DCMAKE_TOOLCHAIN_FILE="${abs_source_dir}"/cmake/mingw-toolchain.cmake )
|
2017-06-14 12:31:05 -04:00
|
|
|
|
2017-05-06 17:51:42 -04:00
|
|
|
(
|
|
|
|
set -x
|
2019-10-06 15:28:06 -04:00
|
|
|
cmake "${cmake_args[@]}" "$@" . &>> cmake.log
|
2017-05-06 17:51:42 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_copy_to() {
|
|
|
|
local target_dir="$1"
|
|
|
|
[[ -d "${target_dir}" ]] && return 0
|
|
|
|
|
|
|
|
mkdir "${target_dir}"
|
|
|
|
git archive --format=tar "${version}" | ( cd "${target_dir}" && tar x )
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-14 16:41:44 -04:00
|
|
|
_copy_missing_mingw_libaries() {
|
|
|
|
# These extra files are copied because
|
2017-06-24 10:11:09 -04:00
|
|
|
# * coverage GCC flags make them needed
|
|
|
|
# * With WINEDLLPATH Wine looks for .dll.so in these folders, not .dll
|
2017-06-14 16:41:44 -04:00
|
|
|
local target="$1"
|
2017-06-27 17:09:18 -04:00
|
|
|
local mingw_gcc_dll_dir="$(dirname "$(ls -1 /usr/lib*/gcc/i686-w64-mingw32/*/libgcc_s_sjlj-1.dll | head -n1)")"
|
2017-06-14 16:41:44 -04:00
|
|
|
for dll in libgcc_s_sjlj-1.dll libstdc++-6.dll; do
|
|
|
|
(
|
|
|
|
set -x
|
2017-06-27 17:09:18 -04:00
|
|
|
ln -s "${mingw_gcc_dll_dir}"/${dll} "${target}"/${dll}
|
|
|
|
)
|
|
|
|
done
|
|
|
|
|
2019-10-06 15:26:09 -04:00
|
|
|
local mingw_pthread_dll="$(ls -1 /usr/i686-w64-mingw32/lib*/libwinpthread-1.dll 2>/dev/null | head -n1)"
|
|
|
|
if [[ -n ${mingw_pthread_dll} ]]; then
|
|
|
|
local mingw_pthread_dll_dir="$(dirname "${mingw_pthread_dll}")"
|
|
|
|
for dll in libwinpthread-1.dll; do
|
|
|
|
source="${mingw_pthread_dll_dir}"/${dll}
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
ln -s "${source}" "${target}"/${dll}
|
|
|
|
)
|
|
|
|
done
|
|
|
|
fi
|
2019-10-06 15:26:47 -04:00
|
|
|
|
|
|
|
for dll in libexpat.dll; do
|
|
|
|
(
|
|
|
|
set -x
|
|
|
|
ln -s "${abs_build_dir}"/${dll} "${target}"/${dll}
|
|
|
|
)
|
|
|
|
done
|
2017-06-14 16:41:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-06 17:51:42 -04:00
|
|
|
_run() {
|
|
|
|
local source_dir="$1"
|
|
|
|
local build_dir="$2"
|
2019-10-06 15:26:47 -04:00
|
|
|
local abs_source_dir="${PWD}/${source_dir}"
|
|
|
|
local abs_build_dir="${PWD}/${build_dir}"
|
2019-10-06 15:28:06 -04:00
|
|
|
local capture_dir=.
|
2017-05-06 17:51:42 -04:00
|
|
|
|
|
|
|
local BASE_FLAGS='-pipe -Wall -Wextra -pedantic -Wno-overlength-strings'
|
|
|
|
BASE_FLAGS+=' --coverage --no-inline'
|
|
|
|
|
2017-08-03 15:11:37 -04:00
|
|
|
${with_unsigned_char} && BASE_FLAGS="${BASE_FLAGS} -funsigned-char"
|
|
|
|
|
2017-07-05 16:49:51 -04:00
|
|
|
local CFLAGS="-std=c99 ${BASE_FLAGS}"
|
2017-05-06 17:51:42 -04:00
|
|
|
local CXXFLAGS="-std=c++98 ${BASE_FLAGS}"
|
|
|
|
|
|
|
|
(
|
|
|
|
set -e
|
|
|
|
cd "${build_dir}"
|
|
|
|
|
2019-10-06 15:28:06 -04:00
|
|
|
_call_cmake \
|
|
|
|
-DCMAKE_C_FLAGS="${CFLAGS}" \
|
|
|
|
-DCMAKE_CXX_FLAGS="${CXXFLAGS}"
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-06-14 16:41:44 -04:00
|
|
|
(
|
|
|
|
set -x
|
2019-10-06 15:28:06 -04:00
|
|
|
make &> build.log
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-06-14 16:41:44 -04:00
|
|
|
lcov -c -d "${capture_dir}" -i -o "${coverage_info}-zero" &> run.log
|
|
|
|
)
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-06-14 16:41:44 -04:00
|
|
|
if ${with_mingw}; then
|
2019-10-06 15:28:06 -04:00
|
|
|
for d in tests xmlwf ; do
|
2017-09-09 12:12:08 -04:00
|
|
|
mkdir -p "${d}"
|
|
|
|
_copy_missing_mingw_libaries "${d}"
|
|
|
|
done
|
2017-06-14 16:41:44 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
set -x
|
2019-10-06 15:28:06 -04:00
|
|
|
make CTEST_OUTPUT_ON_FAILURE=1 test run-xmltest
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-05-08 14:19:43 -04:00
|
|
|
lcov -c -d "${capture_dir}" -o "${coverage_info}-test" &>> run.log
|
2017-05-06 17:51:42 -04:00
|
|
|
lcov \
|
|
|
|
-a "${coverage_info}-zero" \
|
|
|
|
-a "${coverage_info}-test" \
|
2017-05-08 14:19:43 -04:00
|
|
|
-o "${coverage_info}-all" \
|
|
|
|
&>> run.log
|
2017-05-06 17:51:42 -04:00
|
|
|
|
|
|
|
# Make sure that files overlap in report despite different build folders
|
|
|
|
sed "/SF:/ s,${build_dir}/,${source_dir}/," "${coverage_info}-all" > "${coverage_info}"
|
2017-05-08 14:20:28 -04:00
|
|
|
) |& sed 's,^, ,'
|
2017-06-13 17:02:32 -04:00
|
|
|
res=${PIPESTATUS[0]}
|
2017-05-06 17:51:42 -04:00
|
|
|
|
|
|
|
if [[ ${res} -eq 0 ]]; then
|
|
|
|
echo PASSED
|
|
|
|
else
|
|
|
|
echo FAILED >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_merge_coverage_info() {
|
|
|
|
local coverage_dir="$1"
|
|
|
|
shift
|
|
|
|
local build_dirs=( "$@" )
|
|
|
|
|
|
|
|
mkdir -p "${coverage_dir}"
|
|
|
|
(
|
2019-10-07 17:24:57 -04:00
|
|
|
local lcov_merge_args=( -q )
|
2017-05-06 17:51:42 -04:00
|
|
|
for build_dir in "${build_dirs[@]}"; do
|
|
|
|
lcov_merge_args+=( -a "${build_dir}/${coverage_info}" )
|
|
|
|
done
|
|
|
|
lcov_merge_args+=( -o "${coverage_dir}/${coverage_info}" )
|
|
|
|
|
|
|
|
set -x
|
|
|
|
lcov "${lcov_merge_args[@]}"
|
2019-10-07 17:24:57 -04:00
|
|
|
) |& tee "${coverage_dir}/merge.log"
|
2017-05-06 17:51:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_render_html_report() {
|
|
|
|
local coverage_dir="$1"
|
2019-10-07 17:24:57 -04:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
genhtml -o "${coverage_dir}" "${coverage_dir}/${coverage_info}" &> "${coverage_dir}/render.log"
|
|
|
|
)
|
2017-05-06 17:51:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_show_summary() {
|
|
|
|
local coverage_dir="$1"
|
2019-10-07 17:24:57 -04:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
lcov -q -l "${coverage_dir}/${coverage_info}"
|
|
|
|
) | grep -v '^\['
|
2017-05-06 17:51:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_main() {
|
|
|
|
version="$(git describe --tags)"
|
|
|
|
coverage_info=coverage.info
|
|
|
|
|
|
|
|
local build_dirs=()
|
|
|
|
local source_dir="$(_get_source_dir)"
|
|
|
|
local coverage_dir="$(_get_coverage_dir)"
|
|
|
|
|
|
|
|
_copy_to "${source_dir}"
|
|
|
|
|
2017-06-14 12:07:47 -04:00
|
|
|
_build_case() {
|
|
|
|
local build_dir="$(_get_build_dir)"
|
|
|
|
|
|
|
|
echo "[${build_dir}]"
|
|
|
|
_copy_to "${build_dir}"
|
2019-10-06 15:28:06 -04:00
|
|
|
|
2019-10-06 15:48:51 -04:00
|
|
|
# Make sure we don't need to download xmlts.zip over and over again
|
|
|
|
if [[ ${#build_dirs[*]} -gt 0 ]]; then
|
|
|
|
ln -s "$PWD/${build_dirs[0]}/tests/xmlts.zip" "${build_dir}"/tests/
|
|
|
|
fi
|
|
|
|
|
2017-06-14 12:07:47 -04:00
|
|
|
_run "${source_dir}" "${build_dir}"
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-06-14 12:07:47 -04:00
|
|
|
build_dirs+=( "${build_dir}" )
|
|
|
|
}
|
2017-05-06 17:51:42 -04:00
|
|
|
|
2017-06-14 12:31:05 -04:00
|
|
|
# All combinations:
|
2017-08-03 15:11:37 -04:00
|
|
|
with_unsigned_char=false
|
2017-06-14 12:31:05 -04:00
|
|
|
with_libbsd=false
|
2017-06-14 16:41:44 -04:00
|
|
|
for with_mingw in true false ; do
|
2017-09-09 12:56:26 -04:00
|
|
|
for unicode_enabled in true false ; do
|
|
|
|
if ${unicode_enabled} && ! ${with_mingw} ; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-07-03 16:39:50 -04:00
|
|
|
for xml_attr_info_enabled in true false ; do
|
2019-06-19 05:30:47 -04:00
|
|
|
for xml_context in 0 1024 ; do
|
|
|
|
_build_case
|
|
|
|
done
|
2017-06-14 16:41:44 -04:00
|
|
|
done
|
2017-05-06 17:51:42 -04:00
|
|
|
done
|
|
|
|
done
|
|
|
|
|
2017-06-14 12:31:05 -04:00
|
|
|
# Single cases:
|
|
|
|
with_libbsd=true _build_case
|
2017-08-03 15:11:37 -04:00
|
|
|
with_unsigned_char=true _build_case
|
2017-06-14 12:31:05 -04:00
|
|
|
|
2017-05-06 17:51:42 -04:00
|
|
|
echo
|
|
|
|
echo 'Merging coverage files...'
|
|
|
|
_merge_coverage_info "${coverage_dir}" "${build_dirs[@]}"
|
|
|
|
|
|
|
|
echo 'Rendering HTML report...'
|
|
|
|
_render_html_report "${coverage_dir}"
|
|
|
|
echo "--> ${coverage_dir}/index.html"
|
|
|
|
|
|
|
|
echo
|
2019-10-07 17:24:57 -04:00
|
|
|
echo 'Rendering ASCII report...'
|
2017-05-06 17:51:42 -04:00
|
|
|
_show_summary "${coverage_dir}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_main
|