/core/externals/update-engine/externals/google-toolbox-for-mac/XcodePlugin/Resources/EnableGCov.applescript

http://macfuse.googlecode.com/ · AppleScript · 86 lines · 58 code · 2 blank · 26 comment · 10 complexity · 3f3dd56dcf2efb2e6c7751e3f03bf9b7 MD5 · raw file

  1. (*
  2. EnableGCov.applescript
  3. Copyright 2007-2009 Google Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. use this file except in compliance with the License. You may obtain a copy
  6. of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  10. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  11. License for the specific language governing permissions and limitations under
  12. the License.
  13. Enables and disables gcov by either setting or removing the
  14. GCC_INSTRUMENT_PROGRAM_FLOW_ARCS & GCC_GENERATE_TEST_COVERAGE_FILES
  15. settings as appropriate, and adding a link to the gcov library
  16. if necessary.
  17. *)
  18. (*
  19. gets passed a list of args from Xcode
  20. first arg is whether to enable or disable gcov settings,
  21. *)
  22. on run (enable)
  23. tell application "Xcode"
  24. tell project of active project document
  25. set buildconfig to name of active build configuration type
  26. tell build configuration buildconfig of active target
  27. set needsGcovLib to true
  28. try
  29. set machOType to value of flattened build setting "MACH_O_TYPE"
  30. if (machOType is "staticlib") or (machOType is "mh_object") then
  31. set needsGcovLib to false
  32. end if
  33. end try
  34. if item 1 of enable is "YES" then
  35. set value of build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS" to "YES"
  36. set value of build setting "GCC_GENERATE_TEST_COVERAGE_FILES" to "YES"
  37. if needsGcovLib then
  38. try
  39. set a to value of build setting "OTHER_LDFLAGS"
  40. on error
  41. set a to "$(inherited)"
  42. end try
  43. if a does not contain "-lgcov" then
  44. set value of build setting "OTHER_LDFLAGS" to a & " -lgcov"
  45. end if
  46. end if
  47. else
  48. try
  49. delete build setting "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"
  50. end try
  51. try
  52. delete build setting "GCC_GENERATE_TEST_COVERAGE_FILES"
  53. end try
  54. if needsGcovLib then
  55. try
  56. set a to value of build setting "OTHER_LDFLAGS"
  57. set oldDelims to AppleScript's text item delimiters
  58. set AppleScript's text item delimiters to " "
  59. set a to every text item of a
  60. set c to {}
  61. repeat with b in a
  62. if b as string is not equal to "-lgcov" then
  63. set c to c & b
  64. end if
  65. end repeat
  66. set a to c as string
  67. set AppleScript's text item delimiters to oldDelims
  68. if (length of a > 0) and (a ­ "$(inherited)") then
  69. set value of build setting "OTHER_LDFLAGS" to a
  70. else
  71. delete build setting "OTHER_LDFLAGS"
  72. end if
  73. end try
  74. end if
  75. end if
  76. end tell
  77. end tell
  78. end tell
  79. end run