/core/externals/google-toolbox-for-mac/XcodePlugin/Resources/CreateUnitTestExecutable.applescript

http://macfuse.googlecode.com/ · AppleScript · 224 lines · 182 code · 16 blank · 26 comment · 17 complexity · f195565310a676dfae7d119980e33209 MD5 · raw file

  1. (*
  2. CreateUnitTestExecutable.scpt
  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. Support script for easily creating debug executables for unittests
  14. 2008/03/06 Added support for debug frameworks, Xcode 3.1, and debugging under a testhost
  15. *)
  16. on replaceText(theString, fString, rString)
  17. set current_Delimiters to AppleScript's text item delimiters
  18. set AppleScript's text item delimiters to fString
  19. set sList to every text item of theString
  20. set AppleScript's text item delimiters to rString
  21. set newString to sList as string
  22. set AppleScript's text item delimiters to current_Delimiters
  23. return newString
  24. end replaceText
  25. on findVariable(a)
  26. set b to "echo '" & a & "' | grep -o \"$\\([^)]*)\\)\" | head -n 1"
  27. return do shell script b
  28. end findVariable
  29. on expandBuildSettings(a, b)
  30. tell me
  31. repeat
  32. set pattern to findVariable(a)
  33. if (length of pattern is equal to 0) then
  34. exit repeat
  35. else
  36. set oldValue to word 2 of pattern
  37. tell application "Xcode"
  38. -- get our project
  39. tell project of active project document
  40. set activeBuildConfig to name of active build configuration type
  41. try
  42. if oldValue is "inherited" then
  43. set oldValue to word 2 of b
  44. tell build configuration activeBuildConfig
  45. set newValue to value of flattened build setting oldValue
  46. end tell
  47. else
  48. tell build configuration activeBuildConfig of active target
  49. set newValue to value of flattened build setting oldValue
  50. end tell
  51. end if
  52. on error
  53. log "Unable to expand '" & oldValue & "'"
  54. set newValue to ""
  55. end try
  56. end tell
  57. end tell
  58. set newValue to expandBuildSettings(newValue, a)
  59. set a to replaceText(a, pattern, newValue)
  60. end if
  61. end repeat
  62. end tell
  63. return a
  64. end expandBuildSettings
  65. on expandBuildSetting(a)
  66. return expandBuildSettings(a, "")
  67. end expandBuildSetting
  68. tell application "Xcode"
  69. -- get our project
  70. tell project of active project document
  71. set activeBuildConfig to name of active build configuration type
  72. -- build executable
  73. tell build configuration activeBuildConfig of active target
  74. tell me
  75. set productName to expandBuildSetting("$(PRODUCT_NAME)")
  76. set productPath to expandBuildSetting("$(SRCROOT)/$(BUILT_PRODUCTS_DIR)")
  77. end tell
  78. tell me
  79. set wrapperExtension to expandBuildSetting("$(WRAPPER_EXTENSION)")
  80. end tell
  81. try
  82. tell me
  83. set useGC to expandBuildSetting("$(GCC_ENABLE_OBJC_GC)")
  84. if useGC is equal to "Unsupported" or useGC is equal to "" then
  85. set useGC to yes
  86. else
  87. set useGC to no
  88. end if
  89. end tell
  90. on error e
  91. log "Unable to expand GCC_ENABLE_OBJC_GC " & e
  92. set useGC to no
  93. end try
  94. try
  95. tell me
  96. set testhost to expandBuildSetting("$(TEST_HOST)")
  97. -- if testhost is a relative path, make it absolute
  98. if first character of testhost is not "/" then
  99. set testhost to expandBuildSetting("$(SRCROOT)") & "/" & testhost
  100. end if
  101. end tell
  102. on error e
  103. log "Unable to expand testHost " & e
  104. set testhost to ""
  105. end try
  106. end tell
  107. if wrapperExtension is equal to "octest" then
  108. set executablePath to "/Developer/Tools/otest"
  109. set executableName to "otest"
  110. else if wrapperExtension is equal to "gtest" then
  111. set executablePath to "/Developer/Tools/gUnit"
  112. set executableName to "gUnit"
  113. else
  114. display alert "Unknown test type with extension " & wrapperExtension
  115. return
  116. end if
  117. if testhost is not equal to "" then
  118. set executablePath to testhost
  119. set executableName to "TestHost"
  120. end if
  121. set execName to productName & "(" & executableName & ")"
  122. set exec to make new executable with properties Ź
  123. {name:execName, launchable:yes, path:executablePath, comments:Ź
  124. "Test executable for " & name of active target & "(" & executableName & ")." & Ź
  125. return & "Generated " & (current date) & " by Google Toolbox For Mac Xcode Plugin." & Ź
  126. return & "Go to http://developer.apple.com/technotes/tn2004/tn2124.html for more info on settings."}
  127. tell exec
  128. if useGC is equal to "Unsupported" or useGC is equal to "" then
  129. end if
  130. if wrapperExtension is "octest" then
  131. -- force some nice cocoa debug stuff on
  132. make new launch argument with properties {name:"-NSBindingDebugLogLevel 1", active:yes}
  133. make new launch argument with properties {name:"-NSScriptingDebugLogLevel 1", active:yes}
  134. make new launch argument with properties {name:"-NSTraceEvents YES", active:no}
  135. make new launch argument with properties {name:"-NSShowAllViews YES", active:no}
  136. make new launch argument with properties {name:"-NSShowAllDrawing YES", active:no}
  137. make new launch argument with properties {name:"-NSDragManagerLogLevel 6", active:no}
  138. make new launch argument with properties {name:"-NSAccessibilityDebugLogLevel 3", active:no}
  139. end if
  140. set bundlename to productName & "." & wrapperExtension
  141. set bundlePath to productPath & "/" & bundlename
  142. if testhost is not equal to "" then
  143. make new environment variable with properties {name:"XCInjectBundleInto", value:testhost, active:yes}
  144. make new environment variable with properties {name:"DYLD_INSERT_LIBRARIES", value:"/Developer/Library/PrivateFrameworks/DevToolsBundleInjection.framework/DevToolsBundleInjection", active:yes}
  145. make new environment variable with properties {name:"XCInjectBundle", value:bundlePath, active:yes}
  146. if wrapperExtension is "octest" then
  147. make new launch argument with properties {name:"-SenTest All", active:yes}
  148. end if
  149. else
  150. if wrapperExtension is "octest" then
  151. make new launch argument with properties {name:"-SenTest Self", active:yes}
  152. end if
  153. make new launch argument with properties {name:"\"" & bundlePath & "\"", active:yes}
  154. end if
  155. make new environment variable with properties {name:"OBJC_DISABLE_GC", value:"YES", active:useGC}
  156. make new environment variable with properties {name:"DYLD_LIBRARY_PATH", value:".", active:yes}
  157. make new environment variable with properties {name:"DYLD_FRAMEWORK_PATH", value:".:/Developer/Library/Frameworks", active:yes}
  158. make new environment variable with properties {name:"DYLD_NEW_LOCAL_SHARED_REGIONS", value:"YES", active:yes}
  159. make new environment variable with properties {name:"DYLD_NO_FIX_PREBINDING", value:"YES", active:yes}
  160. make new environment variable with properties {name:"MallocScribble", value:"YES", active:yes}
  161. make new environment variable with properties {name:"MallocPreScribble", value:"YES", active:yes}
  162. make new environment variable with properties {name:"MallocGuardEdges", value:"YES", active:yes}
  163. make new environment variable with properties {name:"NSAutoreleaseFreedObjectCheckEnabled", value:"YES", active:yes}
  164. make new environment variable with properties {name:"NSZombieEnabled", value:"YES", active:yes}
  165. make new environment variable with properties {name:"OBJC_DEBUG_FRAGILE_SUPERCLASSES", value:"YES", active:yes}
  166. make new environment variable with properties {name:"ComponentDebug", value:"1", active:no}
  167. make new environment variable with properties {name:"FilesASDDebug", value:"1", active:no}
  168. make new environment variable with properties {name:"VNDebug", value:"1", active:no}
  169. make new environment variable with properties {name:"WSDebug", value:"1", active:no}
  170. make new environment variable with properties {name:"WSDebugVerbose", value:"1", active:no}
  171. make new environment variable with properties {name:"DRVerboseLogging", value:"1", active:no}
  172. make new environment variable with properties {name:"INIT_Processes", value:"1", active:no}
  173. make new environment variable with properties {name:"EventDebug", value:"1", active:no}
  174. make new environment variable with properties {name:"EventRate", value:"1", active:no}
  175. make new environment variable with properties {name:"TSMEventTracing", value:"1", active:no}
  176. make new environment variable with properties {name:"OBJC_PRINT_IMAGES", value:"1", active:no}
  177. make new environment variable with properties {name:"OBJC_PRINT_LOAD_METHODS", value:"1", active:no}
  178. make new environment variable with properties {name:"DYLD_IMAGE_SUFFIX", value:"_debug", active:no}
  179. make new environment variable with properties {name:"DYLD_PRINT_LIBRARIES", value:"1", active:no}
  180. make new environment variable with properties {name:"DYLD_PRINT_LIBRARIES_POST_LAUNCH", value:"1", active:no}
  181. make new environment variable with properties {name:"DYLD_PREBIND_DEBUG", value:"1", active:no}
  182. make new environment variable with properties {name:"DYLD_PRINT_APIS", value:"1", active:no}
  183. make new environment variable with properties {name:"DYLD_PRINT_BINDINGS", value:"1", active:no}
  184. make new environment variable with properties {name:"DYLD_PRINT_INITIALIZERS", value:"1", active:no}
  185. make new environment variable with properties {name:"DYLD_PRINT_SEGMENTS", value:"1", active:no}
  186. make new environment variable with properties {name:"DYLD_PRINT_STATISTICS", value:"1", active:no}
  187. make new environment variable with properties {name:"NSDeallocateZombies", value:"YES", active:no}
  188. make new environment variable with properties {name:"NSHangOnUncaughtException", value:"YES", active:no}
  189. make new environment variable with properties {name:"NSEnableAutoreleasePool", value:"NO", active:no}
  190. make new environment variable with properties {name:"NSAutoreleaseHighWaterMark", value:"1000", active:no}
  191. make new environment variable with properties {name:"NSAutoreleaseHighWaterResolution", value:"100", active:no}
  192. make new environment variable with properties {name:"NSPrintDynamicClassLoads", value:"YES", active:no}
  193. make new environment variable with properties {name:"NSExceptionLoggingEnabled", value:"YES", active:no}
  194. make new environment variable with properties {name:"NSDOLoggingEnabled", value:"YES", active:no}
  195. make new environment variable with properties {name:"NSQuitAfterLaunch", value:"YES", active:no}
  196. make new environment variable with properties {name:"CFZombieLevel", value:"3", active:no}
  197. make new environment variable with properties {name:"AEDebugSends", value:"1", active:no}
  198. make new environment variable with properties {name:"AEDebugReceives", value:"1", active:no}
  199. end tell
  200. set active executable to exec
  201. end tell
  202. end tell