summaryrefslogtreecommitdiff
path: root/dev-util/clang-extract/clang-extract-9999.ebuild
blob: 0c1d8f39cd8e8e0a7bece12976eae5b0a2391805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

LLVM_COMPAT=( {16..18} )
PYTHON_COMPAT=( python3_{10..13} )
inherit flag-o-matic llvm-r1 meson python-any-r1

DESCRIPTION="Tool to extract code content from source files"
HOMEPAGE="https://github.com/SUSE/clang-extract"

if [[ ${PV} == 9999 ]] ; then
	EGIT_REPO_URI="https://github.com/SUSE/clang-extract.git"
	inherit git-r3
else
	CLANG_EXTRACT_COMMIT="ec46efd739f15ee49f99834ba56c019cbf69e4ed"
	SRC_URI="
		https://github.com/SUSE/clang-extract/archive/${CLANG_EXTRACT_COMMIT}.tar.gz -> ${P}.gh.tar.gz
	"
	S="${WORKDIR}"/${PN}-${CLANG_EXTRACT_COMMIT}

	KEYWORDS="~amd64"
fi

LICENSE="UoI-NCSA"
SLOT="0"
IUSE="test"
RESTRICT="!test? ( test )"

DEPEND="
	app-arch/zstd:=
	sys-libs/zlib
	virtual/libelf
	$(llvm_gen_dep '
		llvm-core/clang:${LLVM_SLOT}
		llvm-core/llvm:${LLVM_SLOT}
	')
"
RDEPEND="${DEPEND}"
BDEPEND="
	$(llvm_gen_dep '
		llvm-core/clang:${LLVM_SLOT}
	')
	test? ( ${PYTHON_DEPS} )
"

PATCHES=(
	"${FILESDIR}"/${PN}-meson.patch
)

pkg_setup() {
	use test && python-any-r1_pkg_setup
	llvm-r1_pkg_setup
}

src_prepare() {
	default

	# There's no need to manually add --gcc-install-dir to Clang invocations;
	# we already have this setup properly via our Clang config files in
	# /etc/clang.
	sed -i -e '/add_project_argument.*gcc-install-dir/d' meson.build || die

	# Testsuite makes some (bad) assumptions about layout
	BUILD_DIR="${S}"/build
}

src_configure() {
	# Use whatever CC/CXX llvm-r1 found for us, as meson.build
	# asserts on GCC being used.
	export CC=clang
	export CXX=clang++
	export PKG_CONFIG_PATH="$(get_llvm_prefix)/$(get_libdir)/pkgconfig:${PKG_CONFIG_PATH}"
	# User flags may be expecting GCC
	strip-unsupported-flags

	meson_src_configure
}

src_test() {
	# These hacks are inspired by dev-util/clazy.
	#
	# clang-extract wants to be installed in the directory of the clang binary,
	# so it can find the llvm/clang via relative paths.
	#
	# Setup the directories and symlink the system include dir for that.
	local -x LLVM_ROOT="$(get_llvm_prefix)"
	local -x CLANG_ROOT="${LLVM_ROOT//llvm/clang}"

	mkdir -p "${BUILD_DIR}${CLANG_ROOT}" || die
	ln -s "${CLANG_ROOT}/include" "${BUILD_DIR}${CLANG_ROOT}/include" || die
	mkdir -p "${BUILD_DIR}${LLVM_ROOT}/bin" || die
	ln -s "${BUILD_DIR}"/clang-extract "${BUILD_DIR}${LLVM_ROOT}/bin" || die
	ln -s "${BUILD_DIR}"/ce-inline "${BUILD_DIR}${LLVM_ROOT}/bin" || die

	# Wrap runtest.py so we always pass -bin-path.
	#
	# This is gnarly but we already have to make sure it uses the
	# right Python, so it was quicker to just do the bash wrapper.
	mv testsuite/lib/runtest.py{,.real} || die
	cat <<-EOF > testsuite/lib/runtest.py || die
	#!/bin/bash
	export CLANG_NO_DEFAULT_CONFIG=1
	${EPYTHON} "${S}"/testsuite/lib/runtest.py.real \
		-bin-path "${BUILD_DIR}${LLVM_ROOT}/bin/" \
		"\$@"
	EOF
	chmod +x testsuite/lib/runtest.py || die

	local -x PATH="${BUILD_DIR}/${LLVM_ROOT}/bin:${BUILD_DIR}/bin:${PATH}"
	local -x LD_LIBRARY_PATH="${BUILD_DIR}/lib:${LD_LIBRARY_PATH}"

	meson_src_test
}