annotate ScriptingBridge_Xcode.lua @ 7:8956367af822

Added ScriptingBridge_iOSSimulatorQuit.lua for Part 4
author Eric Wing <ewing@anscamobile.com>
date Thu, 11 Aug 2011 15:44:58 -0700
parents d63043d62684
children 7a0e6eeedd92
rev   line source
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
1 #!/Library/Frameworks/LuaCocoa.framework/Versions/Current/Tools/luacocoa
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
2 --[[
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
3 Simple Scripting Bridge example using Xcode 3 to demonstrate automated building and running.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
4 --]]
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
5
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
6 LuaCocoa.import("ScriptingBridge")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
7 LuaCocoa.import("Foundation")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
8
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
9 -- Not finding through scripting bridge, so adding here
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
10 kAEDefaultTimeout = -1
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
11 kNoTimeOut = -2
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
12
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
13 -- TODO: Add better 10.6 error handling.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
14 -- http://developer.apple.com/library/mac/#releasenotes/ScriptingAutomation/RN-ScriptingBridge/_index.html
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
15
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
16 function GetURLFromFileAndPath(file_name)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
17 local current_working_directory = NSFileManager:defaultManager():currentDirectoryPath()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
18
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
19 local file_string = NSString:stringWithUTF8String_(file_name):stringByExpandingTildeInPath():stringByStandardizingPath()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
20 if not file_string:isAbsolutePath() then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
21 file_string = current_working_directory:stringByAppendingPathComponent_(file_string):stringByStandardizingPath()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
22 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
23 --print("file_string", file_string)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
24
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
25 local ns_url = NSURL:URLWithString_(file_string:stringByAddingPercentEscapesUsingEncoding_(NSUTF8StringEncoding))
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
26 --print("ns_url", ns_url)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
27
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
28 return ns_url
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
29 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
30
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
31 local xcode_application = SBApplication:applicationWithBundleIdentifier_("com.apple.Xcode")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
32
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
33 if xcode_application ~= nil then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
34 -- arg[0] is the script name
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
35 -- arg[1] is either 'os' or 'simulator'
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
36 -- negative index values represent arguments that come before the script
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
37 -- we only want the arguments after the script name
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
38 -- so use a numeric for
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
39 local file_to_open = arg[1] or "MySampleProject.xcodeproj"
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
40 local url_to_open = GetURLFromFileAndPath(file_to_open)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
41 local xcode_document = xcode_application:open(url_to_open)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
42
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
43 local simulator_or_device = arg[2] or "os"
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
44
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
45 -- The sample project has "Debug" and "Release" configurations to choose from.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
46 local build_configuration_type = "Release"
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
47
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
48 --[[
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
49 local all_documents = xcode_application:projects()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
50
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
51 print(all_documents, #all_documents)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
52 for i=1, #all_documents do
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
53 local a_doc = all_documents[i]
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
54 print("doc", a_doc)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
55 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
56 --]]
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
57
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
58 -- I'm assuming that the document we just opened becomes the activeProjectDocument
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
59 local active_project_document = xcode_application:activeProjectDocument()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
60 print("active_project", active_project_document, active_project_document:name(), active_project_document:path())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
61
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
62
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
63 local xcode_project = active_project_document:project()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
64 print(xcode_project, xcode_project:name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
65
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
66
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
67 -- This could be a problem: activeSDK() is nil. Looks like an Apple bug.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
68 -- Hmmm, Sometimes it works. I don't understand this.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
69 -- iphoneos4.2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
70 -- iphonesimulator4.2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
71 print("activeSDK", xcode_project:activeSDK())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
72 local active_sdk = tostring(xcode_project:activeSDK())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
73 print("active_sdk", active_sdk)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
74
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
75 if not string.match(active_sdk, simulator_or_device) then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
76 if "simulator" == simulator_or_device then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
77 local sdk = string.gsub(active_sdk, "os", "simulator")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
78 print("sdk", sdk)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
79 xcode_project:setActiveSDK(sdk)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
80 else
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
81 local sdk = string.gsub(active_sdk, "simulator", "os")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
82 print("sdk", sdk)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
83 xcode_project:setActiveSDK(sdk)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
84 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
85 print("changed activeSDK", xcode_project:activeSDK())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
86 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
87
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
88
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
89 -- I don't think we need to worry about setting the architexture since we build Universal (fat)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
90 -- However, have seen Xcode get into weird states when switching between simulator and device.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
91 -- Sometimes you need to set this and verify you actually changed it.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
92 -- xcode_project:setActiveArchitecture("armv7")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
93 -- xcode_project:setActiveArchitecture("i386")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
94 -- print("activeArchitecture", xcode_project:activeArchitecture())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
95
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
96
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
97 -- I'm unclear on buildConfigurations vs buildConfigurationTypes
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
98 -- I don't think we need to use buildConfigurations
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
99 --[[
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
100 local array_of_build_configurations = xcode_project:buildConfigurations()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
101 for i=1, #array_of_build_configurations do
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
102 print("buildConfigurations[:".. tostring(i) .. "]" .. array_of_build_configurations[i]:name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
103 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
104 --]]
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
105
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
106 -- Get the list of build configuration types and then hunt for the one I want.
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
107 local array_of_build_configuration_types = xcode_project:buildConfigurationTypes()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
108 local desired_build_configuration_type = nil
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
109 for i=1, #array_of_build_configuration_types do
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
110 print("buildConfigurationType[".. tostring(i) .. "]" .. array_of_build_configuration_types[i]:name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
111 -- Xcode is acting weird. It seems to overwrite entries and replace them, but I don't think it is actually
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
112 -- replacing them. We need to pick the right element.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
113 -- For us, Release is the 2nd position, not the first.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
114 if tostring(array_of_build_configuration_types[i]:name()) == tostring(build_configuration_type) then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
115 desired_build_configuration_type = array_of_build_configuration_types[i]
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
116 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
117 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
118
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
119
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
120
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
121 --print("config type", xcode_project:activeBuildConfigurationType():name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
122
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
123 -- Find out what the current (active) configuration is set to and change it if necessary
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
124 -- You are not allowed to create a new instance of XcodeBuildConfigurationType
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
125 -- Instead, you must use an object returned from the system.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
126 -- It appears you cannot use copy or mutableCopy as they throw exceptions.
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
127 -- XcodeBuildConfigurationType = NSClassFromString("XcodeBuildConfigurationType")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
128 -- local build_configuration_type = XcodeBuildConfigurationType:alloc():init()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
129 -- copy and mutableCopy throw exceptions
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
130 local active_build_configuration_type = xcode_project:activeBuildConfigurationType()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
131 if active_build_configuration_type ~= desired_build_configuration_type then
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
132 print("desired_build_configuration_type", desired_build_configuration_type)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
133 xcode_project:setActiveBuildConfigurationType_(desired_build_configuration_type)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
134 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
135 -- Calling name() sometimes fails and crashes Xcode 3.2.6
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
136 -- print("config type", xcode_project:activeBuildConfigurationType():name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
137
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
138
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
139
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
140 local array_of_targets = xcode_project:targets()
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
141 local active_target = xcode_project:activeTarget()
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
142 for i=1, #array_of_targets do
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
143 print("targets[".. tostring(i) .. "]" .. array_of_targets[i]:name())
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
144 -- Watch out: __eq (==) always returns false for different types.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
145 local the_name = array_of_targets[i]:name()
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
146 if tostring(the_name) == "OpenGLES2" then
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
147 active_target = array_of_targets[i]
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
148 end
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
149 end
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
150 xcode_project:setActiveTarget_(active_target)
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
151
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
152 print("ActiveTarget:", xcode_project:activeTarget():name())
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
153
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
154
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
155
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
156 local array_of_executables = xcode_project:executables()
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
157 for i=1, #array_of_executables do
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
158 print("executables[".. tostring(i) .. "]" .. array_of_executables[i]:name())
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
159 end
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
160
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
161 local active_executable = xcode_project:activeExecutable()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
162 print(active_executable, active_executable:name())
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
163 active_executable:setName_("OpenGLES2")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
164
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
165 print("ActiveExecutable:", xcode_project:activeExecutable():name())
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
166
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
167
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
168
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
169 -- Xcode building can take a long time. We don't want Scripting Bridge
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
170 -- to timeout and move along before the build finishes.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
171 -- So disable the timeout.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
172 xcode_application:setTimeout_(kNoTimeOut)
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
173 -- Build the project
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
174 ret_string = xcode_project:buildStaticAnalysis_transcript_using_(false, false, desired_build_configuration_type)
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
175
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
176 -- local build_configuration_type =
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
177
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
178 print(ret_string)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
179 print("launching...")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
180 -- Refetch the object just in case since we tried changing it
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
181 active_executable = xcode_project:activeExecutable()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
182
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
183
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
184 -- launch() doesn't seem to actually work. We must use debug()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
185 -- local ret_string = active_executable:launch()
3
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
186 -- calling debug() seems to hang and never return even when the app exits.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
187 -- We probably want the timeout.
d63043d62684 Minor fixes, clean ups, comments to make script more presentable.
Eric Wing <ewing@anscamobile.com>
parents: 2
diff changeset
188 xcode_application:setTimeout_(kAEDefaultTimeout)
2
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
189 local ret_string = active_executable:debug()
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
190 print(ret_string)
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
191
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
192
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
193 else
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
194 print("Xcode not available")
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
195 end
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
196
5c54957c04c5 Added ScriptingBridge/LuaCocoa example.
Eric Wing <ewing@anscamobile.com>
parents:
diff changeset
197