Added support for linking system frameworks

This commit is contained in:
starkos 2009-08-28 00:02:36 +00:00
parent 267dab61e2
commit d9d7b89726
3 changed files with 182 additions and 67 deletions

View File

@ -32,6 +32,12 @@
local prjnode = premake.project.buildsourcetree(prj)
tree.insert(ctx.root, prjnode)
-- add virtual groups for resources and frameworks
prjnode.resources = tree.insert(prjnode, tree.new("Resources"))
prjnode.resources.stageid = xcode.newid()
prjnode.frameworks = tree.insert(prjnode, tree.new("Frameworks"))
prjnode.frameworks.stageid = xcode.newid()
-- first pass over the tree to handle resource files like MainMenu.xib. If present,
-- create a new project-level group named "Resources" to contain the files, and
-- virtual groups to contain each language variant. I'm converting how these files
@ -40,28 +46,26 @@
tree.traverse(prjnode, {
onleaf = function(node)
if xcode.islocalized(node) then
-- create a "Resources" folder if necessary
if not prjnode.resources then
prjnode.resources = tree.new("Resources")
tree.insert(prjnode, prjnode.resources)
end
-- create node to represent the file; will become a virtual group later
if not prjnode.resources.children[node.name] then
local group = tree.new(node.name)
group.languages = { }
prjnode.resources.children[node.name] = group
tree.insert(prjnode.resources, group)
end
-- add this language to the group
local lang = path.getbasename(node.parent.name)
prjnode.resources.children[node.name].languages[lang] = node
end
end
})
-- second pass: finish configuring things
-- Create a "Frameworks" group in the project and add any linked frameworks to it
for _, link in ipairs(prj.links) do
if xcode.isframework(link) then
tree.add(prjnode.frameworks, link)
end
end
-- Second pass over the tree to finish configuring things
tree.traverse(prjnode, {
onnode = function(node)
-- assign IDs to all nodes in the tree
@ -84,7 +88,6 @@
}, true)
end
-- Targets live outside the main source tree. In general there is one target per Premake
-- project; projects with multiple kinds require multiple targets, one for each kind
ctx.targets = { }
@ -100,8 +103,7 @@
name = prjnode.project.name .. path.getextension(cfg.buildtarget.name),
id = xcode.newid(),
fileid = xcode.newid(),
sourcesid = xcode.newid(),
frameworksid = xcode.newid()
sourcesid = xcode.newid()
})
-- mark this kind as done
@ -151,6 +153,7 @@
[".cc" ] = "Sources",
[".cpp" ] = "Sources",
[".cxx" ] = "Sources",
[".framework"] = "Frameworks",
[".m" ] = "Sources",
[".xib" ] = "Resources",
}
@ -174,6 +177,7 @@
[".cpp" ] = "sourcecode.cpp.cpp",
[".css" ] = "text.css",
[".cxx" ] = "sourcecode.cpp.cpp",
[".framework"] = "wrapper.framework",
[".gif" ] = "image.gif",
[".h" ] = "sourcecode.c.h",
[".html"] = "text.html",
@ -221,7 +225,6 @@
--
-- Returns true if a node represents a localized file.
--
--
function xcode.islocalized(node)
@ -241,6 +244,15 @@
end
--
-- Returns true if the file name represents a framework.
--
function xcode.isframework(fname)
return (path.getextension(fname) == ".framework")
end
--
-- Retrieves a unique 12 byte ID for an object.
--
@ -319,10 +331,13 @@
onleaf = function(node)
if not node.path then return end
local nodename, nodepath, encoding
local nodename, nodepath, encoding, source
if xcode.islocalized(node) then
nodename = path.getbasename(node.parent.name)
nodepath = path.join(tree.getlocalpath(node.parent), node.name)
elseif xcode.isframework(node.name) then
nodepath = "/System/Library/Frameworks/" .. node.name -- this obviously needs to change
source = "<absolute>"
else
encoding = " fileEncoding = 4;"
end
@ -330,9 +345,10 @@
nodename = nodename or node.name
nodepath = nodepath or tree.getlocalpath(node)
encoding = encoding or ""
source = source or "<group>"
_p(2,'%s /* %s */ = {isa = PBXFileReference;%s lastKnownFileType = %s; name = %s; path = %s; sourceTree = "<group>"; };',
node.id, nodename, encoding, xcode.getfiletype(node.name), nodename, nodepath)
_p(2,'%s /* %s */ = {isa = PBXFileReference;%s lastKnownFileType = %s; name = %s; path = %s; sourceTree = "%s"; };',
node.id, nodename, encoding, xcode.getfiletype(node.name), nodename, nodepath, source)
end
})
for _, target in ipairs(ctx.targets) do
@ -344,6 +360,25 @@
end
function xcode.PBXFrameworksBuildPhase(ctx)
_p('/* Begin PBXFrameworksBuildPhase section */')
for _, target in ipairs(ctx.targets) do
_p(2,'%s /* Frameworks */ = {', target.prjnode.frameworks.stageid)
_p(3,'isa = PBXFrameworksBuildPhase;')
_p(3,'buildActionMask = 2147483647;')
_p(3,'files = (')
for _, framework in ipairs(target.prjnode.frameworks.children) do
_p(4,'%s /* %s in Frameworks */,', framework.buildid, framework.name)
end
_p(3,');')
_p(3,'runOnlyForDeploymentPostprocessing = 0;')
_p(2,'};')
end
_p('/* End PBXFrameworksBuildPhase section */')
_p('')
end
function xcode.PBXGroup(ctx)
_p('/* Begin PBXGroup section */')
@ -421,21 +456,7 @@
xcode.header()
xcode.PBXBuildFile(ctx)
xcode.PBXFileReference(ctx)
_p('/* Begin PBXFrameworksBuildPhase section */')
for _, target in ipairs(ctx.targets) do
_p(2,'%s /* Frameworks */ = {', target.frameworksid)
_p(3,'isa = PBXFrameworksBuildPhase;')
_p(3,'buildActionMask = 2147483647;')
_p(3,'files = (')
_p(3,');')
_p(3,'runOnlyForDeploymentPostprocessing = 0;')
_p(2,'};')
end
_p('/* End PBXFrameworksBuildPhase section */')
_p('')
xcode.PBXFrameworksBuildPhase(ctx)
xcode.PBXGroup(ctx)
@ -445,8 +466,9 @@
_p(3,'isa = PBXNativeTarget;')
_p(3,'buildConfigurationList = %s /* Build configuration list for PBXNativeTarget "%s" */;', target.cfgsectionid, target.name)
_p(3,'buildPhases = (')
_p(4,'%s /* Resources */,', target.prjnode.resources.stageid)
_p(4,'%s /* Sources */,', target.sourcesid)
_p(4,'%s /* Frameworks */,', target.frameworksid)
_p(4,'%s /* Frameworks */,', target.prjnode.frameworks.stageid)
_p(3,');')
_p(3,'buildRules = (')
_p(3,');')
@ -458,7 +480,7 @@
_p(3,'productType = "%s";', xcode.getproducttype(target.kind))
_p(2,'};')
end
_p('/* End PBXProject section */')
_p('/* End PBXNativeTarget section */')
_p('')
@ -480,6 +502,21 @@
_p('/* End PBXProject section */')
_p('')
_p('/* Begin PBXResourcesBuildPhase section */')
for _, target in ipairs(ctx.targets) do
_p(2,'%s /* Resources */ = {', target.prjnode.resources.stageid)
_p(3,'isa = PBXResourcesBuildPhase;')
_p(3,'buildActionMask = 2147483647;')
_p(3,'files = (')
for _, resource in ipairs(target.prjnode.resources.children) do
_p(4,'%s /* %s in Resources */,', resource.buildid, resource.name)
end
_p(3,');')
_p(3,'runOnlyForDeploymentPostprocessing = 0;')
_p(2,'};')
end
_p('/* End PBXResourcesBuildPhase section */')
_p('')
_p('/* Begin PBXSourcesBuildPhase section */')
for _, target in ipairs(ctx.targets) do
@ -489,7 +526,7 @@
_p(3,'files = (')
tree.traverse(target.prjnode, {
onleaf = function(node)
if node.buildid then
if xcode.getfilecategory(node.name) == "Sources" then
_p(4,'%s /* %s in Sources */,', node.buildid, node.name)
end
end

View File

@ -68,6 +68,7 @@
parent.children[child.name] = child
end
child.parent = parent
return child
end

View File

@ -25,10 +25,8 @@
kind "ConsoleApp"
old_newid = xcode.newid
local next_id = 0
xcode.newid = function()
next_id = next_id + 1
return string.format("%012d", next_id)
return string.format("000000000000")
end
end
@ -85,7 +83,7 @@
-- PBXBuildFile section tests
--
function T.xcode3.PBXBuildFile_ListsBuildableFiles()
function T.xcode3.PBXBuildFile_ListsBuildableSources()
files {
"source.h", "source.c", "source.cpp",
}
@ -93,8 +91,8 @@
xcode.PBXBuildFile(ctx)
test.capture [[
/* Begin PBXBuildFile section */
000000000005 /* source.c in Sources */ = {isa = PBXBuildFile; fileRef = 000000000004 /* source.c */; };
000000000007 /* source.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 000000000006 /* source.cpp */; };
000000000000 /* source.c in Sources */ = {isa = PBXBuildFile; fileRef = 000000000000 /* source.c */; };
000000000000 /* source.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 000000000000 /* source.cpp */; };
/* End PBXBuildFile section */
]]
end
@ -108,7 +106,7 @@
xcode.PBXBuildFile(ctx)
test.capture [[
/* Begin PBXBuildFile section */
000000000011 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000010 /* MainMenu.xib */; };
000000000000 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000000 /* MainMenu.xib */; };
/* End PBXBuildFile section */
]]
end
@ -122,13 +120,26 @@
xcode.PBXBuildFile(ctx)
test.capture [[
/* Begin PBXBuildFile section */
000000000012 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000011 /* MainMenu.xib */; };
000000000023 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000022 /* MainMenu.xib */; };
000000000000 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000000 /* MainMenu.xib */; };
000000000000 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 000000000000 /* MainMenu.xib */; };
/* End PBXBuildFile section */
]]
end
function T.xcode3.PBXBuildFile_ListsFrameworks()
links { "Cocoa.framework" }
prepare()
xcode.PBXBuildFile(ctx)
test.capture [[
/* Begin PBXBuildFile section */
000000000000 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 000000000000 /* Cocoa.framework */; };
/* End PBXBuildFile section */
]]
end
--
-- PBXFileReference section tests
--
@ -138,7 +149,7 @@
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000004 /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyProject; sourceTree = BUILT_PRODUCTS_DIR; };
000000000000 /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyProject; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
]]
end
@ -152,9 +163,9 @@
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000003 /* source.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = source.h; path = source.h; sourceTree = "<group>"; };
000000000004 /* source.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = source.c; path = source.c; sourceTree = "<group>"; };
000000000006 /* source.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = source.cpp; path = source.cpp; sourceTree = "<group>"; };
000000000000 /* source.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = source.h; path = source.h; sourceTree = "<group>"; };
000000000000 /* source.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = source.c; path = source.c; sourceTree = "<group>"; };
000000000000 /* source.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = source.cpp; path = source.cpp; sourceTree = "<group>"; };
]]
end
@ -167,8 +178,8 @@
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000004 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000007 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
]]
end
@ -181,10 +192,62 @@
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000005 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000008 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000016 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000019 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
000000000000 /* French */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = French; path = French.lproj/MainMenu.xib; sourceTree = "<group>"; };
]]
end
function T.xcode3.PBXFileReference_ListFrameworksCorrectly()
links { "Cocoa.framework" }
prepare()
xcode.PBXFileReference(ctx)
test.capture [[
/* Begin PBXFileReference section */
000000000000 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
]]
end
--
-- PBXFrameworksBuildPhase section tests
--
function T.xcode3.PBXFrameworksBuild_OnNoFiles()
prepare()
xcode.PBXFrameworksBuildPhase(ctx)
test.capture [[
/* Begin PBXFrameworksBuildPhase section */
000000000000 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
]]
end
function T.xcode3.PBXFrameworksBuild_ListsFrameworksCorrectly()
links { "Cocoa.framework" }
prepare()
xcode.PBXFrameworksBuildPhase(ctx)
test.capture [[
/* Begin PBXFrameworksBuildPhase section */
000000000000 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
000000000000 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
]]
end
@ -198,6 +261,15 @@
xcode.PBXGroup(ctx)
test.capture [[
/* Begin PBXGroup section */
000000000000 /* MyProject */ = {
isa = PBXGroup;
children = (
000000000000 /* Resources */,
000000000000 /* Frameworks */,
);
name = MyProject;
sourceTree = "<group>";
};
/* End PBXGroup section */
]]
end
@ -209,10 +281,12 @@
xcode.PBXGroup(ctx)
test.capture [[
/* Begin PBXGroup section */
000000000002 /* MyProject */ = {
000000000000 /* MyProject */ = {
isa = PBXGroup;
children = (
000000000003 /* source.h */,
000000000000 /* source.h */,
000000000000 /* Resources */,
000000000000 /* Frameworks */,
);
name = MyProject;
sourceTree = "<group>";
@ -228,18 +302,20 @@
xcode.PBXGroup(ctx)
test.capture [[
/* Begin PBXGroup section */
000000000002 /* MyProject */ = {
000000000000 /* MyProject */ = {
isa = PBXGroup;
children = (
000000000003 /* include */,
000000000000 /* include */,
000000000000 /* Resources */,
000000000000 /* Frameworks */,
);
name = MyProject;
sourceTree = "<group>";
};
000000000003 /* include */ = {
000000000000 /* include */ = {
isa = PBXGroup;
children = (
000000000004 /* source.h */,
000000000000 /* source.h */,
);
name = include;
path = include;
@ -256,18 +332,19 @@
xcode.PBXGroup(ctx)
test.capture [[
/* Begin PBXGroup section */
000000000002 /* MyProject */ = {
000000000000 /* MyProject */ = {
isa = PBXGroup;
children = (
000000000009 /* Resources */,
000000000000 /* Resources */,
000000000000 /* Frameworks */,
);
name = MyProject;
sourceTree = "<group>";
};
000000000009 /* Resources */ = {
000000000000 /* Resources */ = {
isa = PBXGroup;
children = (
000000000010 /* MainMenu.xib */,
000000000000 /* MainMenu.xib */,
);
name = Resources;
sourceTree = "<group>";
@ -290,11 +367,11 @@
xcode.PBXVariantGroup(ctx)
test.capture [[
/* Begin PBXVariantGroup section */
000000000010 /* MainMenu.xib */ = {
000000000000 /* MainMenu.xib */ = {
isa = PBXVariantGroup;
children = (
000000000007 /* French */,
000000000004 /* English */,
000000000000 /* French */,
000000000000 /* English */,
);
name = MainMenu.xib;
sourceTree = "<group>";