objc.exp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. # Copyright (C) 1992-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. # This file was written by Rob Savoye (rob@cygnus.com)
  16. # Currently maintained by Doug Evans (dje@cygnus.com)
  17. # This file is loaded by the tool init file (eg: unix.exp). It provides
  18. # default definitions for objc_start, etc. and other supporting cast members.
  19. # These globals are used by objc_start if no compiler arguments are provided.
  20. # They are also used by the various testsuites to define the environment:
  21. # where to find stdio.h, libc.a, etc.
  22. load_lib libgloss.exp
  23. load_lib prune.exp
  24. load_lib gcc-defs.exp
  25. load_lib timeout.exp
  26. load_lib target-libpath.exp
  27. load_lib target-utils.exp
  28. #
  29. # OBJC_UNDER_TEST is the compiler under test.
  30. #
  31. #
  32. # default_objc_version -- extract and print the version number of the compiler
  33. #
  34. proc default_objc_version { } {
  35. global OBJC_UNDER_TEST
  36. objc_init
  37. # Ignore any arguments after the command.
  38. set compiler [lindex $OBJC_UNDER_TEST 0]
  39. if ![is_remote host] {
  40. set compiler_name [which $compiler]
  41. } else {
  42. set compiler_name $compiler
  43. }
  44. # Verify that the compiler exists.
  45. if { $compiler_name != 0 } then {
  46. set tmp [remote_exec host "$compiler -v"]
  47. set status [lindex $tmp 0]
  48. set output [lindex $tmp 1]
  49. regexp " version \[^\n\r\]*" $output version
  50. if { $status == 0 && [info exists version] } then {
  51. clone_output "$compiler_name $version\n"
  52. } else {
  53. clone_output "Couldn't determine version of $compiler_name: $output\n"
  54. }
  55. } else {
  56. # Compiler does not exist (this should have already been detected).
  57. warning "$compiler does not exist"
  58. }
  59. }
  60. #
  61. # Call objc_version. We do it this way so we can override it if needed.
  62. #
  63. proc objc_version { } {
  64. default_objc_version
  65. }
  66. #
  67. # objc_init -- called at the start of each .exp script.
  68. #
  69. # There currently isn't much to do, but always using it allows us to
  70. # make some enhancements without having to go back and rewrite the scripts.
  71. #
  72. set objc_initialized 0
  73. proc objc_init { args } {
  74. global rootme
  75. global tmpdir
  76. global libdir
  77. global gluefile wrap_flags
  78. global objc_initialized
  79. global OBJC_UNDER_TEST
  80. global TOOL_EXECUTABLE
  81. global objc_libgcc_s_path
  82. global gcc_warning_prefix
  83. global gcc_error_prefix
  84. # We set LC_ALL and LANG to C so that we get the same error messages as
  85. # expected.
  86. setenv LC_ALL C
  87. setenv LANG C
  88. # Many hosts now default to a non-ASCII C locale, however, so
  89. # they can set a charset encoding here if they need.
  90. if { [ishost "*-*-cygwin*"] } {
  91. setenv LC_ALL C.ASCII
  92. setenv LANG C.ASCII
  93. }
  94. if { $objc_initialized == 1 } { return; }
  95. if ![info exists OBJC_UNDER_TEST] then {
  96. if [info exists TOOL_EXECUTABLE] {
  97. set OBJC_UNDER_TEST $TOOL_EXECUTABLE
  98. } else {
  99. set OBJC_UNDER_TEST [find_gcc]
  100. }
  101. }
  102. if ![info exists tmpdir] then {
  103. set tmpdir /tmp
  104. }
  105. set gcc_warning_prefix "warning:"
  106. set gcc_error_prefix "(fatal )?error:"
  107. objc_maybe_build_wrapper "${tmpdir}/objc-testglue.o"
  108. set objc_libgcc_s_path [gcc-set-multilib-library-path $OBJC_UNDER_TEST]
  109. }
  110. proc objc_target_compile { source dest type options } {
  111. global rootme
  112. global tmpdir
  113. global gluefile wrap_flags
  114. global srcdir
  115. global OBJC_UNDER_TEST
  116. global TOOL_OPTIONS
  117. global ld_library_path
  118. global objc_libgcc_s_path
  119. global shlib_ext
  120. global TEST_ALWAYS_FLAGS
  121. set shlib_ext [get_shlib_extension]
  122. set ld_library_path ".:${objc_libgcc_s_path}"
  123. # We have to figure out which runtime will be used on darwin because
  124. # we need to add the include path for the gnu runtime if that is in
  125. # use.
  126. # First set the default...
  127. if { [istarget *-*-darwin*] } {
  128. set nextruntime 1
  129. } else {
  130. set nextruntime 0
  131. }
  132. verbose "initial next runtime state : $nextruntime" 2
  133. # Next, see if we define the option in dg-options...
  134. foreach opt $options {
  135. if [regexp ".*-fnext-runtime.*" $opt] {
  136. set nextruntime 1
  137. }
  138. if [regexp ".*-fgnu-runtime.*" $opt] {
  139. set nextruntime 0
  140. }
  141. }
  142. verbose "next runtime state after dg opts: $nextruntime" 2
  143. set tgt [target_info name]
  144. if [board_info $tgt exists multilib_flags] {
  145. set lb [board_info $tgt multilib_flags]
  146. verbose "board multilib_flags $lb" 2
  147. foreach opt $lb {
  148. if [regexp ".*-fnext-runtime.*" $opt] {
  149. set nextruntime 1
  150. }
  151. if [regexp ".*-fgnu-runtime.*" $opt] {
  152. set nextruntime 0
  153. }
  154. }
  155. }
  156. verbose "next runtime state after any multilib opts: $nextruntime" 2
  157. lappend options "libs=-lobjc"
  158. verbose "shared lib extension: $shlib_ext" 3
  159. if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
  160. lappend options "libs=${gluefile}"
  161. lappend options "ldflags=$wrap_flags"
  162. }
  163. if [target_info exists objc,stack_size] {
  164. lappend options "additional_flags=-DSTACK_SIZE=[target_info objc,stack_size]"
  165. }
  166. if [target_info exists objc,no_trampolines] {
  167. lappend options "additional_flags=-DNO_TRAMPOLINES"
  168. }
  169. if [target_info exists objc,no_label_values] {
  170. lappend options "additional_flags=-DNO_LABEL_VALUES"
  171. }
  172. # TEST_ALWAYS_FLAGS are flags that should be passed to every
  173. # compilation. They are passed first to allow individual
  174. # tests to override them.
  175. if [info exists TEST_ALWAYS_FLAGS] {
  176. set options [concat "{additional_flags=$TEST_ALWAYS_FLAGS}" $options]
  177. }
  178. # TOOL_OPTIONS must come first, so that it doesn't override testcase
  179. # specific options.
  180. if [info exists TOOL_OPTIONS] {
  181. set options [concat "{additional_flags=$TOOL_OPTIONS}" $options]
  182. }
  183. # If we have built libobjc along with the compiler, point the test harness
  184. # at it (and associated headers).
  185. set objcpath "[get_multilibs]"
  186. set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.a]
  187. if { $libobjc_dir == "" } {
  188. # On darwin there is, potentially, a gnu runtime too.
  189. set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.a]
  190. }
  191. # Perhaps we didn't build static libs.
  192. if { $libobjc_dir == "" } {
  193. set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc.${shlib_ext}]
  194. # On darwin there is, potentially, a gnu runtime too.
  195. if { $libobjc_dir == "" } {
  196. set libobjc_dir [lookfor_file ${objcpath} libobjc/.libs/libobjc-gnu.${shlib_ext}]
  197. }
  198. }
  199. if { $libobjc_dir != "" } {
  200. # If we are using the gnu runtime, add its includes.
  201. if { $nextruntime == 0 } {
  202. set objc_include_dir "${srcdir}/../../libobjc"
  203. lappend options "additional_flags=-I${objc_include_dir}"
  204. verbose "adding gnu runtime include dir: $objc_include_dir "
  205. }
  206. set libobjc_dir [file dirname ${libobjc_dir}]
  207. # Allow for %s spec substitutions..
  208. set objc_link_flags " -B${libobjc_dir} "
  209. lappend options "additional_flags=${objc_link_flags}"
  210. set objc_link_flags " -L${libobjc_dir} "
  211. lappend options "additional_flags=${objc_link_flags}"
  212. append ld_library_path ":${libobjc_dir}"
  213. }
  214. if { $type == "precompiled_header" } {
  215. # If we generating a precompiled header, we have say this is an
  216. # objective-C header.
  217. set source [concat "-x objective-c-header" $source]
  218. }
  219. lappend options "compiler=$OBJC_UNDER_TEST"
  220. lappend options "timeout=[timeout_value]"
  221. set_ld_library_path_env_vars
  222. set options [dg-additional-files-options $options $source]
  223. return [target_compile $source $dest $type $options]
  224. }
  225. #
  226. # objc_pass -- utility to record a testcase passed.
  227. #
  228. proc objc_pass { testcase cflags } {
  229. if { "$cflags" == "" } {
  230. pass "$testcase"
  231. } else {
  232. pass "$testcase, $cflags"
  233. }
  234. }
  235. #
  236. # objc_fail -- utility to record a testcase failed
  237. #
  238. proc objc_fail { testcase cflags } {
  239. if { "$cflags" == "" } {
  240. fail "$testcase"
  241. } else {
  242. fail "$testcase, $cflags"
  243. }
  244. }
  245. #
  246. # objc_finish -- called at the end of every .exp script that calls objc_init
  247. #
  248. # The purpose of this proc is to hide all quirks of the testing environment
  249. # from the testsuites. It also exists to undo anything that objc_init did
  250. # (that needs undoing).
  251. #
  252. proc objc_finish { } {
  253. # The testing harness apparently requires this.
  254. global errorInfo
  255. if [info exists errorInfo] then {
  256. unset errorInfo
  257. }
  258. # Might as well reset these (keeps our caller from wondering whether
  259. # s/he has to or not).
  260. global prms_id bug_id
  261. set prms_id 0
  262. set bug_id 0
  263. }
  264. proc objc_exit { } {
  265. global gluefile
  266. if [info exists gluefile] {
  267. file_on_build delete $gluefile
  268. unset gluefile
  269. }
  270. }
  271. # If this is an older version of dejagnu (without runtest_file_p),
  272. # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
  273. # This can be deleted after next dejagnu release.
  274. if { [info procs runtest_file_p] == "" } then {
  275. proc runtest_file_p { runtests testcase } {
  276. if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
  277. if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
  278. return 1
  279. } else {
  280. return 0
  281. }
  282. }
  283. return 1
  284. }
  285. }
  286. # Provide a definition of this if missing (delete after next dejagnu release).
  287. if { [info procs prune_warnings] == "" } then {
  288. proc prune_warnings { text } {
  289. return $text
  290. }
  291. }
  292. # Prune messages from objc that aren't useful.
  293. proc prune_objc_output { text } {
  294. #send_user "Before:$text\n"
  295. regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
  296. regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
  297. # It would be nice to avoid passing anything to objc that would cause it to
  298. # issue these messages (since ignoring them seems like a hack on our part),
  299. # but that's too difficult in the general case. For example, sometimes
  300. # you need to use -B to point objc at crt0.o, but there are some targets
  301. # that don't have crt0.o.
  302. regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
  303. regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
  304. #send_user "After:$text\n"
  305. return $text
  306. }