PageRenderTime 39ms CodeModel.GetById 6ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 1ms

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

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