]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gdc.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / gdc.exp
1 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
16
17 #
18 # gdc support library routines
19 #
20
21 load_lib prune.exp
22 load_lib gcc-defs.exp
23 load_lib timeout.exp
24 load_lib target-libpath.exp
25
26 #
27 # GDC_UNDER_TEST is the compiler under test.
28 #
29
30 set gdc_compile_options ""
31
32
33 #
34 # gdc_version -- extract and print the version number of the compiler
35 #
36
37 proc gdc_version { } {
38 global GDC_UNDER_TEST
39
40 gdc_init
41
42 # ignore any arguments after the command
43 set compiler [lindex $GDC_UNDER_TEST 0]
44
45 # verify that the compiler exists
46 if { [is_remote host] || [which $compiler] != 0 } then {
47 set tmp [remote_exec host "$compiler -v"]
48 set status [lindex $tmp 0]
49 set output [lindex $tmp 1]
50 regexp " version \[^\n\r\]*" $output version
51 if { $status == 0 && [info exists version] } then {
52 if [is_remote host] {
53 clone_output "$compiler $version\n"
54 } else {
55 clone_output "[which $compiler] $version\n"
56 }
57 } else {
58 clone_output "Couldn't determine version of [which $compiler]\n"
59 }
60 } else {
61 # compiler does not exist (this should have already been detected)
62 warning "$compiler does not exist"
63 }
64 }
65
66 #
67 # gdc_include_flags -- include flags for the gcc tree structure
68 #
69
70 proc gdc_include_flags { paths } {
71 global srcdir
72 global GDC_INCLUDE_CXX_FLAGS
73 global TESTING_IN_BUILD_TREE
74
75 set flags ""
76
77 if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } {
78 return "${flags}"
79 }
80
81 if [info exists GDC_INCLUDE_CXX_FLAGS] {
82 set include_cxx_flags $GDC_INCLUDE_CXX_FLAGS
83 } else {
84 set include_cxx_flags 0
85 }
86
87 set gccpath ${paths}
88
89 if { $gccpath != "" } {
90 if [file exists "${gccpath}/libphobos/libdruntime"] {
91 append flags "-I${gccpath}/libphobos/libdruntime "
92 }
93 }
94 append flags "-I${srcdir}/../../libphobos/libdruntime "
95 append flags "-I${srcdir}/../../libphobos/src "
96
97 # For the tests that mix C++ and D, need to know where headers are located.
98 if $include_cxx_flags {
99 set odir [lookfor_file ${gccpath} libstdc++-v3]
100 if { ${odir} != "" && [file exists ${odir}/scripts/testsuite_flags] } {
101 set cxxflags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
102 set idx [lsearch $cxxflags "-nostdinc++"]
103 append flags [lreplace $cxxflags $idx $idx]
104 }
105 }
106
107 return "$flags"
108 }
109
110 #
111 # gdc_link_flags -- linker flags for the gcc tree structure
112 #
113
114 proc gdc_link_flags { paths } {
115 global srcdir
116 global ld_library_path
117 global GDC_UNDER_TEST
118 global GDC_INCLUDE_CXX_FLAGS
119 global shlib_ext
120 global SHARED_OPTION
121
122 set gccpath ${paths}
123 set libio_dir ""
124 set flags ""
125 set ld_library_path "."
126 set shlib_ext [get_shlib_extension]
127 set SHARED_OPTION ""
128 verbose "shared lib extension: $shlib_ext"
129
130 if [info exists GDC_INCLUDE_CXX_FLAGS] {
131 set include_cxx_flags $GDC_INCLUDE_CXX_FLAGS
132 } else {
133 set include_cxx_flags 0
134 }
135
136 if { $gccpath != "" } {
137 # Path to libgphobos.spec.
138 append flags "-B${gccpath}/libphobos/src "
139 # Path to drtbegin.o/drtend.o.
140 if { [file exists "${gccpath}/libphobos/libdruntime/gcc/drtbegin.o"] } {
141 append flags "-B${gccpath}/libphobos/libdruntime/gcc "
142 }
143
144 if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \
145 || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
146 append flags "-L${gccpath}/libphobos/src/.libs "
147 append ld_library_path ":${gccpath}/libphobos/src/.libs"
148 }
149 # Static linking is default. If only the shared lib is available adjust
150 # flags to always use it. If both are available, set SHARED_OPTION which
151 # will be added to PERMUTE_ARGS
152 if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
153 if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] } {
154 set SHARED_OPTION "-shared-libphobos"
155 } else {
156 append flags "-shared-libphobos "
157 }
158 }
159 if [file exists "${gccpath}/libiberty/libiberty.a"] {
160 append flags "-L${gccpath}/libiberty "
161 }
162 # For the tests that mix C++ and D, need to know where library is located.
163 if $include_cxx_flags {
164 if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
165 || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
166 append flags "-L${gccpath}/libstdc++-v3/src/.libs "
167 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
168 }
169 }
170 append ld_library_path [gcc-set-multilib-library-path $GDC_UNDER_TEST]
171 } else {
172 global tool_root_dir
173
174 set libphobos [lookfor_file ${tool_root_dir} libgphobos]
175 if { $libphobos != "" } {
176 append flags "-B${libphobos} -L${libphobos} "
177 append ld_library_path ":${libphobos}"
178 }
179 set libiberty [lookfor_file ${tool_root_dir} libiberty]
180 if { $libiberty != "" } {
181 append flags "-L${libiberty} "
182 }
183 if $include_cxx_flags {
184 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
185 if { $libstdcpp != "" } {
186 append flags "-L${libstdcpp} "
187 append ld_library_path ":${libstdcpp}"
188 }
189 }
190 }
191
192 set_ld_library_path_env_vars
193
194 return "$flags"
195 }
196
197 #
198 # gdc_init -- called at the start of each subdir of tests
199 #
200
201 proc gdc_init { args } {
202 global gdc_initialized
203 global base_dir
204 global tmpdir
205 global libdir
206 global gluefile wrap_flags
207 global TOOL_EXECUTABLE
208 global GDC_UNDER_TEST
209 global TESTING_IN_BUILD_TREE
210 global gcc_warning_prefix
211 global gcc_error_prefix
212
213 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
214 setenv LC_ALL C
215 setenv LANG C
216
217 if ![info exists GDC_UNDER_TEST] then {
218 if [info exists TOOL_EXECUTABLE] {
219 set GDC_UNDER_TEST $TOOL_EXECUTABLE
220 } else {
221 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
222 set GDC_UNDER_TEST [transform gdc]
223 } else {
224 set GDC_UNDER_TEST [findfile $base_dir/../../gdc "$base_dir/../../gdc -B$base_dir/../../" [findfile $base_dir/gdc "$base_dir/gdc -B$base_dir/" [transform gdc]]]
225 }
226 }
227 }
228
229 if ![is_remote host] {
230 if { [which $GDC_UNDER_TEST] == 0 } then {
231 perror "GDC_UNDER_TEST ($GDC_UNDER_TEST) does not exist"
232 exit 1
233 }
234 }
235 if ![info exists tmpdir] {
236 set tmpdir "/tmp"
237 }
238
239 if [info exists gluefile] {
240 unset gluefile
241 }
242
243 gdc_maybe_build_wrapper "${tmpdir}/d-testglue.o"
244
245 set gcc_warning_prefix "warning:"
246 set gcc_error_prefix "(fatal )?error:"
247
248 verbose "gdc is initialized" 3
249 }
250
251 #
252 # gdc_target_compile -- compile a source file
253 #
254
255 proc gdc_target_compile { source dest type options } {
256 global tmpdir
257 global gluefile wrap_flags
258 global GDC_UNDER_TEST
259 global TOOL_OPTIONS
260 global TEST_ALWAYS_FLAGS
261
262 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
263 lappend options "libs=${gluefile}"
264 lappend options "ldflags=${wrap_flags}"
265 }
266
267 set always_dflags ""
268
269 # TEST_ALWAYS_FLAGS are flags that should be passed to every
270 # compilation. They are passed first to allow individual
271 # tests to override them.
272 if [info exists TEST_ALWAYS_FLAGS] {
273 lappend always_dflags "additional_flags=$TEST_ALWAYS_FLAGS"
274 }
275
276 if ![is_remote host] {
277 if [info exists TOOL_OPTIONS] {
278 lappend always_dflags "additional_flags=[gdc_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
279 lappend always_dflags "ldflags=[gdc_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
280 } else {
281 lappend always_dflags "additional_flags=[gdc_include_flags [get_multilibs] ]"
282 lappend always_dflags "ldflags=[gdc_link_flags [get_multilibs] ]"
283 }
284 }
285
286 if [info exists TOOL_OPTIONS] {
287 lappend always_dflags "additional_flags=$TOOL_OPTIONS"
288 }
289
290 verbose "always_dflags set to: $always_dflags"
291
292 lappend options "timeout=[timeout_value]"
293 lappend options "compiler=$GDC_UNDER_TEST"
294
295 set options [concat "$always_dflags" $options]
296 set options [dg-additional-files-options $options $source]
297 return [target_compile $source $dest $type $options]
298 }