Began porting to solution object

This commit is contained in:
starkos 2009-11-04 18:25:08 +00:00
parent 03b9eb3deb
commit 293e2353ba
11 changed files with 67 additions and 43 deletions

View File

@ -19,6 +19,7 @@
"base/action.lua", "base/action.lua",
"base/option.lua", "base/option.lua",
"base/tree.lua", "base/tree.lua",
"base/solution.lua",
"base/project.lua", "base/project.lua",
"base/configs.lua", "base/configs.lua",
"base/api.lua", "base/api.lua",

View File

@ -9,7 +9,7 @@
_p('<CodeBlocks_workspace_file>') _p('<CodeBlocks_workspace_file>')
_p('\t<Workspace title="%s">', sln.name) _p('\t<Workspace title="%s">', sln.name)
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
local fname = path.join(path.getrelative(sln.location, prj.location), prj.name) local fname = path.join(path.getrelative(sln.location, prj.location), prj.name)
local active = iif(prj.project == sln.projects[1], ' active="1"', '') local active = iif(prj.project == sln.projects[1], ' active="1"', '')

View File

@ -13,7 +13,7 @@
_p('Microsoft Visual Studio Solution File, Format Version 7.00') _p('Microsoft Visual Studio Solution File, Format Version 7.00')
-- Write out the list of project entries -- Write out the list of project entries
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj))) local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)))
_p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid)
_p('EndProject') _p('EndProject')
@ -30,7 +30,7 @@
_p('\tEndGlobalSection') _p('\tEndGlobalSection')
_p('\tGlobalSection(ProjectConfiguration) = postSolution') _p('\tGlobalSection(ProjectConfiguration) = postSolution')
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
for _, cfgname in ipairs(sln.configurations) do for _, cfgname in ipairs(sln.configurations) do
_p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) _p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))
_p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) _p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))

View File

@ -13,7 +13,7 @@
_p('Microsoft Visual Studio Solution File, Format Version 8.00') _p('Microsoft Visual Studio Solution File, Format Version 8.00')
-- Write out the list of project entries -- Write out the list of project entries
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj))) local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)))
_p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid)
@ -40,7 +40,7 @@
_p('\tEndGlobalSection') _p('\tEndGlobalSection')
_p('\tGlobalSection(ProjectConfiguration) = postSolution') _p('\tGlobalSection(ProjectConfiguration) = postSolution')
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
for _, cfgname in ipairs(sln.configurations) do for _, cfgname in ipairs(sln.configurations) do
_p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) _p('\t\t{%s}.%s.ActiveCfg = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))
_p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj)) _p('\t\t{%s}.%s.Build.0 = %s|%s', prj.uuid, cfgname, cfgname, _VS.arch(prj))

View File

