2016-11-09 19:29:33 +00:00
|
|
|
---
|
|
|
|
-- xcode/xcode4_workspace.lua
|
|
|
|
-- Generate an Xcode workspace.
|
|
|
|
-- Author Mihai Sebea
|
|
|
|
-- Modified by Jason Perkins
|
|
|
|
-- Copyright (c) 2014-2015 Jason Perkins and the Premake project
|
|
|
|
---
|
|
|
|
|
|
|
|
local p = premake
|
|
|
|
local m = p.modules.xcode
|
2017-06-07 07:10:05 +00:00
|
|
|
local tree = p.tree
|
2016-11-09 19:29:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
-- Generate an Xcode contents.xcworkspacedata file.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.workspace = function(wks)
|
|
|
|
return {
|
|
|
|
m.xmlDeclaration,
|
|
|
|
m.workspace,
|
2019-02-07 04:02:26 +00:00
|
|
|
m.reorderProjects,
|
2016-11-09 19:29:33 +00:00
|
|
|
m.workspaceFileRefs,
|
|
|
|
m.workspaceTail,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function m.generateWorkspace(wks)
|
|
|
|
m.prepareWorkspace(wks)
|
|
|
|
p.callArray(m.elements.workspace, wks)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.workspace()
|
|
|
|
p.push('<Workspace')
|
|
|
|
p.w('version = "1.0">')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.workspaceTail()
|
|
|
|
-- Don't output final newline. Xcode doesn't.
|
2017-04-25 05:44:13 +00:00
|
|
|
p.out('</Workspace>')
|
2016-11-09 19:29:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-02-07 04:02:26 +00:00
|
|
|
--
|
|
|
|
-- If a startup project is specified, move it (and any enclosing groups)
|
|
|
|
-- to the front of the project list. This will make Visual Studio treat
|
|
|
|
-- it like a startup project.
|
|
|
|
--
|
|
|
|
-- I force the new ordering into the tree so that it will get applied to
|
|
|
|
-- all sections of the solution; otherwise the first change to the solution
|
|
|
|
-- in the IDE will cause the orderings to get rewritten.
|
|
|
|
--
|
|
|
|
|
|
|
|
function m.reorderProjects(wks)
|
|
|
|
if wks.startproject then
|
|
|
|
local np
|
|
|
|
local tr = p.workspace.grouptree(wks)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onleaf = function(n)
|
|
|
|
if n.project.name == wks.startproject then
|
|
|
|
np = n
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
while np and np.parent do
|
|
|
|
local p = np.parent
|
|
|
|
local i = table.indexof(p.children, np)
|
|
|
|
table.remove(p.children, i)
|
|
|
|
table.insert(p.children, 1, np)
|
|
|
|
np = p
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-11-09 19:29:33 +00:00
|
|
|
---
|
|
|
|
-- Generate the list of project references.
|
|
|
|
---
|
|
|
|
|
|
|
|
m.elements.workspaceFileRef = function(prj)
|
|
|
|
return {
|
|
|
|
m.workspaceLocation,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function m.workspaceFileRefs(wks)
|
2017-06-07 07:10:05 +00:00
|
|
|
local tr = p.workspace.grouptree(wks)
|
|
|
|
tree.traverse(tr, {
|
|
|
|
onleaf = function(n)
|
|
|
|
local prj = n.project
|
|
|
|
|
|
|
|
p.push('<FileRef')
|
|
|
|
local contents = p.capture(function()
|
|
|
|
p.callArray(m.elements.workspaceFileRef, prj)
|
|
|
|
end)
|
|
|
|
p.outln(contents .. ">")
|
|
|
|
p.pop('</FileRef>')
|
|
|
|
end,
|
|
|
|
|
|
|
|
onbranchenter = function(n)
|
|
|
|
local prj = n.project
|
|
|
|
|
|
|
|
p.push('<Group')
|
|
|
|
p.w('location = "container:"')
|
|
|
|
p.w('name = "%s">', n.name)
|
|
|
|
end,
|
|
|
|
|
|
|
|
onbranchexit = function(n)
|
|
|
|
p.pop('</Group>')
|
|
|
|
end,
|
|
|
|
})
|
2016-11-09 19:29:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
--
|
|
|
|
-- Handlers for individual project elements
|
|
|
|
--
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
function m.workspaceLocation(prj)
|
|
|
|
local fname = p.filename(prj, ".xcodeproj")
|
|
|
|
fname = path.getrelative(prj.workspace.location, fname)
|
|
|
|
p.w('location = "group:%s"', fname)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function m.xmlDeclaration()
|
|
|
|
p.xmlUtf8(true)
|
|
|
|
end
|