sys-libs/compiler-rt: Support running built-in tests
authorMichał Górny <mgorny@gentoo.org>
Fri, 23 Dec 2016 10:51:42 +0000 (11:51 +0100)
committerMichał Górny <mgorny@gentoo.org>
Fri, 23 Dec 2016 10:53:16 +0000 (11:53 +0100)
sys-libs/compiler-rt/compiler-rt-9999.ebuild

index 75abf2dd6d221ef4eb355d239cc13de1a7caba18..a48b4738680e0e9ff4b353615e7e057f961c4dac 100644 (file)
@@ -20,12 +20,13 @@ EGIT_REPO_URI="http://llvm.org/git/compiler-rt.git
 LICENSE="|| ( UoI-NCSA MIT )"
 SLOT="0/${PV%.*}"
 KEYWORDS=""
-IUSE=""
+IUSE="test"
 
 RDEPEND="
        !<sys-devel/llvm-4.0"
 DEPEND="${RDEPEND}
        ~sys-devel/llvm-${PV}
+       test? ( ~sys-devel/clang-${PV} )
        ${PYTHON_DEPS}"
 
 test_compiler() {
@@ -64,6 +65,54 @@ src_configure() {
        cmake-utils_src_configure
 }
 
+src_test() {
+       # prepare a test compiler
+       local clang_version=4.0.0
+       local sys_dir=( "${EPREFIX}/usr/lib/clang/${clang_version}/lib"/* )
+       [[ -e ${sys_dir} ]] || die "Unable to find ${sys_dir}"
+       [[ ${#sys_dir[@]} -eq 1 ]] || die "Non-deterministic compiler-rt install: ${sys_dir[@]}"
+
+       # copy clang over since resource_dir is located relatively to binary
+       # therefore, we can put our new libraries in it
+       mkdir -p "${BUILD_DIR}"/{bin,$(get_libdir),lib/clang/"${clang_version}"/include} || die
+       cp "${EPREFIX}/usr/bin/clang" "${EPREFIX}/usr/bin/clang++" \
+               "${BUILD_DIR}"/bin/ || die
+       cp "${EPREFIX}/usr/lib/clang/${clang_version}/include"/*.h \
+               "${BUILD_DIR}/lib/clang/${clang_version}/include/" || die
+
+       # builtins are not converted to lit yet, so run them manually
+       local tests=() f
+       cd "${S}"/test/builtins/Unit || die
+       while read -r -d '' f; do
+               # ppc subdir is unmaintained and lacks proper guards
+               # (and ppc builtins do not seem to be used anyway)
+               [[ ${f} == ./ppc/* ]] && continue
+               # these are special
+               [[ ${f} == ./cpu_model_test.c ]] && continue
+               [[ ${f} == ./gcc_personality_test.c ]] && continue
+               # unsupported
+               [[ ${f} == ./trampoline_setup_test.c ]] && continue
+               tests+=( "${f%.c}" )
+       done < <(find -name '*.c' -print0)
+
+       {
+               echo "check: ${tests[*]/#/check-}" &&
+               echo ".PHONY: check ${tests[*]/#/check-}" &&
+               for f in "${tests[@]}"; do
+                       echo "check-${f}: ${f}" &&
+                       echo "  ${f}"
+               done
+       } > Makefile || die
+
+       # use -k to run all tests even if some fail
+       emake -k \
+               CC="${BUILD_DIR}/bin/clang" \
+               CFLAGS='' \
+               CPPFLAGS='-I../../../lib/builtins' \
+               LDFLAGS='-rtlib=compiler-rt' \
+               LDLIBS='-lm'
+}
+
 src_install() {
        cmake-utils_src_install