1 # Copyright (C) 2017-2019 Free Software Foundation, Inc.
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.
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.
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/>.
18 # DejaGnu does not have proper library search paths for load_lib.
19 # We have to explicitly load everything that gdc.exp wants to load.
22 proc load_gcc_lib { filename } {
23 global srcdir loaded_libs
25 load_file $srcdir/../../gcc/testsuite/lib/$filename
26 set loaded_libs($filename) ""
32 load_gcc_lib target-supports.exp
33 load_gcc_lib target-supports-dg.exp
34 load_gcc_lib dg-options.exp
35 load_gcc_lib target-libpath.exp
36 load_gcc_lib timeout.exp
37 load_gcc_lib wrapper.exp
38 load_gcc_lib target-utils.exp
39 load_gcc_lib gcc-defs.exp
41 set TESTING_IN_BUILD_TREE 1
43 # Define libphobos callbacks for dg.exp.
45 proc libphobos-dg-test { prog do_what extra_tool_flags } {
49 # Set up the compiler flags, based on what we're going to do.
52 set compile_type "executable"
53 # FIXME: "./" is to cope with "." not being in $PATH.
54 # Should this be handled elsewhere?
56 set output_file "./[file rootname [file tail $prog]].exe"
57 # This is the only place where we care if an executable was
58 # created or not. If it was, dg.exp will try to run it.
59 catch { remote_file build delete $output_file }
62 set compile_type "executable"
63 set output_file "./[file rootname [file tail $prog]].exe"
66 perror "$do_what: not a valid dg-do keyword"
71 set select_compile "libphobos_target_compile"
73 if { $extra_tool_flags != "" } {
74 lappend options "additional_flags=$extra_tool_flags"
77 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options]
79 return [list $comp_output $output_file]
86 proc libphobos_init { args } {
88 global srcdir blddir objdir tool_root_dir
91 global gdcpaths gdcldflags
92 global gluefile wrap_flags
93 global ld_library_path
96 # If a testcase doesn't have special options, use these.
97 if ![info exists DEFAULT_DFLAGS] then {
101 # By default, we assume we want to run program images.
102 global dg-do-what-default
104 set dg-do-what-default "run"
106 set dg-do-what-default "link"
109 # What arguments to pass to run program images.
110 global libphobos_run_args
111 set libphobos_run_args ""
114 set blddir [lookfor_file [get_multilibs] libphobos]
115 set flags_file "${blddir}/testsuite/testsuite_flags"
116 set shlib_ext [get_shlib_extension]
118 set gdc [transform "gdc"]
119 set gdcflags "-fmessage-length=0"
120 set gdcpaths "-I${srcdir}"
123 if { [file exists $flags_file] } {
124 set gdc [exec sh $flags_file --gdc]
125 set gdcflags [exec sh $flags_file --gdcflags]
126 set gdcpaths [exec sh $flags_file --gdcpaths]
127 set gdcldflags [exec sh $flags_file --gdcldflags]
131 if [info exists env(EXEEXT)] {
132 set exeext $env(EXEEXT)
135 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
136 set ld_library_path ""
138 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
140 set gccdir [file dirname $gccdir]
141 append ld_library_path ":${gccdir}"
144 if { [file exists "${blddir}/libdruntime/.libs/libgdruntime.${shlib_ext}"] } {
145 append ld_library_path ":${blddir}/libdruntime/.libs"
148 if { [file exists "${blddir}/src/.libs/libgphobos.${shlib_ext}"] } {
149 append ld_library_path ":${blddir}/src/.libs"
152 set_ld_library_path_env_vars
154 libphobos_maybe_build_wrapper "${objdir}/testglue.o"
158 # libphobos_target_compile -- compile a source file.
161 proc libphobos_target_compile { source dest type options } {
163 global gdcpaths gdcldflags
164 global gluefile wrap_flags
166 lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never"
168 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
169 lappend options "libs=${gluefile}"
170 lappend options "ldflags=${wrap_flags}"
173 # Flag setting based on type argument.
174 if { $type == "executable" } {
175 # Link the support objects into executables.
176 lappend options "additional_flags=$gdcldflags"
179 # Set the compiler, only add D flags and paths if building D sources.
181 if [regexp ".*\.d\$" $source] {
182 set gdc_final [concat $gdc_final $gdcflags]
183 set gdc_final [concat $gdc_final $gdcpaths]
186 lappend options "compiler=$gdc_final"
187 lappend options "timeout=[timeout_value]"
189 set options [dg-additional-files-options $options $source]
190 set comp_output [target_compile $source $dest $type $options]