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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
#!/bin/bash
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
gentooRepo=$(portageq get_repo_path / gentoo)
readonly gentooRepo
EAPI=8
source "${gentooRepo}"/eclass/tests/tests-common.sh || exit
TESTS_ECLASS_SEARCH_PATHS=( .. "${gentooRepo}"/eclass )
# Before the inherit so multilib.eclass picks the correct value
export CHOST=x86_my_whatever
inherit dlang-utils
test_var() {
local var=${1}
local impl=${2}
local expect=${3}
tbegin "${var} for ${impl}"
local ${var}
_dlang_export ${impl} ${var}
# We have variables with [] which breaks [[ == ]]
[ "${!var}" = "${expect}" ] || eerror "(${impl}: ${var}: '${!var}' != '${expect}'"
tend ${?}
}
test_is() {
local func=${1}
local expect=${2}
tbegin "${func} (expecting: ${expect})"
${func}
[[ ${?} == ${expect} ]]
tend ${?}
}
test_var EDC dmd-2_102 dmd-2.102
test_var EDC dmd-2.102 dmd-2.102
test_var EDC gdc-13 gdc-13
test_var EDC ldc2-1_35 ldc2-1.35
test_var DC dmd-2_102 "${EPREFIX}"/usr/lib/dmd/2.102/bin/dmd
test_var DC ldc2-1_36 "${EPREFIX}"/usr/lib/ldc2/1.36/bin/ldc2
test_var DC gdc-12 "${EPREFIX}"/usr/"${CHOST_default}"/gcc-bin/12/gdc
test_var DMDW dmd-2.102 "${EPREFIX}"/usr/lib/dmd/2.102/bin/dmd
test_var DMDW ldc2-1.36 "${EPREFIX}"/usr/lib/ldc2/1.36/bin/ldmd2
test_var DMDW gdc-12 "${EPREFIX}"/usr/"${CHOST_default}"/gcc-bin/12/gdmd
# DLANG_LIBDIR tested bellow
test_var DLANG_IMPORT_DIR dmd-2_102 "/usr/include/dlang"
test_var DLANG_IMPORT_DIR gdc-13 "/usr/include/dlang"
test_var DLANG_IMPORT_DIR ldc2-1_35 "/usr/include/dlang"
# DLANG_MODEL_FLAGS tested alongside DLANG_LIBDIR
DMDFLAGS=bar
GDCFLAGS=baz
LDCFLAGS=foo
test_var DCFLAGS dmd-2.102 "bar"
test_var DCFLAGS gdc-13 "baz"
test_var DCFLAGS ldc2-1_36 "foo"
DMDFLAGS='-O'
GDCFLAGS='-march=native'
LDCFLAGS='-flto'
test_var DMDW_DCFLAGS dmd-2.102 "-O"
test_var DMDW_DCFLAGS gdc-13 '-q,-march=native'
test_var DMDW_DCFLAGS ldc2-1_36 "-flto"
LDFLAGS='-Wl,-O1 -Xlinker --as-needed -garbage'
test_var DLANG_LDFLAGS dmd-2.102 "-L-O1 -L--as-needed -garbage"
test_var DLANG_LDFLAGS gdc-13 "${LDFLAGS} -shared-libphobos"
test_var DLANG_LDFLAGS ldc2-1_36 "-L-O1 -L--as-needed -garbage"
# Test multiple flags chained in -Wl,
LDFLAGS='-Wl,-z,pack-relative-relocs -Wl,a,b,c --flto'
test_var DLANG_LDFLAGS dmd-2.106 "-L-z -Lpack-relative-relocs -La -Lb -Lc --flto"
test_var DLANG_LDFLAGS gdc-13 "${LDFLAGS} -shared-libphobos"
test_var DLANG_LDFLAGS ldc2-1_36 "-L-z -Lpack-relative-relocs -La -Lb -Lc --flto"
LDFLAGS='-Wl,-O1 -Xlinker --as-needed -garbage'
test_var DLANG_DMDW_LDFLAGS dmd-2.106 "-L-O1 -L--as-needed -garbage"
test_var DLANG_DMDW_LDFLAGS gdc-13 "-L-O1 -L--as-needed -garbage -q,-shared-libphobos"
test_var DLANG_DMDW_LDFLAGS ldc2-1_35 "-L-O1 -L--as-needed -garbage"
test_var DLANG_LINKER_FLAG dmd-2.102 "-L"
test_var DLANG_LINKER_FLAG gdc-13 "-Wl,"
test_var DLANG_LINKER_FLAG ldc2-1_36 "-L"
test_var DLANG_OUTPUT_FLAG dmd-2.102 "-of"
test_var DLANG_OUTPUT_FLAG gdc-13 "-o"
test_var DLANG_OUTPUT_FLAG ldc2-1_36 "-of="
test_var DLANG_UNITTEST_FLAG dmd-2.102 "-unittest"
test_var DLANG_UNITTEST_FLAG gdc-13 "-funittest"
test_var DLANG_UNITTEST_FLAG ldc2-1_36 "-unittest"
test_var DLANG_VERSION_FLAG dmd-2.102 "-version"
test_var DLANG_VERSION_FLAG gdc-13 "-fversion"
test_var DLANG_VERSION_FLAG ldc2-1_36 "-d-version"
test_var DLANG_FE_VERSION dmd-2.102 2.102
test_var DLANG_FE_VERSION gdc-13 2.103
test_var DLANG_FE_VERSION ldc2-1_36 2.106
test_var DLANG_BE_VERSION dmd-2.102 2.102
test_var DLANG_BE_VERSION gdc-13 13
test_var DLANG_BE_VERSION ldc2-1_36 1.36
test_var DLANG_WNO_ERROR_FLAG dmd-2.102 -wi
test_var DLANG_WNO_ERROR_FLAG gdc-13 -Wno-error
test_var DLANG_WNO_ERROR_FLAG ldc2-1.36 --wi
test_var DLANG_SYSTEM_IMPORT_PATHS dmd-2.101 "${EPREFIX}/usr/lib/dmd/2.101/import"
test_var DLANG_SYSTEM_IMPORT_PATHS gdc-13 "${EPREFIX}/usr/lib/gcc/${CHOST_default}/13/include/d"
test_var DLANG_SYSTEM_IMPORT_PATHS ldc2-1_32 "${EPREFIX}/usr/lib/ldc2/1.32/include/d"
test_var DLANG_PKG_DEP dmd-2.102 "dev-lang/dmd:2.102="
test_var DLANG_PKG_DEP gdc-12 "sys-devel/gcc:12[d] dev-util/gdmd:12"
test_var DLANG_PKG_DEP ldc2-1.36 "dev-lang/ldc2:1.36="
declare -A DLANG_REQ_USE=(
[dmd]="flag1"
[gdc]="flag2"
[ldc2]="flag3(-)?"
)
test_var DLANG_PKG_DEP dmd-2.102 "dev-lang/dmd:2.102=[flag1]"
test_var DLANG_PKG_DEP gdc-12 "sys-devel/gcc:12[d,flag2] dev-util/gdmd:12"
test_var DLANG_PKG_DEP ldc2-1.36 "dev-lang/ldc2:1.36=[flag3(-)?]"
get_libdir() {
local libdir_var="LIBDIR_${ABI}"
echo "${!libdir_var}"
}
# multilib
MULTILIB_ABIS="amd64 x86"
DEFAULT_ABI=amd64
LIBDIR_amd64=lib64
LIBDIR_x86=lib
ABI=amd64
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib64"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/lib64"
test_var DLANG_MODEL_FLAG ldc2-1.35 '-m64'
ABI=x86
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib32"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12/32"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/lib32"
test_var DLANG_MODEL_FLAG ldc2-1.35 '-m32'
# nomultilib
MULTILIB_ABIS=amd64
DEFAULT_ABI=amd64
LIBDIR_amd64=lib64
ABI=amd64
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib64"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/lib64"
test_var DLANG_MODEL_FLAG ldc2-1.35 ''
LIBDIR_amd64=mylib
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib64"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/mylib"
MULTILIB_ABIS=x86
DEFAULT_ABI=x86
LIBDIR_x86=lib
ABI=x86
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/lib"
test_var DLANG_MODEL_FLAG ldc2-1.35 ''
LIBDIR_x86=mylib
test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/mylib"
MULTILIB_ABIS=arm64
DEFAULT_ABI=arm64
LIBDIR_arm64=lib64
ABI=arm64
#test_var DLANG_LIBDIR dmd-2.102 "lib/dmd/2.102/lib64"
test_var DLANG_LIBDIR gdc-12 "lib/gcc/${CHOST_default}/12"
test_var DLANG_LIBDIR ldc2-1.35 "lib/ldc2/1.35/lib64"
test_var DLANG_MODEL_FLAG ldc2-1.35 ''
assert_eq() {
local what=${1} expected=${2}
[[ ${what} != ${expected} ]] && die "'${what}' != '${expected}'"
}
# No $EDC set
assert_eq $(EDC= dlang_get_import_dir) "/usr/include/dlang"
tbegin '_dlang_compile_extra_flags'
imports="A B"
assert_eq "$(EDC=dmd-2.102 _dlang_compile_extra_flags)" "-IA -IB"
string_imports="c d"
assert_eq "$(EDC=dmd-2.102 _dlang_compile_extra_flags)" "-IA -IB -Jc -Jd"
versions="x yY"
assert_eq "$(EDC=dmd-2.102 _dlang_compile_extra_flags)" \
"-IA -IB -Jc -Jd -version=x -version=yY"
libs="bar baz"
assert_eq "$(EDC=dmd-2.102 _dlang_compile_extra_flags)" \
"-IA -IB -Jc -Jd -version=x -version=yY -L-lbar -L-lbaz"
assert_eq "$(EDC=gdc-12 _dlang_compile_extra_flags)" \
"-IA -IB -Jc -Jd -fversion=x -fversion=yY -Wl,-lbar -Wl,-lbaz"
assert_eq "$(EDC=ldc2-1.35 _dlang_compile_extra_flags)" \
"-I=A -I=B -J=c -J=d -d-version=x -d-version=yY -L-lbar -L-lbaz"
tend
tbegin "that _dlang_verify_patterns accepts frontend versions"
( _dlang_verify_patterns "2.100" "2.107" )
tend ${?}
tbegin "_dlang_impl_matches on frontend version"
_dlang_impl_matches "gdc-13" "2.103"
tend ${?}
# check _dlang_impl_matches behavior
einfo "Testing dlang_impl_matches"
eindent
test_is "_dlang_impl_matches gdc-13 2.103" 0
test_is "_dlang_impl_matches dmd-2_107 2.107" 0
test_is "_dlang_impl_matches ldc2-1_36 2.106" 0
set -f
test_is "_dlang_impl_matches gdc-13 gdc*" 0
test_is "_dlang_impl_matches dmd-2.103 gdc*" 1
test_is "_dlang_impl_matches gdc-13 dmd-2_103" 1
test_is "_dlang_impl_matches dmd-2.107 dmd-2.0*" 1
test_is "_dlang_impl_matches ldc2-1_34 ldc2*" 0
set +f
test_is "_dlang_impl_matches gdc-12 2.100" 0
test_is "_dlang_impl_matches gdc-12 2.086" 1
test_is "_dlang_impl_matches gdc-12 2.103" 1
test_is "_dlang_impl_matches dmd-2_107 2.107" 0
test_is "_dlang_impl_matches dmd-2_107 2.106" 1
test_is "_dlang_impl_matches dmd-2_107 2.103" 1
test_is "_dlang_impl_matches ldc2-1_36 2.107" 1
test_is "_dlang_impl_matches ldc2-1_36 2.103" 1
# Check for the oldest frontend version patterns
test_is "_dlang_impl_matches gdc-12 2.100" 0
test_is "_dlang_impl_matches dmd-2.101 2.101" 0
test_is "_dlang_impl_matches ldc2-1.32 2.102" 0
eoutdent
tbegin "simple dlang-filter-dflags"
EDC=dmd-2.105
DMDFLAGS='-O --color -mcpu=native'
dlang-filter-dflags "dmd*" "--col*"
[[ "${DMDFLAGS}" == "-O -mcpu=native" ]]
tend $?
tbegin "propagation of flag changes done by dlang-filter-dflags"
EDC=gdc-12
GDCFLAGS='-march=native -O2 -pipe'
_dlang_export "${EDC}" DCFLAGS DMDW_DCFLAGS
dlang-filter-dflags "gdc*" "-march=native"
[[ "${GDCFLAGS}" == "-O2 -pipe" ]] &&
[[ "${DCFLAGS}" == "-O2 -pipe" ]] &&
[[ "${DMDW_DCFLAGS}" == "-q,-O2 -q,-pipe" ]]
tend $?
tbegin "dlang_get_abi_bits"
assert_eq $(dlang_get_abi_bits x86) 32
assert_eq $(dlang_get_abi_bits amd64) 64
assert_eq $(dlang_get_abi_bits aarch64) ""
assert_eq $(ABI=x86 dlang_get_abi_bits) 32
tend
|