Add project and file hierarchy to PBXGroup

This commit is contained in:
starkos 2009-08-19 20:19:22 +00:00
parent 8bb8fbf149
commit 28cb46f1eb
3 changed files with 66 additions and 42 deletions

View File

@ -76,7 +76,7 @@
-- Xcode merges all of the projects together into a single, logical tree. Assign IDs to
-- all objects and convert paths from project-relative to solution-relative to compensate
local root = tree.new()
local root = tree.new(sln.name)
for prj in premake.eachproject(sln) do
local prjnode = premake.project.buildsourcetree(prj)
tree.insert(root, prjnode)
@ -90,7 +90,7 @@
node.id = xcode.newid()
end,
onleafnode = function(node)
onleaf = function(node)
node.path = path.getrelative(sln.location, path.join(prj.location, node.path))
-- is this a buildable file? Probably needs to be smarter
if path.iscppfile(node.name) then
@ -136,7 +136,7 @@
_p('/* Begin PBXBuildFile section */')
tree.traverse(root, {
onleafnode = function(node)
onleaf = function(node)
if node.buildid then
_p('\t\t%s /* %s in Sources */ = {isa = PBXBuildFile; fileRef = %s /* %s */; };',
node.buildid, node.name, node.id, node.name)
@ -149,9 +149,10 @@
_p('/* Begin PBXFileReference section */')
tree.traverse(root, {
onleafnode = function(node)
_p('\t\t%s /* %s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = %s; path = %s; sourceTree = "<group>"; };',
node.id, node.name, xcode.getfiletype(node.name), node.path)
onleaf = function(node)
_p('\t\t%s /* %s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = %s; name = %s; path = %s; sourceTree = "<group>"; };',
node.id, node.name, xcode.getfiletype(node.name), node.name,
iif(node.parent.path, node.name, node.path))
end
})
for _, target in ipairs(targets) do
@ -175,20 +176,25 @@
_p('/* Begin PBXGroup section */')
for _, prjnode in ipairs(root.children) do
_p('\t\t08FB7794FE84155DC02AAC07 /* %s */ = {', sln.name)
_p('\t\t\tisa = PBXGroup;')
_p('\t\t\tchildren = (')
tree.traverse(prjnode, {
onleafnode = function(node)
_p('\t\t\t\t%s /* %s */,', node.id, node.name)
-- if there is only one project node, hide it by using it as my root
tree.traverse(iif(#root.children == 1, root.children[1], root), {
onbranch = function(node, depth)
-- Xcode has a hardcoded ID for the root group
_p('\t\t%s /* %s */ = {', iif(depth == 0, "08FB7794FE84155DC02AAC07", node.id), node.name)
_p('\t\t\tisa = PBXGroup;')
_p('\t\t\tchildren = (')
for _, child in ipairs(node.children) do
_p('\t\t\t\t%s /* %s */,', child.id, child.name)
end
})
_p('\t\t\t);')
_p('\t\t\tname = %s;', sln.name)
_p('\t\t\tsourceTree = "<group>";')
_p('\t\t};')
end
_p('\t\t\t);')
_p('\t\t\tname = %s;', node.name)
if node.path then
_p('\t\t\tpath = %s;', iif(node.parent.path, node.name, node.path))
end
_p('\t\t\tsourceTree = "<group>";')
_p('\t\t};')
end
}, true)
_p('/* End PBXGroup section */')
_p('')
@ -244,7 +250,7 @@
_p('\t\t\tbuildActionMask = 2147483647;')
_p('\t\t\tfiles = (')
tree.traverse(prjnode, {
onleafnode = function(node)
onleaf = function(node)
if node.buildid then
_p('\t\t\t\t%s /* %s in Sources */,', node.buildid, node.name)
end

View File

@ -17,7 +17,6 @@
for _, fname in ipairs(prj.files) do
local node = premake.tree.add(tr, fname)
node.path = fname
end
return tr

View File

@ -26,25 +26,28 @@
--
-- Add a new node to the tree, or returns the current node if it already exists.
--
-- @param t
-- @param tr
-- The tree to contain the new node.
-- @param name
-- The name of the new node, as a file path
-- @param p
-- The path of the new node.
-- @returns
-- The new tree node.
--
function premake.tree.add(t, name)
local dir = path.getdirectory(name)
function premake.tree.add(tr, p)
-- locate the parent node (or keep the root)
local dir = path.getdirectory(p)
if dir ~= "." then
t = premake.tree.add(t, dir)
name = path.getname(name)
tr = premake.tree.add(tr, dir)
end
local child = t.children[name]
-- add it if it doesn't exist already
local name = path.getname(p)
local child = tr.children[name]
if not child then
child = premake.tree.new(name)
premake.tree.insert(t, child)
child.path = p
premake.tree.insert(tr, child)
end
return child
end
@ -64,6 +67,7 @@
if child.name then
parent.children[child.name] = child
end
child.parent = parent
end
@ -75,21 +79,36 @@
-- @param fn
-- A collection of callback functions, which may contain:
--
-- onnode(node, depth) - called on each node encountered
-- onnode(node, depth) - called on each node encountered
-- onleaf(node, depth) - called only on leaf nodes
-- onbranch(node, depth) - called only on branch nodes
--
-- onleafnode(node, depth) - called only on leaf nodes
-- @param includeroot
-- True to include the root node in the traversal, otherwise it will be skipped.
--
function premake.tree.traverse(t, fn)
local function traversal(t, fn, depth)
for _, node in ipairs(t.children) do
if fn.onnode then fn.onnode(node, depth) end
if #node.children > 0 then
traversal(node, fn, depth + 1)
else
if fn.onleafnode then fn.onleafnode(node, depth) end
end
function premake.tree.traverse(t, fn, includeroot)
local donode, dochildren
donode = function(node, fn, depth)
if fn.onnode then fn.onnode(node, depth) end
if #node.children > 0 then
if fn.onbranch then fn.onbranch(node, depth) end
dochildren(node, fn, depth + 1)
else
if fn.onleaf then fn.onleaf(node, depth) end
end
end
traversal(t, fn, 0)
dochildren = function(parent, fn, depth)
for _, node in ipairs(parent.children) do
donode(node, fn, depth)
end
end
if includeroot then
donode(t, fn, 0)
else
dochildren(t, fn, 0)
end
end