makeprojects.applescript 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. global oldDelimiters
  2. global variables
  3. global variablesRef
  4. global bakefilesXML
  5. global bakefilesXMLRef
  6. global projectFile
  7. global osxBuildFolder
  8. property test : false
  9. -- retrieves the files from the xml node including optional conditions
  10. on parseSources(theName, theElement, theVariables, theConditions)
  11. set AppleScript's text item delimiters to " "
  12. set allElements to {}
  13. repeat with currElement in XML contents of theElement
  14. if class of currElement is text then
  15. set allElements to allElements & (every text item of currElement)
  16. else
  17. if class of currElement is XML element and XML tag of currElement is "if" then
  18. if (cond of XML attributes of currElement is in theConditions) then
  19. set allElements to allElements & (every text item of (item 1 of XML contents of currElement))
  20. end if
  21. end if
  22. end if
  23. end repeat
  24. set AppleScript's text item delimiters to oldDelimiters
  25. copy {varname:theName, entries:allElements} to end of theVariables
  26. end parseSources
  27. on parseEntry(theElement, theVariables, theConditions)
  28. set theName to var of XML attributes of theElement
  29. parseSources(theName, theElement, theVariables, theConditions)
  30. end parseEntry
  31. on parseLib(theElement, theVariables, theConditions)
  32. set theName to |id| of XML attributes of theElement
  33. repeat with currElement in XML contents of theElement
  34. if class of currElement is XML element and XML tag of currElement is "sources" then
  35. parseSources(theName, currElement, theVariables, theConditions)
  36. end if
  37. end repeat
  38. end parseLib
  39. on parseNode(anElement, theVariables, theConditions)
  40. if class of anElement is XML element and Â
  41. XML tag of anElement is "set" then
  42. parseEntry(anElement, theVariables, theConditions)
  43. else
  44. if class of anElement is XML element and Â
  45. XML tag of anElement is "lib" then
  46. parseLib(anElement, theVariables, theConditions)
  47. end if
  48. end if
  49. end parseNode
  50. -- iterates through the entire xml tree and populates the variables
  51. on parseFiles(theXML, theVariables, theConditions)
  52. if class of theXML is XML element or class of theXML is XML document then
  53. repeat with anElement in XML contents of theXML
  54. try
  55. parseNode(anElement, theVariables, theConditions)
  56. on error number -1728
  57. -- ignore this error
  58. end try
  59. end repeat
  60. else if class of theXML is list then
  61. repeat with anElement in theXML
  62. try
  63. parseNode(anElement, theVariables, theConditions)
  64. on error number -1728
  65. -- ignore this error
  66. end try
  67. end repeat
  68. end if
  69. end parseFiles
  70. -- gets the entries of the variable named theName
  71. on getVar(theName)
  72. repeat with anElement in variablesRef
  73. if (varname of anElement is theName) then
  74. return entries of anElement
  75. end if
  76. end repeat
  77. end getVar
  78. -- adds sources from fileList to a group named container
  79. on addNode(theContainer, fileList)
  80. tell application "Xcode"
  81. tell project 1
  82. set theTargets to targets
  83. repeat with listItem in fileList
  84. if (listItem starts with "$(") then
  85. set AppleScript's text item delimiters to ""
  86. set variableName to (characters 3 through ((length of listItem) - 1) of listItem) as text
  87. set AppleScript's text item delimiters to oldDelimiters
  88. my addNode(theContainer, my getVar(variableName))
  89. else
  90. set AppleScript's text item delimiters to "/"
  91. set currPath to every text item in listItem
  92. set currFile to "../../" & listItem
  93. set currFileName to (item -1 in currPath)
  94. set currGroup to (items 1 through -2 in currPath as text)
  95. set AppleScript's text item delimiters to oldDelimiters
  96. try
  97. set theGroup to group theContainer
  98. on error
  99. tell root group
  100. make new group with properties {name:theContainer}
  101. end tell
  102. end try
  103. tell group theContainer
  104. try
  105. set theGroup to group named currGroup
  106. on error
  107. make new group with properties {name:currGroup}
  108. end try
  109. tell group currGroup
  110. set newFile to make new file reference with properties {name:currFileName, path:currFile, path type:project relative}
  111. repeat with theTarget in theTargets
  112. add newFile to (get compile sources phase of theTarget)
  113. end repeat
  114. end tell
  115. end tell
  116. end if
  117. end repeat
  118. end tell
  119. end tell
  120. end addNode
  121. -- retrieves contents of file at posixFilePath
  122. on readFile(posixFilePath)
  123. set fileRef to open for access POSIX file posixFilePath
  124. set theData to read fileRef
  125. close access fileRef
  126. return theData
  127. end readFile
  128. on init()
  129. tell application "Xcode"
  130. quit
  131. end tell
  132. set variablesRef to a reference to variables
  133. set bakefilesXMLRef to a reference to bakefilesXML
  134. set oldDelimiters to AppleScript's text item delimiters
  135. tell application "Finder"
  136. set osxBuildFolder to POSIX path of ((folder of (path to me)) as Unicode text)
  137. end tell
  138. end init
  139. -- reads the files list and evaluates the conditions
  140. on readFilesList(theFiles, theConditions)
  141. set variables to {}
  142. repeat with theFile in theFiles
  143. set bakefilesXML to parse XML (readFile(osxBuildFolder & theFile))
  144. parseFiles(bakefilesXMLRef, variablesRef, theConditions)
  145. end repeat
  146. end readFilesList
  147. -- creates a new project file from the respective template
  148. on instantiateProject(theProject)
  149. set projectName to projectName of theProject
  150. set template to (osxBuildFolder & projectName & "_in.xcodeproj")
  151. set projectFile to (osxBuildFolder & projectName & ".xcodeproj")
  152. tell application "Finder"
  153. if exists projectFile as POSIX file then
  154. set templateContentFile to (osxBuildFolder & projectName & "_in.xcodeproj/project.pbxproj")
  155. set projectContentFile to (osxBuildFolder & projectName & ".xcodeproj/project.pbxproj")
  156. try
  157. tell me
  158. do shell script "rm -f " & quoted form of projectContentFile
  159. end tell
  160. end try
  161. try
  162. tell me
  163. do shell script "cp " & quoted form of templateContentFile & " " & quoted form of projectContentFile
  164. end tell
  165. end try
  166. else
  167. set duplicateProject to duplicate (template as POSIX file) with replace
  168. set name of duplicateProject to (projectName & ".xcodeproj")
  169. end if
  170. end tell
  171. end instantiateProject
  172. -- adds the source files of the nodes of theProject to the xcode project
  173. on populateProject(theProject)
  174. tell application "Xcode"
  175. open projectFile
  176. end tell
  177. repeat with theNode in nodes of theProject
  178. -- reopen xcode for each pass, as otherwise the undomanager
  179. -- happens to crash quite frequently
  180. addNode(label of theNode, entries of theNode)
  181. end repeat
  182. tell application "Xcode"
  183. quit
  184. end tell
  185. do shell script (osxBuildFolder as text) & "fix_xcode_ids.py \"" & (POSIX path of projectFile as Unicode text) & "\""
  186. -- reopen again to let Xcode sort identifiers
  187. tell application "Xcode"
  188. open projectFile
  189. end tell
  190. tell application "Xcode"
  191. quit
  192. end tell
  193. end populateProject
  194. on makeProject(theProject)
  195. instantiateProject(theProject)
  196. readFilesList(bklfiles of theProject, conditions of theProject)
  197. populateProject(theProject)
  198. end makeProject
  199. -- main
  200. init()
  201. set theProject to {projectName:"", conditions:{}, bklfiles:{Â
  202. "../bakefiles/files.bkl", "../bakefiles/zlib.bkl", "../bakefiles/regex.bkl", "../bakefiles/tiff.bkl", "../bakefiles/png.bkl", "../bakefiles/jpeg.bkl", "../bakefiles/scintilla.bkl", "../bakefiles/expat.bkl"}, nodes:{Â
  203. {label:"base", entries:{"$(BASE_SRC)"}}, Â
  204. {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, Â
  205. {label:"core", entries:{"$(CORE_SRC)"}}, Â
  206. {label:"net", entries:{"$(NET_SRC)"}}, Â
  207. {label:"adv", entries:{"$(ADVANCED_SRC)"}}, Â
  208. {label:"webview", entries:{"$(WEBVIEW_SRC)"}}, Â
  209. {label:"media", entries:{"$(MEDIA_SRC)"}}, Â
  210. {label:"html", entries:{"$(HTML_SRC)"}}, Â
  211. {label:"xrc", entries:{"$(XRC_SRC)"}}, Â
  212. {label:"xml", entries:{"$(XML_SRC)"}}, Â
  213. {label:"opengl", entries:{"$(OPENGL_SRC)"}}, Â
  214. {label:"aui", entries:{"$(AUI_SRC)"}}, Â
  215. {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, Â
  216. {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, Â
  217. {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, Â
  218. {label:"stc", entries:{"$(STC_SRC)"}}, Â
  219. {label:"libzlib", entries:{"$(wxzlib)"}}, Â
  220. {label:"libtiff", entries:{"$(wxtiff)"}}, Â
  221. {label:"libjpeg", entries:{"$(wxjpeg)"}}, Â
  222. {label:"libpng", entries:{"$(wxpng)"}}, Â
  223. {label:"libregex", entries:{"$(wxregex)"}}, Â
  224. {label:"libscintilla", entries:{"$(wxscintilla)"}}, Â
  225. {label:"libexpat", entries:{"$(wxexpat)"}} Â
  226. }}
  227. set conditions of theProject to {"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_CARBON'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}
  228. set projectName of theProject to "wxcarbon"
  229. makeProject(theProject)
  230. set conditions of theProject to {"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_COCOA'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}
  231. set projectName of theProject to "wxcocoa"
  232. makeProject(theProject)
  233. set conditions of theProject to {"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_IPHONE'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}
  234. set projectName of theProject to "wxiphone"
  235. makeProject(theProject)