building xcode projects from files.bkl
[wxWidgets.git] / build / osx / makeprojects.applescript
1 global oldDelimiters\rglobal variables\rglobal variablesRef\rglobal bakefilesXML\rglobal bakefilesXMLRef\r\rglobal osxBuildFolder\r\rproperty test : false\r\r-- retrieves the files from the xml node including optional conditions\ron parseEntry(theElement, theVariables, theConditions)\r   set AppleScript's text item delimiters to " "\r  set theName to var of XML attributes of theElement\r     set allElements to {}\r  repeat with currElement in XML contents of theElement\r          if class of currElement is text then\r                   set allElements to allElements & (every text item of currElement)\r              else\r                   if class of currElement is XML element and XML tag of currElement is "if" then\r                         if (cond of XML attributes of currElement is in theConditions) then\r                                    set allElements to allElements & (every text item of (item 1 of XML contents of currElement))\r                          end if\r                 end if\r         end if\r end repeat\r     set AppleScript's text item delimiters to oldDelimiters\r        copy {varname:theName, entries:allElements} to end of theVariables\rend parseEntry\r\r-- iterates through the entire xml tree and populates the variables\ron parseFiles(theXML, theVariables, theConditions)\r      if class of theXML is XML element or class of theXML is XML document then\r              repeat with anElement in XML contents of theXML\r                        try\r                            if class of anElement is XML element and ¬\r                                    XML tag of anElement is "set" then\r                                     parseEntry(anElement, theVariables, theConditions)\r                             end if\r                 on error number -1728\r                          -- ignore this error\r                   end try\r                end repeat\r     else if class of theXML is list then\r           repeat with anElement in theXML\r                        try\r                            if class of anElement is XML element and ¬\r                                    XML tag of anElement is "set" and ¬\r                                   var of XML attributes of anElement is theName then\r                                     parseEntry(anElement, theVariables, theConditions)\r                             end if\r                 on error number -1728\r                          -- ignore this error\r                   end try\r                end repeat\r     end if\rend parseFiles\r\r-- gets the entries of the variable named theName\ron getVar(theName)\r    repeat with anElement in variablesRef\r          if (varname of anElement is theName) then\r                      return entries of anElement\r            end if\r end repeat\rend getVar\r\r-- adds sources from fileList to a group named container\ron addNode(container, fileList)\r        repeat with listItem in fileList\r               if (listItem starts with "$(") then\r                    set AppleScript's text item delimiters to ""\r                   set variableName to (characters 3 through ((length of listItem) - 1) of listItem) as text\r                      set AppleScript's text item delimiters to oldDelimiters\r                        addNode(container, getVar(variableName))\r               else\r                   tell application "Xcode"\r                               tell project 1\r                                 set theTargets to targets\r                                      set AppleScript's text item delimiters to "/"\r                                  set currPath to every text item in listItem\r                                    set currFile to "../../" & listItem\r                                    set currFileName to (item -1 in currPath)\r                                      set currGroup to (items 1 through -2 in currPath as text)\r                                      set AppleScript's text item delimiters to oldDelimiters\r                                        try\r                                            set theGroup to group named container\r                                  on error\r                                               tell root group\r                                                        make new group with properties {name:container}\r                                                end tell\r                                       end try\r                                        tell group container\r                                           try\r                                                    set theGroup to group named currGroup\r                                          on error\r                                                       make new group with properties {name:currGroup}\r                                                end try\r                                                tell group currGroup\r                                                   set newFile to make new file reference with properties {name:currFileName, path:currFile, path type:project relative}\r                                                  repeat with theTarget in theTargets\r                                                            add newFile to (get compile sources phase of theTarget)\r                                                        end repeat\r                                             end tell\r                                       end tell\r                               end tell\r                       end tell\r               end if\r end repeat\rend addNode\r\r-- retrieves contents of file at posixFilePath\ron readFile(posixFilePath)\r      set fileRef to open for access POSIX file posixFilePath\r        set theData to read fileRef\r    close access fileRef\r   return theData\rend readFile\r\ron init()\r tell application "Xcode"\r               quit\r   end tell\r       set variablesRef to a reference to variables\r   set bakefilesXMLRef to a reference to bakefilesXML\r     set oldDelimiters to AppleScript's text item delimiters\r        tell application "Finder"\r              set osxBuildFolder to POSIX path of ((folder of (path to me)) as Unicode text)\r end tell\rend init\r\r-- reads the files list and evaluates the conditions\ron readFilesList(theConditions)\r        set variables to {}\r    set bakefilesXML to parse XML (readFile(osxBuildFolder & "../bakefiles/files.bkl"))\r    parseFiles(bakefilesXMLRef, variablesRef, theConditions)\rend readFilesList\r\r-- creates a new project file from the respective template\ron instantiateProject(theProject)\r       set projectName to projectName of theProject\r   set template to POSIX file (osxBuildFolder & projectName & "_in.xcodeproj")\r    set newFile to POSIX file (osxBuildFolder & projectName & ".xcodeproj")\r        tell application "Finder"\r              try\r                    delete file newFile\r            end try\r                set duplicateProject to duplicate template with replace\r                set name of duplicateProject to (projectName & ".xcodeproj")\r   end tell\r       tell application "Xcode"\r               open newFile\r   end tell\rend instantiateProject\r\r-- adds the source files of the nodes of theProject to the xcode project\ron populateProject(theProject)\r       repeat with theNode in nodes of theProject\r             addNode(label of theNode, entries of theNode)\r  end repeat\r     tell application "Xcode"\r               quit\r   end tell\rend populateProject\r\ron makeProject(theProject)\r       instantiateProject(theProject)\r readFilesList(conditions of theProject)\r        populateProject(theProject)\rend makeProject\r\r-- main\r\rinit()\rset theProject to {conditions:{"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_CARBON'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}, projectName:¬\r    "wxcarbon", nodes:{¬\r  {label:"base", entries:{"$(BASE_SRC)"}}, ¬\r    {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, ¬\r    {label:"core", entries:{"$(CORE_SRC)"}}, ¬\r    {label:"net", entries:{"$(NET_SRC)"}}, ¬\r      {label:"adv", entries:{"$(ADVANCED_SRC)"}}, ¬\r {label:"media", entries:{"$(MEDIA_SRC)"}}, ¬\r  {label:"html", entries:{"$(HTML_SRC)"}}, ¬\r    {label:"xrc", entries:{"$(XRC_SRC)"}}, ¬\r      {label:"xml", entries:{"$(XML_SRC)"}}, ¬\r      {label:"opengl", entries:{"$(OPENGL_SRC)"}}, ¬\r        {label:"aui", entries:{"$(AUI_SRC)"}}, ¬\r      {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, ¬\r        {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, ¬\r    {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, ¬\r    {label:"stc", entries:{"$(STC_SRC)"}}}}\rmakeProject(theProject)\r\rset theProject to {conditions:{"PLATFORM_MACOSX=='1'", "TOOLKIT=='OSX_COCOA'", "WXUNIV=='0'", "USE_GUI=='1' and WXUNIV=='0'"}, projectName:¬\r "wxcocoa", nodes:{¬\r   {label:"base", entries:{"$(BASE_SRC)"}}, ¬\r    {label:"base", entries:{"$(BASE_AND_GUI_SRC)"}}, ¬\r    {label:"core", entries:{"$(CORE_SRC)"}}, ¬\r    {label:"net", entries:{"$(NET_SRC)"}}, ¬\r      {label:"adv", entries:{"$(ADVANCED_SRC)"}}, ¬\r {label:"media", entries:{"$(MEDIA_SRC)"}}, ¬\r  {label:"html", entries:{"$(HTML_SRC)"}}, ¬\r    {label:"xrc", entries:{"$(XRC_SRC)"}}, ¬\r      {label:"xml", entries:{"$(XML_SRC)"}}, ¬\r      {label:"opengl", entries:{"$(OPENGL_SRC)"}}, ¬\r        {label:"aui", entries:{"$(AUI_SRC)"}}, ¬\r      {label:"ribbon", entries:{"$(RIBBON_SRC)"}}, ¬\r        {label:"propgrid", entries:{"$(PROPGRID_SRC)"}}, ¬\r    {label:"richtext", entries:{"$(RICHTEXT_SRC)"}}, ¬\r    {label:"stc", entries:{"$(STC_SRC)"}}}}\rmakeProject(theProject)\r\r\r