Add .xib file resources

This commit is contained in:
starkos 2009-08-24 21:42:14 +00:00
parent 874ac5599f
commit 1b00abd12c
4 changed files with 107 additions and 30 deletions

View File

@ -47,7 +47,7 @@
end
-- assign a build ID to buildable files
if xcode.isbuildable(node.name) then
if xcode.getfilecategory(node.name) then
node.buildid = xcode.newid()
end
end
@ -96,8 +96,32 @@
return ctx
end
--
-- Return the Xcode category (for lack of a better term) for a file, such
-- as "Sources" or "Resources".
--
-- @param fname
-- The file name to identify.
-- @returns
-- An Xcode file category, string.
--
function xcode.getfilecategory(fname)
print("Category for ", fname)
local categories = {
[".c" ] = "Sources",
[".cc" ] = "Sources",
[".cpp" ] = "Sources",
[".cxx" ] = "Sources",
[".m" ] = "Sources",
[".xib" ] = "Resources",
}
return categories[path.getextension(fname)]
end
--
-- Return the Xcode type for a given file, based on the file extension.
--
@ -119,9 +143,9 @@
[".html"] = "text.html",
[".lua" ] = "sourcecode.lua",
[".m" ] = "sourcecode.c.objc",
[".xib" ] = "file.xib",
}
return types[path.getextension(fname)] or "text"
end
@ -159,25 +183,6 @@
end
--
-- Returns true if Xcode considers the specified file to be "buildable".
--
-- @param fname
-- The name of the file under consideration.
--
function xcode.isbuildable(fname)
local buildable = {
[".c" ] = true,
[".cc" ] = true,
[".cpp"] = true,
[".cxx"] = true,
[".m" ] = true,
}
return buildable[path.getextension(fname)]
end
--
-- Retrieves a unique 12 byte ID for an object.
--
@ -238,8 +243,8 @@
tree.traverse(ctx.root, {
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)
_p('\t\t%s /* %s in %s */ = {isa = PBXBuildFile; fileRef = %s /* %s */; };',
node.buildid, node.name, xcode.getfilecategory(node.name), node.id, node.name)
end
end
})
@ -252,9 +257,22 @@
_p('/* Begin PBXFileReference section */')
tree.traverse(ctx.root, {
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))
if xcode.getfilecategory(node.name) == "Resources" then
if path.getextension(node.parent.name) == ".lproj" then
-- localized resource
local lang = path.getbasename(node.parent.name)
_p('\t\t%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = %s; name = %s; path = %s; sourceTree = "<group>"; };',
node.id, lang, xcode.getfiletype(node.name), lang, path.join(tree.getlocalpath(node.parent), node.name))
else
-- non-localized resource
_p('\t\t%s /* %s */ = {isa = PBXFileReference; lastKnownFileType = %s; name = %s; path = %s; sourceTree = "<group>"; };',
node.id, node.name, xcode.getfiletype(node.name), node.name, tree.getlocalpath(node))
end
else
-- non-resource 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, tree.getlocalpath(node))
end
end
})
for _, target in ipairs(ctx.targets) do

View File

@ -71,6 +71,23 @@
end
--
-- Gets the node's relative path from it's parent. If the parent does not have
-- a path set (it is the root or other container node) returns the full node path.
--
-- @param node
-- The node to query.
--
function premake.tree.getlocalpath(node)
if node.parent.path then
return node.name
else
return node.path
end
end
--
-- Traverse a tree.
--

View File

@ -78,7 +78,7 @@
-- PBXBuildFile section tests
--
function T.xcode3.PBXBuildFile_ListsAllBuildableFiles()
function T.xcode3.PBXBuildFile_ListsBuildableFiles()
files {
"source.h",
"source.c",
@ -94,12 +94,25 @@
]]
end
function T.xcode3.PBXBuildFile_ListsResourceFiles()
files {
"source.h",
"English.lproj/MainMenu.xib",
}
prepare()
xcode.PBXBuildFile(ctx)
test.capture [[
/* Begin PBXBuildFile section */
000000000006 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000005 /* MainMenu.xib */; };
/* End PBXBuildFile section */
]]
end
--
-- PBXFileReference section tests
--
function T.xcode3.PBXFileReference_ListAllFileTypesCorrectly()
function T.xcode3.PBXFileReference_ListSourceTypesCorrectly()
files {
"source.h", "source.c"
}
@ -113,3 +126,15 @@
/* End PBXFileReference section */
]]
end
function T.xcode3.PBXFileReference_ListResourcesCorrectly()
files {
"English.lproj/MainMenu.xib"
}
prepare()
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000004 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
]]
end

View File

@ -67,3 +67,20 @@
getresult())
end
--
-- Tests for tree.getlocalpath()
--
function T.tree.GetLocalPath_ReturnsPath_OnNoParentPath()
local c = tree.add(tr, "Root/Child")
c.parent.path = nil
test.isequal("Root/Child", tree.getlocalpath(c))
end
function T.tree.GetLocalPath_ReturnsName_OnParentPathSet()
local c = tree.add(tr, "Root/Child")
test.isequal("Child", tree.getlocalpath(c))
end