wxWidgets/build/osx/makeprojects.applescript
2010-01-03 18:55:00 +00:00

1 line
7.0 KiB
AppleScript

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