Finished porting

This commit is contained in:
starkos 2009-11-09 21:34:46 +00:00
parent 0273520f02
commit eef1a97501
7 changed files with 46 additions and 269 deletions

View File

@ -64,7 +64,6 @@
"actions/xcode/xcode_common.lua",
"actions/xcode/xcode_solution.lua",
"actions/xcode/xcode_project.lua",
"actions/xcode/xcode_pbxproj.lua",
-- Clean action
"actions/clean/_clean.lua",

View File

@ -65,6 +65,23 @@
end
--
-- Return the default installation path, based target kind.
--
-- @param cfg
-- The configuration to query.
-- @returns
-- The install path, string.
--
function xcode.getinstallpath(cfg)
local paths = {
WindowedApp = "$(HOME)/Applications",
}
return paths[cfg.kind]
end
--
-- Return the Xcode product type, based target kind.
--
@ -85,6 +102,26 @@
end
--
-- Return the Xcode target type, based on the target file extension.
--
-- @param node
-- The product node to identify.
-- @returns
-- An Xcode target type, string.
--
function xcode.gettargettype(node)
local types = {
ConsoleApp = "\"compiled.mach-o.executable\"",
WindowedApp = "wrapper.application",
StaticLib = "archive.ar",
SharedLib = "\"compiled.mach-o.dylib\"",
}
return types[node.cfg.kind]
end
--
-- Returns true if the file name represents a framework.
--
@ -252,7 +289,7 @@
_p(3,');')
_p(3,'name = %s;', name)
if node.cfg.kind == "WindowedApp" then
_p(3,'productInstallPath = "$(HOME)/Applications";')
_p(3,'productInstallPath = "%s";', xcode.getinstallpath(node.cfg))
end
_p(3,'productName = %s;', name)
_p(3,'productReference = %s /* %s */;', node.id, node.name)
@ -384,11 +421,15 @@
end
if tr.infoplist then
_p(4,'INFOPLIST_FILE = %s;', tr.infoplist.path)
_p(4,'INFOPLIST_FILE = "%s";', tr.infoplist.path)
end
_p(4,'PRODUCT_NAME = %s;', cfg.buildtarget.basename)
if cfg.kind == "WindowedApp" then
_p(4,'INSTALL_PATH = "%s";', xcode.getinstallpath(cfg))
end
_p(4,'SYMROOT = %s;', cfg.objectsdir)
_p(3,'};')
_p(3,'name = %s;', cfg.name)

View File

