*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / sys-libs / compiler-rt-sanitizers / compiler-rt-sanitizers-10.0.0.9999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python{2_7,3_{6,7}} )
7 inherit check-reqs cmake-utils flag-o-matic llvm llvm.org \
8         multiprocessing python-any-r1
9
10 DESCRIPTION="Compiler runtime libraries for clang (sanitizers & xray)"
11 HOMEPAGE="https://llvm.org/"
12 LLVM_COMPONENTS=( compiler-rt )
13 LLVM_TEST_COMPONENTS=( llvm/lib/Testing/Support llvm/utils/unittest )
14 llvm.org_set_globals
15
16 LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
17 SLOT="$(ver_cut 1-3)"
18 KEYWORDS=""
19 IUSE="+clang +libfuzzer +profile +sanitize test +xray elibc_glibc"
20 # FIXME: libfuzzer does not enable all its necessary dependencies
21 REQUIRED_USE="libfuzzer? ( || ( sanitize xray ) )"
22 RESTRICT="!test? ( test ) !clang? ( test )"
23
24 CLANG_SLOT=${SLOT%%.*}
25 # llvm-6 for new lit options
26 DEPEND="
27         >=sys-devel/llvm-6"
28 BDEPEND="
29         clang? ( sys-devel/clang )
30         elibc_glibc? ( net-libs/libtirpc )
31         test? (
32                 !<sys-apps/sandbox-2.13
33                 $(python_gen_any_dep ">=dev-python/lit-5[\${PYTHON_USEDEP}]")
34                 =sys-devel/clang-${PV%_*}*:${CLANG_SLOT}
35                 sys-libs/compiler-rt:${SLOT} )
36         ${PYTHON_DEPS}"
37
38 # least intrusive of all
39 CMAKE_BUILD_TYPE=RelWithDebInfo
40
41 check_space() {
42         if use test; then
43                 local CHECKREQS_DISK_BUILD=11G
44                 check-reqs_pkg_pretend
45         fi
46 }
47
48 pkg_pretend() {
49         check_space
50 }
51
52 pkg_setup() {
53         check_space
54         llvm_pkg_setup
55         python-any-r1_pkg_setup
56 }
57
58 src_prepare() {
59         cmake-utils_src_prepare
60
61         if use test; then
62                 # remove tests that are (still) broken by new glibc
63                 # https://bugs.llvm.org/show_bug.cgi?id=36065
64                 if use elibc_glibc && has_version '>=sys-libs/glibc-2.25'; then
65                         rm test/lsan/TestCases/Linux/fork_and_leak.cpp || die
66                 fi
67         fi
68 }
69
70 src_configure() {
71         # pre-set since we need to pass it to cmake
72         BUILD_DIR=${WORKDIR}/compiler-rt_build
73
74         if use clang; then
75                 local -x CC=${CHOST}-clang
76                 local -x CXX=${CHOST}-clang++
77                 strip-unsupported-flags
78         fi
79
80         local mycmakeargs=(
81                 -DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${SLOT}"
82                 # use a build dir structure consistent with install
83                 # this makes it possible to easily deploy test-friendly clang
84                 -DCOMPILER_RT_OUTPUT_DIR="${BUILD_DIR}/lib/clang/${SLOT}"
85
86                 -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
87                 # builtins & crt installed by sys-libs/compiler-rt
88                 -DCOMPILER_RT_BUILD_BUILTINS=OFF
89                 -DCOMPILER_RT_BUILD_CRT=OFF
90                 -DCOMPILER_RT_BUILD_LIBFUZZER=$(usex libfuzzer)
91                 -DCOMPILER_RT_BUILD_PROFILE=$(usex profile)
92                 -DCOMPILER_RT_BUILD_SANITIZERS=$(usex sanitize)
93                 -DCOMPILER_RT_BUILD_XRAY=$(usex xray)
94         )
95         if use test; then
96                 mycmakeargs+=(
97                         -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
98                         -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
99                         -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
100
101                         # they are created during src_test()
102                         -DCOMPILER_RT_TEST_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang"
103                         -DCOMPILER_RT_TEST_CXX_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang++"
104                 )
105
106                 # same flags are passed for build & tests, so we need to strip
107                 # them down to a subset supported by clang
108                 CC=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang \
109                 CXX=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang++ \
110                 strip-unsupported-flags
111         fi
112
113         if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
114                 mycmakeargs+=(
115                         # disable use of SDK for the system itself
116                         -DDARWIN_macosx_CACHED_SYSROOT=/
117                 )
118         fi
119
120         cmake-utils_src_configure
121
122         if use test; then
123                 local sys_dir=( "${EPREFIX}"/usr/lib/clang/${SLOT}/lib/* )
124                 [[ -e ${sys_dir} ]] || die "Unable to find ${sys_dir}"
125                 [[ ${#sys_dir[@]} -eq 1 ]] || die "Non-deterministic compiler-rt install: ${sys_dir[*]}"
126
127                 # copy clang over since resource_dir is located relatively to binary
128                 # therefore, we can put our new libraries in it
129                 mkdir -p "${BUILD_DIR}"/lib/{llvm/${CLANG_SLOT}/{bin,$(get_libdir)},clang/${SLOT}/include} || die
130                 cp "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/bin/clang{,++} \
131                         "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/bin/ || die
132                 cp "${EPREFIX}"/usr/lib/clang/${SLOT}/include/*.h \
133                         "${BUILD_DIR}"/lib/clang/${SLOT}/include/ || die
134                 cp "${sys_dir}"/*builtins*.a \
135                         "${BUILD_DIR}/lib/clang/${SLOT}/lib/${sys_dir##*/}/" || die
136                 # we also need LLVMgold.so for gold-based tests
137                 if [[ -f ${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so ]]; then
138                         ln -s "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so \
139                                 "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/$(get_libdir)/ || die
140                 fi
141         fi
142 }
143
144 src_test() {
145         # respect TMPDIR!
146         local -x LIT_PRESERVES_TMP=1
147         # disable sandbox to have it stop clobbering LD_PRELOAD
148         local -x SANDBOX_ON=0
149         # wipe LD_PRELOAD to make ASAN happy
150         local -x LD_PRELOAD=
151
152         cmake-utils_src_make check-all
153 }