aboutsummaryrefslogtreecommitdiff
blob: e66824cee01b7657ce885951f68fc0d2dbb0c241 (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
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="Dfmt is a formatter for D source code"
HOMEPAGE="https://github.com/dlang-community/dfmt"

LIBDPARSE="fe6d1e38fb4fc04323170389cfec67ed7fd4e24a"
SRC_URI="
	https://github.com/dlang-community/dfmt/archive/v${PV}.tar.gz -> ${PN}-${PV}.tar.gz
	https://github.com/dlang-community/libdparse/archive/${LIBDPARSE}.tar.gz -> libdparse-${LIBDPARSE}.tar.gz
	"
LICENSE="Boost-1.0"

SLOT="0"
KEYWORDS="~amd64 ~arm64 ~x86"

DLANG_COMPAT=( dmd-2_{106..109} gdc-1{3,4} ldc2-1_{35..39} )

inherit dlang-single bash-completion-r1

REQUIRED_USE=${DLANG_REQUIRED_USE}
DEPEND=${DLANG_DEPS}
BDEPEND=${DLANG_DEPS}
RDEPEND=${DLANG_DEPS}

src_prepare() {
	mv -T "../libdparse-${LIBDPARSE}" libdparse || die "Couldn't move submodule libdparse"
	# Make a dummy folder to silence a find warning in the makefile
	mkdir -p stdx-allocator/source || die "Couldn't create dummy stdx-allocator directory"

	default

	mkdir bin || die "Failed to create 'bin' directory."
	echo "v${PV}" > bin/githash.txt
	touch githash

	# Use our user's flags + $(INCLUDE_PATHS) defined in the makefile
	export D_FLAGS="$(dlang_get_dmdw_dcflags) $(dlang_get_dmdw_ldflags) \$(INCLUDE_PATHS)"
	# Tests fail with -march=native and -O2 with <sys-devel/gcc-13.2.1_p20240330,
	# probably https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171 again.
	if [[ ${EDC} == gdc-13 && ${D_FLAGS} == *-march=native* ]]; then
		ewarn '-march=native has been removed from your flags.'
		ewarn 'See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114171'
		# Interestingly `-q,` is a valid gdmd flag.
		export D_FLAGS=${D_FLAGS//-march=native}
	fi
}

src_compile() {
	emake DC="$(dlang_get_dmdw)" DMD_FLAGS="${D_FLAGS}"
}

src_test() {
	# minimal workaround for https://github.com/dlang-community/dfmt/pull/600
	touch githash.d
	# Let the makefile add -unittest -g, keeps our code simpler
	emake bin/dfmt-test DC="$(dlang_get_dmdw)" DMD_COMMON_FLAGS="${D_FLAGS}"
	./bin/dfmt-test || die "Unittests failed"

	cd tests || die

	dlang_compile_bin "run_tests" "test.d"
	./run_tests || die "Tests failed"
}

src_install() {
	dobin bin/dfmt
	dodoc README.md LICENSE.txt
	dobashcomp bash-completion/completions/dfmt
}