@ -1,229 +0,0 @@
--
-- xcode_pbxproj.lua
-- Generate an Xcode project, which incorporates the entire Premake structure.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
local xcode = premake.xcode
local tree = premake.tree
--
-- Create a solution tree corresponding to what is shown in the Xcode project
-- browser pane, with nodes for files and folders, resources, frameworks, and
-- products.
--
-- @param sln
-- The solution being generated.
-- @returns
-- A tree, loaded with metadata, which mirrors Xcode's view of the solution.
--
function xcode.buildtree(sln)
local node
-- create a solution level node and add each project to it; remember which
-- node goes with which project for later reference
local tr = tree.new(sln.name)
local prjnodes = {}
for prj in premake.solution.eachproject(sln) do
prjnodes[prj] = tree.insert(tr, premake.project.buildsourcetree(prj))
end
-- if there is only one project, use that as the tree root instead of the
-- solution. This avoids an otherwise empty level in the tree
if #tr.children == 1 then
tr = tr.children[1]
tr.parent = nil
end
tr.solution = sln
-- convert localized resources from their filesystem layout (English.lproj/MainMenu.xib)
-- to Xcode's display layout (MainMenu.xib/English).
tree.traverse(tr, {
onbranch = function(node)
if path.getextension(node.name) == ".lproj" then
local lang = path.getbasename(node.name) -- "English", "French", etc.
-- create a new language group for each file it contains
for _, filenode in ipairs(node.children) do
local grpnode = node.parent.children[filenode.name]
if not grpnode then
grpnode = tree.insert(node.parent, tree.new(filenode.name))
grpnode.kind = "vgroup"
end
-- convert the file node to a language node and add to the group
filenode.name = path.getbasename(lang)
tree.insert(grpnode, filenode)
end
-- remove this directory from the tree
tree.remove(node)
end
end
})
-- the special folder "Frameworks" lists all of the frameworks used in the solution.
-- Only add it to the tree if there are frameworks in use.
tr.frameworks = tree.new("Frameworks")
frameworks = { } -- remember which frameworks have already been added
for prj in premake.solution.eachproject(sln) do
for cfg in premake.eachconfig(prj) do
for _, link in ipairs(cfg.links) do
local name = path.getname(link)
if xcode.isframework(name) and not frameworks[name] then
frameworks[name] = name
node = tree.insert(tr.frameworks, tree.new(name))
node.path = link
end
end
end
end
if #tr.frameworks.children > 0 then
tree.insert(tr, tr.frameworks)
end
-- the special folder "Products" lists all of the generated targets, one target
-- for each target kind (ConsoleApp, SharedLibrary, etc.) produced by a project.
tr.products = tree.insert(tr, tree.new("Products"))
for prj in premake.solution.eachproject(sln) do
local kinds = {} -- remember which kinds have already been added
for cfg in premake.eachconfig(prj) do
if not kinds[cfg.kind] then
kinds[cfg.kind] = true
node = tree.insert(tr.products, tree.new(path.getname(cfg.buildtarget.bundlepath)))
node.kind = "product"
node.prjnode = prjnodes[prj]
node.cfg = cfg
node.path = cfg.buildtarget.fullpath
node.targetid = xcode.newid(node, "target")
node.cfgsection = xcode.newid(node, "cfg")
node.resstageid = xcode.newid(node, "rez")
node.sourcesid = xcode.newid(node, "src")
node.fxstageid = xcode.newid(node, "fxs")
-- assign IDs for each configuration
node.configids = {}
for _, cfgname in ipairs(sln.configurations) do
node.configids[cfgname] = xcode.newid(node, cfgname)
end
end
end
end
-- also assign solution-level configuration IDs
tr.configids = {}
for _, cfgname in ipairs(sln.configurations) do
tr.configids[cfgname] = xcode.newid(node, cfgname)
end
-- Final setup
local prjnode
tree.traverse(tr, {
onnode = function(node)
if node.project then
prjnode = node
end
-- assign IDs to every node in the tree
node.id = xcode.newid(node)
-- assign build IDs to buildable files
if xcode.getbuildcategory(node) then
node.buildid = xcode.newid(node, "build")
end
-- Premake is setup for the idea of a solution file referencing multiple project files,
-- but Xcode uses a single file for everything. Convert the file paths from project
-- location relative to solution (the one Xcode file) location relative to compensate.
if node.path then
node.path = xcode.rebase(prjnode.project, node.path)
end
-- remember key files that are needed elsewhere
if node.name == "Info.plist" then
prjnode.infoplist = node
end
end
}, true)
return tr
end
--
-- Return the Xcode target type, based on the target file extension.
--
-- @param node
-- The product node to identify.
-- @returns
-- An Xcode target type, string.
--
function xcode.gettargettype(node)
local types = {
ConsoleApp = "\"compiled.mach-o.executable\"",
WindowedApp = "wrapper.application",
StaticLib = "archive.ar",
SharedLib = "\"compiled.mach-o.dylib\"",
}
return types[node.cfg.kind]
end
--
-- Converts a path or list of paths from project-relative to solution-relative.
--
-- @param prj
-- The project containing the path.
-- @param p
-- A path or list of paths.
-- @returns
-- The rebased path or paths.
--
function xcode.rebase(prj, p)
if type(p) == "string" then
return path.getrelative(prj.solution.location, path.join(prj.location, p))
else
local result = { }
for i, v in ipairs(p) do
result[i] = xcode.rebase(p[i])
end
return result
end
end
---------------------------------------------------------------------------
-- Section generator functions, in the same order in which they appear
-- in the .pbxproj file
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Xcode project generator function
---------------------------------------------------------------------------
function premake.xcode.pbxproj(sln)
tr = xcode.buildtree(sln)
xcode.Header(tr) -- done
xcode.PBXBuildFile(tr) -- done
xcode.PBXFileReference(tr) -- done
xcode.PBXFrameworksBuildPhase(tr) -- done
xcode.PBXGroup(tr) -- done
xcode.PBXNativeTarget(tr) -- done
xcode.PBXProject(tr) -- done
xcode.PBXResourcesBuildPhase(tr)
xcode.PBXSourcesBuildPhase(tr)
xcode.PBXVariantGroup(tr)
xcode.XCBuildConfiguration(tr)
xcode.XCBuildConfigurationList(tr)
xcode.Footer(tr) -- done
end

View File

@ -107,7 +107,7 @@
end
-- remember key files that are needed elsewhere
if node.name == "Info.plist" then
if string.endswith(node.name, "Info.plist") then
tr.infoplist = node
end
end

View File

@ -1,32 +0,0 @@
--
-- tests/actions/test_xcode.lua
-- Automated test suite for the "clean" action.
-- Copyright (c) 2009 Jason Perkins and the Premake project
--
T.xcode3 = { }
local xcode = premake.xcode
--
-- Setup
--
local sln, tr
function T.xcode3.setup()
premake.action.set("xcode3")
-- reset the list of generated IDs
xcode.used_ids = { }
sln = test.createsolution()
end
local function prepare()
io.capture()
premake.buildconfigs()
tr = xcode.buildtree(sln)
end

View File

@ -623,7 +623,7 @@
function suite.XCBuildConfigurationBlock_OnInfoPlist()
files { "Info.plist" }
files { "MyProject-Info.plist" }
prepare()
xcode.XCBuildConfigurationBlock(tr, tr.products.children[1], premake.getconfig(tr.project, "Debug"))
test.capture [[
@ -633,7 +633,7 @@
ALWAYS_SEARCH_USER_PATHS = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = Info.plist;
INFOPLIST_FILE = "MyProject-Info.plist";
PRODUCT_NAME = MyProject;
SYMROOT = obj/Debug;
};

View File

@ -64,8 +64,6 @@
-- Xcode tests
dofile("actions/xcode/test_xcode_common.lua")
dofile("actions/xcode/test_xcode_project.lua")
dofile("actions/test_xcode.lua")
--