]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/lib/plugin-support.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / plugin-support.exp
CommitLineData
99dee823 1# Copyright (C) 2009-2021 Free Software Foundation, Inc.
8ba50c2c
LCW
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# This file contains the support procedures for testing the plugin mechanism.
19
20load_lib dg.exp
21load_lib gcc.exp
22
23#
24# plugin-get-options -- process test directives
25#
26# SRC is the full pathname of the plugin source file.
27#
28proc plugin-get-options { src } {
29 # dg-options sets a variable called dg-extra-tool-flags.
30 set dg-extra-tool-flags ""
31
32 # dg-require-* sets dg-do-what.
33 upvar dg-do-what dg-do-what
34
35 set tmp [dg-get-options $src]
36 foreach op $tmp {
37 set cmd [lindex $op 0]
38 if { ![string compare "dg-options" $cmd] } {
39 set status [catch "$op" errmsg]
40 if { $status != 0 } {
41 perror "src: $errmsg for \"$op\"\n"
42 unresolved "$src: $errmsg for \"$op\""
43 return
44 }
45 } else {
46 # Ignore unrecognized dg- commands, but warn about them.
47 warning "plugin.exp does not support $cmd"
48 }
49 }
50
51 # Return flags to use for compiling the plugin source file
52 return ${dg-extra-tool-flags}
53}
54
55#
56# plugin-test-execute -- build the plugin first and then compile the
57# test files with the plugin.
58#
59# PLUGIN_SRC is the full pathname of the plugin source file.
60# PLUGIN_TESTS is a list of input test source files.
61#
62proc plugin-test-execute { plugin_src plugin_tests } {
63 global srcdir objdir
64 global verbose
65 global GMPINC
eeb971c9
EB
66 global PLUGINCC
67 global PLUGINCFLAGS
8ba50c2c
LCW
68
69 set basename [file tail $plugin_src]
70 set base [file rootname $basename]
71 set plugin_lib $base.so
72
3be74079
RO
73 set testcase [dg-trim-dirname $srcdir $plugin_src]
74 verbose "Test the plugin $testcase" 1
8ba50c2c
LCW
75
76 # Build the plugin itself
77 set extra_flags [plugin-get-options $plugin_src]
78
79 # Note that the plugin test support currently only works when the GCC
80 # build tree is available. (We make sure that is the case in plugin.exp.)
81 # Once we have figured out how/where to package/install GCC header files
82 # for general plugin support, we should modify the following include paths
83 # accordingly.
84 set gcc_srcdir "$srcdir/../.."
85 set gcc_objdir "$objdir/../../.."
86 set includes "-I. -I${srcdir} -I${gcc_srcdir}/gcc -I${gcc_objdir}/gcc \
87 -I${gcc_srcdir}/include -I${gcc_srcdir}/libcpp/include \
4b1b0ac1 88 $GMPINC -I${gcc_objdir}/intl"
8ba50c2c 89
920a8260 90 if { [ ishost *-*-darwin* ] } {
d8ed14ce
IS
91 # -mdynamic-no-pic is incompatible with -fPIC.
92 set plug_cflags ""
93 foreach op $PLUGINCFLAGS {
94 if { [string compare "-mdynamic-no-pic" $op] } {
95 set plug_cflags [concat $plug_cflags " $op"]
96 }
97 }
98 set optstr "$includes"
99 foreach op $extra_flags {
100 if { [string compare "-mdynamic-no-pic" $op] } {
101 set optstr [concat $optstr " $op"]
102 }
103 }
d0cd8160 104 set optstr [concat $optstr "-DIN_GCC -fPIC -shared -fno-rtti -undefined dynamic_lookup"]
d8ed14ce
IS
105 } else {
106 set plug_cflags $PLUGINCFLAGS
15892298 107 set optstr "$includes $extra_flags -DIN_GCC -fPIC -shared -fno-rtti"
920a8260
JH
108 }
109
eeb971c9 110 # Temporarily switch to the environment for the plugin compiler.
2ff2235c 111 restore_ld_library_path_env_vars
d8ed14ce 112 set status [remote_exec build "$PLUGINCC $plug_cflags $plugin_src $optstr -o $plugin_lib"]
2ff2235c
L
113 set status [lindex $status 0]
114 set_ld_library_path_env_vars
115
116 if { $status != 0 } then {
3be74079
RO
117 fail "$testcase compilation"
118 # Strictly, this is wrong: the tests compiled with the plugin should
119 # become unresolved instead.
8ba50c2c 120 return
3be74079
RO
121 } else {
122 pass "$testcase compilation"
8ba50c2c
LCW
123 }
124
125 # Compile the input source files with the plugin
126 global default_flags
127 set plugin_enabling_flags "-fplugin=./$plugin_lib"
128 dg-runtest $plugin_tests $plugin_enabling_flags $default_flags
129
130 # Clean up
131 remote_file build delete $plugin_lib
132}