| 1 |
# Copyright (C) 2012-2025 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 |
# sarif-replay 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 |
# SARIF_REPLAY_UNDER_TEST is the compiler under test. |
| 28 |
# |
| 29 |
|
| 30 |
set sarif-replay_compile_options "" |
| 31 |
|
| 32 |
|
| 33 |
# |
| 34 |
# sarif-replay_version -- extract and print the version number of the compiler |
| 35 |
# |
| 36 |
|
| 37 |
proc sarif-replay_version { } { |
| 38 |
global SARIF_REPLAY_UNDER_TEST |
| 39 |
|
| 40 |
sarif-replay_init |
| 41 |
|
| 42 |
# ignore any arguments after the command |
| 43 |
set compiler [lindex $SARIF_REPLAY_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 |
# sarif-replay_include_flags -- include flags for the gcc tree structure |
| 68 |
# |
| 69 |
|
| 70 |
proc sarif-replay_include_flags { paths } { |
| 71 |
global srcdir |
| 72 |
global SARIF-REPLAY_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 SARIF-REPLAY_INCLUDE_CXX_FLAGS] { |
| 82 |
set include_cxx_flags $SARIF-REPLAY_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 |
# sarif-replay_init -- called at the start of each subdir of tests |
| 112 |
# |
| 113 |
|
| 114 |
proc sarif-replay_init { args } { |
| 115 |
global sarif-replay_initialized |
| 116 |
global base_dir |
| 117 |
global tmpdir |
| 118 |
global libdir |
| 119 |
global gluefile wrap_flags |
| 120 |
global TOOL_EXECUTABLE |
| 121 |
global SARIF_REPLAY_UNDER_TEST |
| 122 |
global TESTING_IN_BUILD_TREE |
| 123 |
global gcc_warning_prefix |
| 124 |
global gcc_error_prefix |
| 125 |
|
| 126 |
# We set LC_ALL and LANG to C so that we get the same error messages as expected. |
| 127 |
setenv LC_ALL C |
| 128 |
setenv LANG C |
| 129 |
|
| 130 |
if ![info exists SARIF_REPLAY_UNDER_TEST] then { |
| 131 |
if [info exists TOOL_EXECUTABLE] { |
| 132 |
set SARIF_REPLAY_UNDER_TEST $TOOL_EXECUTABLE |
| 133 |
} else { |
| 134 |
if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } { |
| 135 |
set SARIF_REPLAY_UNDER_TEST [transform sarif-replay] |
| 136 |
} else { |
| 137 |
set SARIF_REPLAY_UNDER_TEST [findfile $base_dir/../../sarif-replay "$base_dir/../../sarif-replay" [findfile $base_dir/sarif-replay "$base_dir/sarif-replay" [transform sarif-replay]]] |
| 138 |
} |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
verbose "SARIF_REPLAY_UNDER_TEST: $SARIF_REPLAY_UNDER_TEST" 2 |
| 143 |
|
| 144 |
if ![is_remote host] { |
| 145 |
if { [which $SARIF_REPLAY_UNDER_TEST] == 0 } then { |
| 146 |
perror "SARIF_REPLAY_UNDER_TEST ($SARIF_REPLAY_UNDER_TEST) does not exist" |
| 147 |
exit 1 |
| 148 |
} |
| 149 |
} |
| 150 |
if ![info exists tmpdir] { |
| 151 |
set tmpdir "/tmp" |
| 152 |
} |
| 153 |
|
| 154 |
if [info exists gluefile] { |
| 155 |
unset gluefile |
| 156 |
} |
| 157 |
|
| 158 |
set gcc_warning_prefix "warning:" |
| 159 |
set gcc_error_prefix "(fatal )?error:" |
| 160 |
|
| 161 |
verbose "sarif-replay is initialized" 3 |
| 162 |
} |
| 163 |
|
| 164 |
# |
| 165 |
# sarif-replay_target_compile -- compile a source file |
| 166 |
# |
| 167 |
|
| 168 |
proc sarif-replay_target_compile { source dest type options } { |
| 169 |
global tmpdir |
| 170 |
global gluefile wrap_flags |
| 171 |
global SARIF_REPLAY_UNDER_TEST |
| 172 |
global TOOL_OPTIONS |
| 173 |
global TEST_ALWAYS_FLAGS |
| 174 |
|
| 175 |
if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } { |
| 176 |
lappend options "libs=${gluefile}" |
| 177 |
lappend options "ldflags=${wrap_flags}" |
| 178 |
} |
| 179 |
|
| 180 |
set always_sarif_replay_flags "" |
| 181 |
|
| 182 |
# FIXME: strip out -fdiagnostics-plain-output from TEST_ALWAYS_FLAGS |
| 183 |
# rather than hacking this out: |
| 184 |
# |
| 185 |
# TEST_ALWAYS_FLAGS are flags that should be passed to every |
| 186 |
# compilation. They are passed first to allow individual |
| 187 |
# tests to override them. |
| 188 |
## if [info exists TEST_ALWAYS_FLAGS] { |
| 189 |
## lappend always_sarif_replay_flags "additional_flags=$TEST_ALWAYS_FLAGS" |
| 190 |
## } |
| 191 |
|
| 192 |
if [info exists TOOL_OPTIONS] { |
| 193 |
lappend always_sarif_replay_flags "additional_flags=$TOOL_OPTIONS" |
| 194 |
} |
| 195 |
|
| 196 |
verbose "always_sarif_replay_flags set to: $always_sarif_replay_flags" |
| 197 |
|
| 198 |
lappend options "timeout=[timeout_value]" |
| 199 |
lappend options "compiler=$SARIF_REPLAY_UNDER_TEST" |
| 200 |
|
| 201 |
set options [concat "$always_sarif_replay_flags" $options] |
| 202 |
set options [dg-additional-files-options $options $source $dest $type] |
| 203 |
return [target_compile $source $dest $type $options] |
| 204 |
} |