changeset 3:d63043d62684

Minor fixes, clean ups, comments to make script more presentable.
author Eric Wing <ewing@anscamobile.com>
date Mon, 01 Aug 2011 15:49:45 -0700
parents 5c54957c04c5
children fdcbf6da59ec
files ScriptingBridge_Xcode.lua
diffstat 1 files changed, 44 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ScriptingBridge_Xcode.lua	Fri Jul 29 18:53:54 2011 -0700
+++ b/ScriptingBridge_Xcode.lua	Mon Aug 01 15:49:45 2011 -0700
@@ -6,6 +6,13 @@
 LuaCocoa.import("ScriptingBridge")
 LuaCocoa.import("Foundation")
 
+-- Not finding through scripting bridge, so adding here
+kAEDefaultTimeout = -1
+kNoTimeOut = -2
+
+-- TODO: Add better 10.6 error handling. 
+-- http://developer.apple.com/library/mac/#releasenotes/ScriptingAutomation/RN-ScriptingBridge/_index.html
+
 function GetURLFromFileAndPath(file_name)
 	local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath()
 
@@ -96,6 +103,7 @@
 	end
 	--]]
 	
+	-- Get the list of build configuration types and then hunt for the one I want.	
 	local array_of_build_configuration_types = xcode_project:buildConfigurationTypes()
 	local desired_build_configuration_type = nil
 	for i=1, #array_of_build_configuration_types do
@@ -108,25 +116,11 @@
 		end
 	end
 
-	local array_of_executables = xcode_project:executables()
-	for i=1, #array_of_executables do
-		print("executables[".. tostring(i) .. "]" ..  array_of_executables[i]:name())
-	end
 
-	local array_of_targets = xcode_project:targets()
-	local active_target = xcode_project:activeTarget()
-	for i=1, #array_of_targets do
-		print("targets[".. tostring(i) .. "]" ..  array_of_targets[i]:name())
-		-- Watch out: __eq (==) always returns false for different types. 
-		local the_name = array_of_targets[i]:name()
-		if tostring(the_name) == "OpenGLES2" then
-			active_target = array_of_targets[i]
-		end
-	end
-	xcode_project:setActiveTarget_(active_target)
 
 	--print("config type", xcode_project:activeBuildConfigurationType():name())
 
+	-- Find out what the current (active) configuration is set to and change it if necessary	
 	-- You are not allowed to create a new instance of XcodeBuildConfigurationType
 	-- Instead, you must use an object returned from the system.
 	-- It appears you cannot use copy or mutableCopy as they throw exceptions.
@@ -142,13 +136,42 @@
 --	print("config type", xcode_project:activeBuildConfigurationType():name())
 
 
+
+	local array_of_targets = xcode_project:targets()
+	local active_target = xcode_project:activeTarget()
+	for i=1, #array_of_targets do
+		print("targets[".. tostring(i) .. "]" ..  array_of_targets[i]:name())
+		-- Watch out: __eq (==) always returns false for different types. 
+		local the_name = array_of_targets[i]:name()
+		if tostring(the_name) == "OpenGLES2" then
+			active_target = array_of_targets[i]
+		end
+	end
+	xcode_project:setActiveTarget_(active_target)
+
+	print("ActiveTarget:", xcode_project:activeTarget():name())
+
+
+
+	local array_of_executables = xcode_project:executables()
+	for i=1, #array_of_executables do
+		print("executables[".. tostring(i) .. "]" ..  array_of_executables[i]:name())
+	end
+
 	local active_executable = xcode_project:activeExecutable()
 	print(active_executable, active_executable:name())
 	active_executable:setName_("OpenGLES2")
 
-	print("ActiveTarget:", xcode_project:activeTarget():name())
 	print("ActiveExecutable:", xcode_project:activeExecutable():name())
-	ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type)
+
+	
+
+	-- Xcode building can take a long time. We don't want Scripting Bridge
+	-- to timeout and move along before the build finishes.
+	-- So disable the timeout.
+	xcode_application:setTimeout_(kNoTimeOut)
+	-- Build the project
+	ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, desired_build_configuration_type)
 
 --	local build_configuration_type = 
 
@@ -157,8 +180,12 @@
 	-- Refetch the object just in case since we tried changing it
 	active_executable = xcode_project:activeExecutable()
 	
+
 	-- launch() doesn't seem to actually work. We must use debug()
 --	local ret_string = active_executable:launch()
+	-- calling debug() seems to hang and never return even when the app exits.
+	-- We probably want the timeout.
+	xcode_application:setTimeout_(kAEDefaultTimeout)
 	local ret_string = active_executable:debug()
 	print(ret_string)