go.exp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with GCC; see the file COPYING3. If not see
  14. # <http://www.gnu.org/licenses/>.
  15. #
  16. # go support library routines
  17. #
  18. load_lib prune.exp
  19. load_lib gcc-defs.exp
  20. load_lib timeout.exp
  21. load_lib target-libpath.exp
  22. #
  23. # GOC_UNDER_TEST is the compiler under test.
  24. #
  25. set gpp_compile_options ""
  26. #
  27. # go_version -- extract and print the version number of the compiler
  28. #
  29. proc go_version { } {
  30. global GOC_UNDER_TEST
  31. go_init
  32. # ignore any arguments after the command
  33. set compiler [lindex $GOC_UNDER_TEST 0]
  34. # verify that the compiler exists
  35. if { [is_remote host] || [which $compiler] != 0 } then {
  36. set tmp [remote_exec host "$compiler -v"]
  37. set status [lindex $tmp 0]
  38. set output [lindex $tmp 1]
  39. regexp " version \[^\n\r\]*" $output version
  40. if { $status == 0 && [info exists version] } then {
  41. if [is_remote host] {
  42. clone_output "$compiler $version\n"
  43. } else {
  44. clone_output "[which $compiler] $version\n"
  45. }
  46. } else {
  47. clone_output "Couldn't determine version of [which $compiler]\n"
  48. }
  49. } else {
  50. # compiler does not exist (this should have already been detected)
  51. warning "$compiler does not exist"
  52. }
  53. }
  54. #
  55. # go_include_flags -- include flags for the gcc tree structure
  56. #
  57. proc go_include_flags { paths } {
  58. global srcdir
  59. global TESTING_IN_BUILD_TREE
  60. set flags ""
  61. if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } {
  62. return "${flags}"
  63. }
  64. set gccpath ${paths}
  65. if { $gccpath != "" } {
  66. if [file exists "${gccpath}/libgo/os.gox"] {
  67. append flags "-I${gccpath}/libgo "
  68. }
  69. }
  70. }
  71. #
  72. # go_link_flags -- linker flags for the gcc tree structure
  73. #
  74. proc go_link_flags { paths } {
  75. global srcdir
  76. global ld_library_path
  77. global GOC_UNDER_TEST
  78. global shlib_ext
  79. set gccpath ${paths}
  80. set libio_dir ""
  81. set flags ""
  82. set ld_library_path "."
  83. set shlib_ext [get_shlib_extension]
  84. verbose "shared lib extension: $shlib_ext"
  85. if { $gccpath != "" } {
  86. if [file exists "${gccpath}/libgo/libgobegin.a"] {
  87. append flags "-L${gccpath}/libgo "
  88. }
  89. if { [file exists "${gccpath}/libgo/.libs/libgo.a"] \
  90. || [file exists "${gccpath}/libgo/.libs/libgo.${shlib_ext}"] } {
  91. append flags "-L${gccpath}/libgo/.libs "
  92. append ld_library_path ":${gccpath}/libgo/.libs"
  93. }
  94. if [file exists "${gccpath}/libiberty/libiberty.a"] {
  95. append flags "-L${gccpath}/libiberty "
  96. }
  97. append ld_library_path \
  98. [gcc-set-multilib-library-path $GOC_UNDER_TEST]
  99. }
  100. set_ld_library_path_env_vars
  101. return "$flags"
  102. }
  103. #
  104. # go_init -- called at the start of each subdir of tests
  105. #
  106. proc go_init { args } {
  107. global subdir
  108. global gpp_initialized
  109. global base_dir
  110. global tmpdir
  111. global libdir
  112. global gluefile wrap_flags
  113. global objdir srcdir
  114. global ALWAYS_GOCFLAGS
  115. global TOOL_EXECUTABLE TOOL_OPTIONS
  116. global GOC_UNDER_TEST
  117. global TESTING_IN_BUILD_TREE
  118. global TEST_ALWAYS_FLAGS
  119. # We set LC_ALL and LANG to C so that we get the same error messages as expected.
  120. setenv LC_ALL C
  121. setenv LANG C
  122. if ![info exists GOC_UNDER_TEST] then {
  123. if [info exists TOOL_EXECUTABLE] {
  124. set GOC_UNDER_TEST $TOOL_EXECUTABLE
  125. } else {
  126. if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
  127. set GOC_UNDER_TEST [transform gccgo]
  128. } else {
  129. set GOC_UNDER_TEST [findfile $base_dir/../../gccgo "$base_dir/../../gccgo -B$base_dir/../../" [findfile $base_dir/gccgo "$base_dir/gccgo -B$base_dir/" [transform gccgo]]]
  130. }
  131. }
  132. }
  133. if ![is_remote host] {
  134. if { [which $GOC_UNDER_TEST] == 0 } then {
  135. perror "GOC_UNDER_TEST ($GOC_UNDER_TEST) does not exist"
  136. exit 1
  137. }
  138. }
  139. if ![info exists tmpdir] {
  140. set tmpdir "/tmp"
  141. }
  142. if [info exists gluefile] {
  143. unset gluefile
  144. }
  145. go_maybe_build_wrapper "${tmpdir}/go-testglue.o"
  146. set ALWAYS_GOCFLAGS ""
  147. # TEST_ALWAYS_FLAGS are flags that should be passed to every
  148. # compilation. They are passed first to allow individual
  149. # tests to override them.
  150. if [info exists TEST_ALWAYS_FLAGS] {
  151. lappend ALWAYS_GOCFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
  152. }
  153. if ![is_remote host] {
  154. if [info exists TOOL_OPTIONS] {
  155. lappend ALWAYS_GOCFLAGS "additional_flags=[go_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
  156. lappend ALWAYS_GOCFLAGS "ldflags=[go_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
  157. } else {
  158. lappend ALWAYS_GOCFLAGS "additional_flags=[go_include_flags [get_multilibs] ]"
  159. lappend ALWAYS_GOCFLAGS "ldflags=[go_link_flags [get_multilibs] ]"
  160. }
  161. }
  162. if [info exists TOOL_OPTIONS] {
  163. lappend ALWAYS_GOCFLAGS "additional_flags=$TOOL_OPTIONS"
  164. }
  165. verbose -log "ALWAYS_GOCFLAGS set to $ALWAYS_GOCFLAGS"
  166. verbose "go is initialized" 3
  167. }
  168. #
  169. # go_target_compile -- compile a source file
  170. #
  171. proc go_target_compile { source dest type options } {
  172. global tmpdir
  173. global gluefile wrap_flags
  174. global ALWAYS_GOCFLAGS
  175. global GOC_UNDER_TEST
  176. if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
  177. lappend options "libs=${gluefile}"
  178. lappend options "ldflags=${wrap_flags}"
  179. }
  180. lappend options "timeout=[timeout_value]"
  181. lappend options "compiler=$GOC_UNDER_TEST"
  182. set options [concat "$ALWAYS_GOCFLAGS" $options]
  183. set options [dg-additional-files-options $options $source]
  184. return [target_compile $source $dest $type $options]
  185. }