diff --git a/src/_manifest.lua b/src/_manifest.lua index 0efb2a8e..00e7e853 100644 --- a/src/_manifest.lua +++ b/src/_manifest.lua @@ -19,6 +19,7 @@ "base/action.lua", "base/option.lua", "base/tree.lua", + "base/solution.lua", "base/project.lua", "base/configs.lua", "base/api.lua", diff --git a/src/actions/codeblocks/codeblocks_workspace.lua b/src/actions/codeblocks/codeblocks_workspace.lua index 51dce743..d2e498df 100644 --- a/src/actions/codeblocks/codeblocks_workspace.lua +++ b/src/actions/codeblocks/codeblocks_workspace.lua @@ -9,7 +9,7 @@ _p('') _p('\t', 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 active = iif(prj.project == sln.projects[1], ' active="1"', '') diff --git a/src/actions/vstudio/vs2002_solution.lua b/src/actions/vstudio/vs2002_solution.lua index 30fd2ee7..cc59a5e3 100644 --- a/src/actions/vstudio/vs2002_solution.lua +++ b/src/actions/vstudio/vs2002_solution.lua @@ -13,7 +13,7 @@ _p('Microsoft Visual Studio Solution File, Format Version 7.00') -- 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))) _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) _p('EndProject') @@ -30,7 +30,7 @@ _p('\tEndGlobalSection') _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 _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)) diff --git a/src/actions/vstudio/vs2003_solution.lua b/src/actions/vstudio/vs2003_solution.lua index 2e38d657..c97882fb 100644 --- a/src/actions/vstudio/vs2003_solution.lua +++ b/src/actions/vstudio/vs2003_solution.lua @@ -13,7 +13,7 @@ _p('Microsoft Visual Studio Solution File, Format Version 8.00') -- 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))) _p('Project("{%s}") = "%s", "%s", "{%s}"', _VS.tool(prj), prj.name, projpath, prj.uuid) @@ -40,7 +40,7 @@ _p('\tEndGlobalSection') _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 _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)) diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 065a73e8..855503a9 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -19,7 +19,7 @@ _p('# Visual Studio %s', iif(_ACTION == 'vs2005', '2005', '2008')) -- 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 local projpath = path.translate(path.getrelative(sln.location, _VS.projectfile(prj)), "\\") @@ -66,7 +66,7 @@ function premake.vs2005_solution_project_platforms(sln) _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 -- .NET projects always map to the "Any CPU" platform (for now, at diff --git a/src/actions/xcode/xcode_pbxproj.lua b/src/actions/xcode/xcode_pbxproj.lua index 6554e9ee..51bce437 100644 --- a/src/actions/xcode/xcode_pbxproj.lua +++ b/src/actions/xcode/xcode_pbxproj.lua @@ -26,7 +26,7 @@ -- node goes with which project for later reference local tr = tree.new(sln.name) 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)) end @@ -68,7 +68,7 @@ -- 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.eachproject(sln) do + 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) @@ -88,7 +88,7 @@ -- 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.eachproject(sln) do + 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 diff --git a/src/base/action.lua b/src/base/action.lua index f8d90884..467d027f 100644 --- a/src/base/action.lua +++ b/src/base/action.lua @@ -55,7 +55,7 @@ if a.onsolution then a.onsolution(sln) end - for prj in premake.eachproject(sln) do + for prj in premake.solution.eachproject(sln) do if a.onproject then a.onproject(prj) end diff --git a/src/base/project.lua b/src/base/project.lua index 659b0cde..b2dccca4 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -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. -- @@ -541,7 +519,7 @@ -- function premake.hascppproject(sln) - for prj in premake.eachproject(sln) do + for prj in premake.solution.eachproject(sln) do if premake.iscppproject(prj) then return true end @@ -555,7 +533,7 @@ -- function premake.hasdotnetproject(sln) - for prj in premake.eachproject(sln) do + for prj in premake.solution.eachproject(sln) do if premake.isdotnetproject(prj) then return true end diff --git a/src/base/solution.lua b/src/base/solution.lua new file mode 100644 index 00000000..2171ec15 --- /dev/null +++ b/src/base/solution.lua @@ -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 diff --git a/src/base/validate.lua b/src/base/validate.lua index 1b4ee48b..58d3706c 100644 --- a/src/base/validate.lua +++ b/src/base/validate.lua @@ -25,7 +25,7 @@ return nil, "solution '" .. sln.name .. "' needs configurations" end - for prj in premake.eachproject(sln) do + for prj in premake.solution.eachproject(sln) do -- every project must have a language if (not prj.language) then diff --git a/tests/actions/xcode/test_xcode_project.lua b/tests/actions/xcode/test_xcode_project.lua index 0405c73b..a379ce71 100644 --- a/tests/actions/xcode/test_xcode_project.lua +++ b/tests/actions/xcode/test_xcode_project.lua @@ -24,13 +24,8 @@ local function prepare() io.capture() premake.buildconfigs() - - local prj = sln.projects[1] - local cfg = premake.getconfig(prj) - cfg.name = prj.name - cfg.blocks = prj.blocks - - tr = xcode.buildprjtree(cfg) + local prj = premake.solution.getproject(sln, 1) + tr = xcode.buildprjtree(prj) end