Rework solution and project APIs around new container calls

This commit is contained in:
Jason Perkins 2014-10-09 19:34:34 -04:00
parent 68c106bb5b
commit 47aa8db1a7
8 changed files with 58 additions and 153 deletions

View File

@ -99,7 +99,7 @@
function make.getmakefilename(this, searchprjs)
local count = 0
for sln in premake.solution.each() do
for sln in premake.global.eachSolution() do
if sln.location == this.location then
count = count + 1
end

View File

@ -4,10 +4,10 @@
-- Copyright (c) 2002-2014 Jason Perkins and the Premake project
---
premake.action = {}
local action = premake.action
local p = premake
p.action = {}
local action = premake.action
@ -77,7 +77,7 @@
function action.call(name)
local act = action._list[name]
for sln in p.solution.each() do
for sln in p.global.eachSolution() do
if act.onsolution then
act.onsolution(sln)
end
@ -88,7 +88,7 @@
end
end
for rule in p.rule.each() do
for rule in p.global.eachRule() do
if act.onrule then
act.onrule(rule)
end

View File

@ -9,6 +9,56 @@
local global = p.global
---
-- Create a new global container instance.
---
function global.new(name)
return p.container.new(p.global, name)
end
---
-- Iterate over the collection of rules in a session.
--
-- @returns
-- An iterator function.
---
function global.eachRule()
local root = p.api.rootContainer()
return p.container.eachChild(root, p.rule)
end
---
-- Iterate over the collection of solutions in a session.
--
-- @returns
-- An iterator function.
---
function global.eachSolution()
local root = p.api.rootContainer()
return p.container.eachChild(root, p.solution)
end
---
-- Retrieve a solution by name or index.
--
-- @param key
-- The solution key, either a string name or integer index.
-- @returns
-- The solution with the provided key.
---
function global.getSolution(key)
local root = p.api.rootContainer()
if root.solutions then
return root.solutions[key]
end
end

View File

@ -310,7 +310,7 @@ end
function premake.validate()
local ctx = {}
for sln in solution.each() do
for sln in premake.global.eachSolution() do
premake.validateSolution(sln, ctx)
for prj in solution.eachproject(sln) do

View File

@ -109,27 +109,6 @@
--
-- Locate a project by name; case insensitive.
--
-- @param name
-- The name of the project for which to search.
-- @return
-- The corresponding project, or nil if no matching project could be found.
--
function project.findproject(name)
for sln in premake.solution.each() do
for _, prj in ipairs(sln.projects) do
if (prj.name == name) then
return prj
end
end
end
end
--
-- Retrieve the project's configuration information for a particular build
-- configuration/platform pair.
--
@ -141,7 +120,6 @@
-- Optional; the name of the platform on which to filter.
-- @return
-- A configuration object.
--
function project.getconfig(prj, buildcfg, platform)
-- if no build configuration is specified, return the "root" project
@ -205,17 +183,6 @@
---
-- Returns the file name for this project. Also works with solutions.
-- Deprecated 11 Aug 2014
---
function project.getfilename(prj, ext)
return premake.filename(prj, ext)
end
--
-- Return the first configuration of a project, which is used in some
-- actions to generate project-wide defaults.

View File

@ -18,18 +18,3 @@
function rule.new(name)
return p.container.new(rule, name)
end
---
-- Iterate over the collection of rules in a session.
--
-- @returns
-- An iterator function.
---
function rule.each()
local root = p.api.rootContainer()
return p.container.eachChild(root, rule)
end

View File

@ -24,42 +24,6 @@
--
-- Add a new project to the solution.
--
-- @param sln
-- The solution to contain the project.
-- @param prj
-- The new project object.
--
function solution.addproject(sln, prj)
-- add keyed by array index AND name
table.insert(sln.projects, prj)
sln.projects[prj.name] = prj
end
--
-- Iterate over the collection of solutions in a session.
--
-- @returns
-- An iterator function.
--
function solution.each()
local root = p.api.rootContainer()
local i = 0
return function ()
i = i + 1
if i <= #root.solutions then
return root.solutions[i]
end
end
end
--
-- Iterate over the configurations of a solution.
--
@ -126,24 +90,6 @@
end
--
-- Retrieve a solution by name or index.
--
-- @param key
-- The solution key, either a string name or integer index.
-- @returns
-- The solution with the provided key.
--
function solution.get(key)
local root = p.api.rootContainer()
if root.solutions then
return root.solutions[key]
end
end
--
-- Retrieve the tree of project groups.
--
@ -195,46 +141,3 @@
sln = premake.oven.bakeSolution(sln)
return sln.projects[idx]
end
--
-- Checks to see if any projects contained by a solution use
-- a C or C++ as their language.
--
-- @param sln
-- The solution to query.
-- @return
-- True if at least one project in the solution uses C or C++.
--
function solution.hascppproject(sln)
for prj in solution.eachproject(sln) do
if p.project.iscpp(prj) then
return true
end
end
return false
end
--
-- Checks to see if any projects contained by a solution use
-- a .NET language.
--
-- @param sln
-- The solution to query.
-- @return
-- True if at least one project in the solution uses a
-- .NET language
--
function solution.hasdotnetproject(sln)
for prj in solution.eachproject(sln) do
if p.project.isdotnet(prj) then
return true
end
end
return false
end

View File

@ -24,7 +24,7 @@
--
function suite.solution_createsOnFirstUse()
test.isnotnil(premake.solution.get("MySolution"))
test.isnotnil(premake.global.getSolution("MySolution"))
end
function suite.project_createsOnFirstUse()