]> git.ipfire.org Git - thirdparty/gcc.git/blob - libphobos/testsuite/lib/libphobos.exp
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / libphobos / testsuite / lib / libphobos.exp
1 # Copyright (C) 2017-2018 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 # DejaGnu does not have proper library search paths for load_lib.
19 # We have to explicitly load everything that gdc.exp wants to load.
20 #
21
22 proc load_gcc_lib { filename } {
23 global srcdir loaded_libs
24
25 load_file $srcdir/../../gcc/testsuite/lib/$filename
26 set loaded_libs($filename) ""
27 }
28
29 load_lib dg.exp
30 load_lib libgloss.exp
31
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
40
41 set TESTING_IN_BUILD_TREE 1
42
43 # Define libphobos callbacks for dg.exp.
44
45 proc libphobos-dg-test { prog do_what extra_tool_flags } {
46 set compile_type ""
47 set output_file ""
48
49 # Set up the compiler flags, based on what we're going to do.
50 switch $do_what {
51 "run" {
52 set compile_type "executable"
53 # FIXME: "./" is to cope with "." not being in $PATH.
54 # Should this be handled elsewhere?
55 # YES.
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 }
60 }
61 "link" {
62 set compile_type "executable"
63 set output_file "./[file rootname [file tail $prog]].exe"
64 }
65 default {
66 perror "$do_what: not a valid dg-do keyword"
67 return ""
68 }
69 }
70
71 set select_compile "libphobos_target_compile"
72 set options ""
73 if { $extra_tool_flags != "" } {
74 lappend options "additional_flags=$extra_tool_flags"
75 }
76
77 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options]
78
79 return [list $comp_output $output_file]
80 }
81
82 #
83 # libphobos_init
84 #
85
86 proc libphobos_init { args } {
87 global env
88 global srcdir blddir objdir tool_root_dir
89 global exeext
90 global gdc gdcflags
91 global gdcpaths gdcldflags
92 global gluefile wrap_flags
93 global ld_library_path
94 global DEFAULT_DFLAGS
95
96 # If a testcase doesn't have special options, use these.
97 if ![info exists DEFAULT_DFLAGS] then {
98 set DEFAULT_DFLAGS ""
99 }
100
101 # By default, we assume we want to run program images.
102 global dg-do-what-default
103 if [isnative] {
104 set dg-do-what-default "run"
105 } else {
106 set dg-do-what-default "link"
107 }
108
109 # What arguments to pass to run program images.
110 global libphobos_run_args
111 set libphobos_run_args ""
112
113 # Default settings.
114 set blddir [lookfor_file [get_multilibs] libphobos]
115 set flags_file "${blddir}/testsuite/testsuite_flags"
116 set shlib_ext [get_shlib_extension]
117
118 set gdc [transform "gdc"]
119 set gdcflags "-fmessage-length=0"
120 set gdcpaths "-I${srcdir}"
121 set gdcldflags ""
122
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]
128 }
129
130 set exeext ""
131 if [info exists env(EXEEXT)] {
132 set exeext $env(EXEEXT)
133 }
134
135 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
136 set ld_library_path ""
137
138 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
139 if {$gccdir != ""} {
140 set gccdir [file dirname $gccdir]
141 append ld_library_path ":${gccdir}"
142 }
143
144 if { [file exists "${blddir}/libdruntime/.libs/libgdruntime.${shlib_ext}"] } {
145 append ld_library_path ":${blddir}/libdruntime/.libs"
146 }
147
148 if { [file exists "${blddir}/src/.libs/libgphobos.${shlib_ext}"] } {
149 append ld_library_path ":${blddir}/src/.libs"
150 }
151
152 set_ld_library_path_env_vars
153
154 libphobos_maybe_build_wrapper "${objdir}/testglue.o"
155 }
156
157 #
158 # libphobos_target_compile -- compile a source file.
159 #
160
161 proc libphobos_target_compile { source dest type options } {
162 global gdc gdcflags
163 global gdcpaths gdcldflags
164 global gluefile wrap_flags
165
166 lappend options "additional_flags=-fno-diagnostics-show-caret -fdiagnostics-color=never"
167
168 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
169 lappend options "libs=${gluefile}"
170 lappend options "ldflags=${wrap_flags}"
171 }
172
173 # Flag setting based on type argument.
174 if { $type == "executable" } {
175 # Link the support objects into executables.
176 lappend options "additional_flags=$gdcldflags"
177 }
178
179 # Set the compiler, only add D flags and paths if building D sources.
180 set gdc_final $gdc
181 if [regexp ".*\.d\$" $source] {
182 set gdc_final [concat $gdc_final $gdcflags]
183 set gdc_final [concat $gdc_final $gdcpaths]
184 }
185
186 lappend options "compiler=$gdc_final"
187 lappend options "timeout=[timeout_value]"
188
189 set options [dg-additional-files-options $options $source]
190 set comp_output [target_compile $source $dest $type $options]
191
192 return $comp_output
193 }