comparison ScriptingBridge_Xcode.lua @ 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 7a0e6eeedd92
comparison
equal deleted inserted replaced
2:5c54957c04c5 3:d63043d62684
3 Simple Scripting Bridge example using Xcode 3 to demonstrate automated building and running. 3 Simple Scripting Bridge example using Xcode 3 to demonstrate automated building and running.
4 --]] 4 --]]
5 5
6 LuaCocoa.import("ScriptingBridge") 6 LuaCocoa.import("ScriptingBridge")
7 LuaCocoa.import("Foundation") 7 LuaCocoa.import("Foundation")
8
9 -- Not finding through scripting bridge, so adding here
10 kAEDefaultTimeout = -1
11 kNoTimeOut = -2
12
13 -- TODO: Add better 10.6 error handling.
14 -- http://developer.apple.com/library/mac/#releasenotes/ScriptingAutomation/RN-ScriptingBridge/_index.html
8 15
9 function GetURLFromFileAndPath(file_name) 16 function GetURLFromFileAndPath(file_name)
10 local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath() 17 local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath()
11 18
12 local file_string = NSString:stringWithUTF8String_(file_name):stringByExpandingTildeInPath():stringByStandardizingPath() 19 local file_string = NSString:stringWithUTF8String_(file_name):stringByExpandingTildeInPath():stringByStandardizingPath()
94 for i=1, #array_of_build_configurations do 101 for i=1, #array_of_build_configurations do
95 print("buildConfigurations[:".. tostring(i) .. "]" .. array_of_build_configurations[i]:name()) 102 print("buildConfigurations[:".. tostring(i) .. "]" .. array_of_build_configurations[i]:name())
96 end 103 end
97 --]] 104 --]]
98 105
106 -- Get the list of build configuration types and then hunt for the one I want.
99 local array_of_build_configuration_types = xcode_project:buildConfigurationTypes() 107 local array_of_build_configuration_types = xcode_project:buildConfigurationTypes()
100 local desired_build_configuration_type = nil 108 local desired_build_configuration_type = nil
101 for i=1, #array_of_build_configuration_types do 109 for i=1, #array_of_build_configuration_types do
102 print("buildConfigurationType[".. tostring(i) .. "]" .. array_of_build_configuration_types[i]:name()) 110 print("buildConfigurationType[".. tostring(i) .. "]" .. array_of_build_configuration_types[i]:name())
103 -- Xcode is acting weird. It seems to overwrite entries and replace them, but I don't think it is actually 111 -- Xcode is acting weird. It seems to overwrite entries and replace them, but I don't think it is actually
106 if tostring(array_of_build_configuration_types[i]:name()) == tostring(build_configuration_type) then 114 if tostring(array_of_build_configuration_types[i]:name()) == tostring(build_configuration_type) then
107 desired_build_configuration_type = array_of_build_configuration_types[i] 115 desired_build_configuration_type = array_of_build_configuration_types[i]
108 end 116 end
109 end 117 end
110 118
111 local array_of_executables = xcode_project:executables()
112 for i=1, #array_of_executables do
113 print("executables[".. tostring(i) .. "]" .. array_of_executables[i]:name())
114 end
115 119
116 local array_of_targets = xcode_project:targets()
117 local active_target = xcode_project:activeTarget()
118 for i=1, #array_of_targets do
119 print("targets[".. tostring(i) .. "]" .. array_of_targets[i]:name())
120 -- Watch out: __eq (==) always returns false for different types.
121 local the_name = array_of_targets[i]:name()
122 if tostring(the_name) == "OpenGLES2" then
123 active_target = array_of_targets[i]
124 end
125 end
126 xcode_project:setActiveTarget_(active_target)
127 120
128 --print("config type", xcode_project:activeBuildConfigurationType():name()) 121 --print("config type", xcode_project:activeBuildConfigurationType():name())
129 122
123 -- Find out what the current (active) configuration is set to and change it if necessary
130 -- You are not allowed to create a new instance of XcodeBuildConfigurationType 124 -- You are not allowed to create a new instance of XcodeBuildConfigurationType
131 -- Instead, you must use an object returned from the system. 125 -- Instead, you must use an object returned from the system.
132 -- It appears you cannot use copy or mutableCopy as they throw exceptions. 126 -- It appears you cannot use copy or mutableCopy as they throw exceptions.
133 -- XcodeBuildConfigurationType = NSClassFromString("XcodeBuildConfigurationType") 127 -- XcodeBuildConfigurationType = NSClassFromString("XcodeBuildConfigurationType")
134 -- local build_configuration_type = XcodeBuildConfigurationType:alloc():init() 128 -- local build_configuration_type = XcodeBuildConfigurationType:alloc():init()
140 end 134 end
141 -- Calling name() sometimes fails and crashes Xcode 3.2.6 135 -- Calling name() sometimes fails and crashes Xcode 3.2.6
142 -- print("config type", xcode_project:activeBuildConfigurationType():name()) 136 -- print("config type", xcode_project:activeBuildConfigurationType():name())
143 137
144 138
139
140 local array_of_targets = xcode_project:targets()
141 local active_target = xcode_project:activeTarget()
142 for i=1, #array_of_targets do
143 print("targets[".. tostring(i) .. "]" .. array_of_targets[i]:name())
144 -- Watch out: __eq (==) always returns false for different types.
145 local the_name = array_of_targets[i]:name()
146 if tostring(the_name) == "OpenGLES2" then
147 active_target = array_of_targets[i]
148 end
149 end
150 xcode_project:setActiveTarget_(active_target)
151
152 print("ActiveTarget:", xcode_project:activeTarget():name())
153
154
155
156 local array_of_executables = xcode_project:executables()
157 for i=1, #array_of_executables do
158 print("executables[".. tostring(i) .. "]" .. array_of_executables[i]:name())
159 end
160
145 local active_executable = xcode_project:activeExecutable() 161 local active_executable = xcode_project:activeExecutable()
146 print(active_executable, active_executable:name()) 162 print(active_executable, active_executable:name())
147 active_executable:setName_("OpenGLES2") 163 active_executable:setName_("OpenGLES2")
148 164
149 print("ActiveTarget:", xcode_project:activeTarget():name())
150 print("ActiveExecutable:", xcode_project:activeExecutable():name()) 165 print("ActiveExecutable:", xcode_project:activeExecutable():name())
151 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, build_configuration_type) 166
167
168
169 -- Xcode building can take a long time. We don't want Scripting Bridge
170 -- to timeout and move along before the build finishes.
171 -- So disable the timeout.
172 xcode_application:setTimeout_(kNoTimeOut)
173 -- Build the project
174 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, desired_build_configuration_type)
152 175
153 -- local build_configuration_type = 176 -- local build_configuration_type =
154 177
155 print(ret_string) 178 print(ret_string)
156 print("launching...") 179 print("launching...")
157 -- Refetch the object just in case since we tried changing it 180 -- Refetch the object just in case since we tried changing it
158 active_executable = xcode_project:activeExecutable() 181 active_executable = xcode_project:activeExecutable()
159 182
183
160 -- launch() doesn't seem to actually work. We must use debug() 184 -- launch() doesn't seem to actually work. We must use debug()
161 -- local ret_string = active_executable:launch() 185 -- local ret_string = active_executable:launch()
186 -- calling debug() seems to hang and never return even when the app exits.
187 -- We probably want the timeout.
188 xcode_application:setTimeout_(kAEDefaultTimeout)
162 local ret_string = active_executable:debug() 189 local ret_string = active_executable:debug()
163 print(ret_string) 190 print(ret_string)
164 191
165 192
166 else 193 else