@ -19,7 +19,7 @@
_p('# Visual Studio %s', iif(_ACTION == 'vs2005', '2005', '2008')) _p('# Visual Studio %s', iif(_ACTION == 'vs2005', '2005', '2008'))
-- Write out the list of project entries -- Write out the list of project entries
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
-- Build a relative path from the solution file to the project file -- Build a relative path from the solution file to the project file
local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), "\\") local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), "\\")
@ -66,7 +66,7 @@
function premake.vs2005_solution_project_platforms(sln) function premake.vs2005_solution_project_platforms(sln)
_p('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution') _p('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution')
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
for _, cfg in ipairs(sln.vstudio_configs) do for _, cfg in ipairs(sln.vstudio_configs) do
-- .NET projects always map to the "Any CPU" platform (for now, at -- .NET projects always map to the "Any CPU" platform (for now, at

View File

@ -26,7 +26,7 @@
-- node goes with which project for later reference -- node goes with which project for later reference
local tr = tree.new(sln.name) local tr = tree.new(sln.name)
local prjnodes = {} local prjnodes = {}
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
prjnodes[prj] = tree.insert(tr, premake.project.buildsourcetree(prj)) prjnodes[prj] = tree.insert(tr, premake.project.buildsourcetree(prj))
end end
@ -68,7 +68,7 @@
-- Only add it to the tree if there are frameworks in use. -- Only add it to the tree if there are frameworks in use.
tr.frameworks = tree.new("Frameworks") tr.frameworks = tree.new("Frameworks")
frameworks = { } -- remember which frameworks have already been added frameworks = { } -- remember which frameworks have already been added
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
for cfg in premake.eachconfig(prj) do for cfg in premake.eachconfig(prj) do
for _, link in ipairs(cfg.links) do for _, link in ipairs(cfg.links) do
local name = path.getname(link) local name = path.getname(link)
@ -88,7 +88,7 @@
-- the special folder "Products" lists all of the generated targets, one target -- the special folder "Products" lists all of the generated targets, one target
-- for each target kind (ConsoleApp, SharedLibrary, etc.) produced by a project. -- for each target kind (ConsoleApp, SharedLibrary, etc.) produced by a project.
tr.products = tree.insert(tr, tree.new("Products")) tr.products = tree.insert(tr, tree.new("Products"))
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
local kinds = {} -- remember which kinds have already been added local kinds = {} -- remember which kinds have already been added
for cfg in premake.eachconfig(prj) do for cfg in premake.eachconfig(prj) do
if not kinds[cfg.kind] then if not kinds[cfg.kind] then

View File

@ -55,7 +55,7 @@
if a.onsolution then if a.onsolution then
a.onsolution(sln) a.onsolution(sln)
end end
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
if a.onproject then if a.onproject then
a.onproject(prj) a.onproject(prj)
end end

View File

@ -69,28 +69,6 @@
--
-- Iterator for a solution's projects, or rather project root configurations.
-- These configuration objects include all settings related to the project,
-- regardless of where they were originally specified.
--
function premake.eachproject(sln)
local i = 0
return function ()
i = i + 1
if (i <= #sln.projects) then
local prj = sln.projects[i]
local cfg = premake.getconfig(prj)
cfg.name = prj.name
cfg.blocks = prj.blocks
return cfg
end
end
end
-- --
-- Apply XML escaping to a value. -- Apply XML escaping to a value.
-- --
@ -541,7 +519,7 @@
-- --
function premake.hascppproject(sln) function premake.hascppproject(sln)
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
if premake.iscppproject(prj) then if premake.iscppproject(prj) then
return true return true
end end
@ -555,7 +533,7 @@
-- --
function premake.hasdotnetproject(sln) function premake.hasdotnetproject(sln)
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
if premake.isdotnetproject(prj) then if premake.isdotnetproject(prj) then
return true return true
end end

50
src/base/solution.lua Normal file
View File

@ -0,0 +1,50 @@
--
-- solution.lua
-- Work with the list of solutions loaded from the script.
-- Copyright (c) 2002-2009 Jason Perkins and the Premake project
--
premake.solution = { }
--
-- Iterate over the projects of a solution.
--
-- @param sln
-- The solution.
-- @returns
-- An iterator function.
--
function premake.solution.eachproject(sln)
local i = 0
return function ()
i = i + 1
if (i <= #sln.projects) then
return premake.solution.getproject(sln, i)
end
end
end
--
-- Retrieve the project at a particular index.
--
-- @param sln
-- The solution.
-- @param idx
-- An index into the array of projects.
-- @returns
-- The project at the given index.
--
function premake.solution.getproject(sln, idx)
-- retrieve the root configuration of the project, with all of
-- the global (not configuration specific) settings collapsed
local prj = sln.projects[idx]
local cfg = premake.getconfig(prj)
-- root configuration doesn't have a name; use the project's
cfg.name = prj.name
return cfg
end

View File

@ -25,7 +25,7 @@
return nil, "solution '" .. sln.name .. "' needs configurations" return nil, "solution '" .. sln.name .. "' needs configurations"
end end
for prj in premake.eachproject(sln) do for prj in premake.solution.eachproject(sln) do
-- every project must have a language -- every project must have a language
if (not prj.language) then if (not prj.language) then

View File

@ -24,13 +24,8 @@
local function prepare() local function prepare()
io.capture() io.capture()
premake.buildconfigs() premake.buildconfigs()
local prj = premake.solution.getproject(sln, 1)
local prj = sln.projects[1] tr = xcode.buildprjtree(prj)
local cfg = premake.getconfig(prj)
cfg.name = prj.name
cfg.blocks = prj.blocks
tr = xcode.buildprjtree(cfg)
end end