Merge pull request #180 from starkos/rename-solution-to-workspace

Begin renaming solution to workspace
This commit is contained in:
Manu Evans 2015-07-31 09:31:38 +10:00
commit 96848b28f1
15 changed files with 224 additions and 95 deletions

View File

@ -37,7 +37,7 @@
-- project objects -- project objects
"base/global.lua", "base/global.lua",
"base/solution.lua", "base/workspace.lua",
"base/group.lua", "base/group.lua",
"base/project.lua", "base/project.lua",
"base/config.lua", "base/config.lua",

View File

@ -1,7 +1,7 @@
-- --
-- _make.lua -- _make.lua
-- Define the makefile action(s). -- Define the makefile action(s).
-- Copyright (c) 2002-2013 Jason Perkins and the Premake project -- Copyright (c) 2002-2015 Jason Perkins and the Premake project
-- --
premake.make = {} premake.make = {}
@ -28,9 +28,9 @@
dotnet = { "mono", "msnet", "pnet" } dotnet = { "mono", "msnet", "pnet" }
}, },
onSolution = function(sln) onWorkspace = function(wks)
premake.escaper(make.esc) premake.escaper(make.esc)
premake.generate(sln, make.getmakefilename(sln, false), make.generate_solution) premake.generate(wks, make.getmakefilename(wks, false), make.generate_solution)
end, end,
onProject = function(prj) onProject = function(prj)
@ -43,8 +43,8 @@
end end
end, end,
onCleanSolution = function(sln) onCleanWorkspace = function(wks)
premake.clean.file(sln, make.getmakefilename(sln, false)) premake.clean.file(wks, make.getmakefilename(wks, false))
end, end,
onCleanProject = function(prj) onCleanProject = function(prj)

View File

@ -96,12 +96,12 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = vstudio.vs2005.generateSolution, onWorkspace = vstudio.vs2005.generateSolution,
onProject = vstudio.vs2005.generateProject, onProject = vstudio.vs2005.generateProject,
onCleanSolution = vstudio.cleanSolution, onCleanWorkspace = vstudio.cleanSolution,
onCleanProject = vstudio.cleanProject, onCleanProject = vstudio.cleanProject,
onCleanTarget = vstudio.cleanTarget, onCleanTarget = vstudio.cleanTarget,
-- This stuff is specific to the Visual Studio exporters -- This stuff is specific to the Visual Studio exporters

View File

@ -35,12 +35,12 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = vstudio.vs2005.generateSolution, onWorkspace = vstudio.vs2005.generateSolution,
onProject = vstudio.vs2005.generateProject, onProject = vstudio.vs2005.generateProject,
onCleanSolution = vstudio.cleanSolution, onCleanWorkspace = vstudio.cleanSolution,
onCleanProject = vstudio.cleanProject, onCleanProject = vstudio.cleanProject,
onCleanTarget = vstudio.cleanTarget, onCleanTarget = vstudio.cleanTarget,
-- This stuff is specific to the Visual Studio exporters -- This stuff is specific to the Visual Studio exporters

View File

@ -121,8 +121,8 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = function(sln) onWorkspace = function(wks)
vstudio.vs2005.generateSolution(sln) vstudio.vs2005.generateSolution(wks)
end, end,
onProject = function(prj) onProject = function(prj)
vstudio.vs2010.generateProject(prj) vstudio.vs2010.generateProject(prj)
@ -131,8 +131,8 @@
vstudio.vs2010.generateRule(rule) vstudio.vs2010.generateRule(rule)
end, end,
onCleanSolution = function(sln) onCleanWorkspace = function(wks)
vstudio.cleanSolution(sln) vstudio.cleanSolution(wks)
end, end,
onCleanProject = function(prj) onCleanProject = function(prj)
vstudio.cleanProject(prj) vstudio.cleanProject(prj)

View File

@ -37,8 +37,8 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = function(sln) onWorkspace = function(wks)
vstudio.vs2005.generateSolution(sln) vstudio.vs2005.generateSolution(wks)
end, end,
onProject = function(prj) onProject = function(prj)
vstudio.vs2010.generateProject(prj) vstudio.vs2010.generateProject(prj)
@ -47,8 +47,8 @@
vstudio.vs2010.generateRule(rule) vstudio.vs2010.generateRule(rule)
end, end,
onCleanSolution = function(sln) onCleanWorkspace = function(wks)
vstudio.cleanSolution(sln) vstudio.cleanSolution(wks)
end, end,
onCleanProject = function(prj) onCleanProject = function(prj)
vstudio.cleanProject(prj) vstudio.cleanProject(prj)

View File

@ -39,8 +39,8 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = function(sln) onWorkspace = function(wks)
vstudio.vs2005.generateSolution(sln) vstudio.vs2005.generateSolution(wks)
end, end,
onProject = function(prj) onProject = function(prj)
vstudio.vs2010.generateProject(prj) vstudio.vs2010.generateProject(prj)
@ -49,8 +49,8 @@
vstudio.vs2010.generateRule(rule) vstudio.vs2010.generateRule(rule)
end, end,
onCleanSolution = function(sln) onCleanWorkspace = function(wks)
vstudio.cleanSolution(sln) vstudio.cleanSolution(wks)
end, end,
onCleanProject = function(prj) onCleanProject = function(prj)
vstudio.cleanProject(prj) vstudio.cleanProject(prj)

View File

@ -39,8 +39,8 @@
-- Solution and project generation logic -- Solution and project generation logic
onSolution = function(sln) onWorkspace = function(wks)
vstudio.vs2005.generateSolution(sln) vstudio.vs2005.generateSolution(wks)
end, end,
onProject = function(prj) onProject = function(prj)
vstudio.vs2010.generateProject(prj) vstudio.vs2010.generateProject(prj)
@ -49,8 +49,8 @@
vstudio.vs2010.generateRule(rule) vstudio.vs2010.generateRule(rule)
end, end,
onCleanSolution = function(sln) onCleanWorkspace = function(wks)
vstudio.cleanSolution(sln) vstudio.cleanSolution(wks)
end, end,
onCleanProject = function(prj) onCleanProject = function(prj)
vstudio.cleanProject(prj) vstudio.cleanProject(prj)

View File

@ -17,6 +17,9 @@
local _warnings = {} local _warnings = {}
-- Keep track of aliased functions, so I can resolve to canonical names
local _aliases = {}
-- --
-- Define some commonly used symbols, for future-proofing. -- Define some commonly used symbols, for future-proofing.
@ -51,6 +54,36 @@
---
-- Provide an alias for a function in a namespace. Calls to the alias will
-- invoke the canonical function, and attempts to override the alias will
-- instead override the canonical call.
--
-- @param scope
-- The table containing the function to be overridden. Use _G for
-- global functions.
-- @param canonical
-- The name of the function to be aliased (a string value)
-- @param alias
-- The new alias for the function (another string value).
---
function p.alias(scope, canonical, alias)
scope, canonical = p.resolveAlias(scope, canonical)
if not scope[canonical] then
error("unable to alias '" .. canonical .. "'; no such function", 2)
end
_aliases[scope] = _aliases[scope] or {}
_aliases[scope][alias] = canonical
scope[alias] = function(...)
return scope[canonical](...)
end
end
--- ---
-- Call a list of functions. -- Call a list of functions.
-- --
@ -230,10 +263,13 @@
--- ---
function premake.override(scope, name, repl) function premake.override(scope, name, repl)
scope, name = p.resolveAlias(scope, name)
local original = scope[name] local original = scope[name]
if not original then if not original then
error("unable to override '" .. name .. "'; no such function", 2) error("unable to override '" .. name .. "'; no such function", 2)
end end
scope[name] = function(...) scope[name] = function(...)
return repl(original, ...) return repl(original, ...)
end end
@ -253,6 +289,30 @@
---
-- Find the canonical name and scope of a function, resolving any aliases.
--
-- @param scope
-- The table containing the function to be overridden. Use _G for
-- global functions.
-- @param name
-- The name of the function to resolve.
-- @return
-- The canonical scope and function name (a string value).
---
function p.resolveAlias(scope, name)
local aliases = _aliases[scope]
if aliases then
while aliases[name] do
name = aliases[name]
end
end
return scope, name
end
-- --
-- Display a warning, with a formatted message built from the provided -- Display a warning, with a formatted message built from the provided
-- arguments. -- arguments.

View File

@ -73,20 +73,20 @@
--- ---
function action.call(name) function action.call(name)
local act = action._list[name] local a = action._list[name]
if act.onStart then if a.onStart then
act.onStart() a.onStart()
end end
for sln in p.global.eachSolution() do for sln in p.global.eachSolution() do
local onSolution = act.onSolution or act.onsolution local onSolution = a.onWorkspace or a.onSolution or a.onsolution
if onSolution and not sln.external then if onSolution and not sln.external then
onSolution(sln) onSolution(sln)
end end
for prj in p.solution.eachproject(sln) do for prj in p.solution.eachproject(sln) do
local onProject = act.onProject or act.onproject local onProject = a.onProject or a.onproject
if onProject and not prj.external then if onProject and not prj.external then
onProject(prj) onProject(prj)
end end
@ -94,18 +94,18 @@
end end
for rule in p.global.eachRule() do for rule in p.global.eachRule() do
local onRule = act.onRule or act.onrule local onRule = a.onRule or a.onrule
if onRule and not rule.external then if onRule and not rule.external then
onRule(rule) onRule(rule)
end end
end end
if act.execute then if a.execute then
act.execute() a.execute()
end end
if act.onEnd then if a.onEnd then
act.onEnd() a.onEnd()
end end
end end

View File

@ -84,6 +84,7 @@
self.environ = { self.environ = {
sln = self, sln = self,
wks = self,
} }
context.compile(self) context.compile(self)
@ -142,6 +143,7 @@
self.environ = { self.environ = {
sln = sln, sln = sln,
wks = sln,
prj = self, prj = self,
} }
@ -316,7 +318,8 @@
-- fill in any calculated values -- fill in any calculated values
for _, cfg in ipairs(configs) do for _, cfg in ipairs(configs) do
cfg.solution = sln cfg.solution = sln -- confused: doesn't happen automatically already?
cfg.workspace = sln
oven.finishConfig(cfg) oven.finishConfig(cfg)
end end
@ -456,6 +459,7 @@
local environ = { local environ = {
sln = prj.solution, sln = prj.solution,
wks = prj.solution,
prj = prj, prj = prj,
} }

View File

@ -1,67 +1,71 @@
--- ---
-- solution.lua -- workspace.lua
-- Work with the list of solutions loaded from the script. -- Work with the list of workspaces loaded from the script.
-- Copyright (c) 2002-2015 Jason Perkins and the Premake project -- Copyright (c) 2002-2015 Jason Perkins and the Premake project
--- ---
local p = premake local p = premake
p.solution = p.api.container("solution", p.global) p.solution = p.api.container("solution", p.global)
local solution = p.solution
local tree = p.tree ---
-- Begin the switch from solution() to workspace()
---
p.workspace = p.solution
local workspace = p.solution
p.alias(_G, "solution", "workspace")
p.alias(_G, "externalsolution", "externalworkspace")
--- ---
-- Create a new solution container instance. -- Create a new workspace container instance.
--- ---
function solution.new(name) function workspace.new(name)
local sln = p.container.new(solution, name) local wks = p.container.new(workspace, name)
return sln return wks
end end
-- --
-- Iterate over the configurations of a solution. -- Iterate over the configurations of a workspace.
-- --
-- @param sln
-- The solution to query.
-- @return -- @return
-- A configuration iteration function. -- A configuration iteration function.
-- --
function solution.eachconfig(sln) function workspace.eachconfig(self)
sln = premake.oven.bakeSolution(sln) self = premake.oven.bakeSolution(self)
local i = 0 local i = 0
return function() return function()
i = i + 1 i = i + 1
if i > #sln.configs then if i > #self.configs then
return nil return nil
else else
return sln.configs[i] return self.configs[i]
end end
end end
end end
-- --
-- Iterate over the projects of a solution (next-gen). -- Iterate over the projects of a workspace.
-- --
-- @param sln
-- The solution.
-- @return -- @return
-- An iterator function, returning project configurations. -- An iterator function, returning project configurations.
-- --
function solution.eachproject(sln) function workspace.eachproject(self)
local i = 0 local i = 0
return function () return function ()
i = i + 1 i = i + 1
if i <= #sln.projects then if i <= #self.projects then
return premake.solution.getproject(sln, i) return p.workspace.getproject(self, i)
end end
end end
end end
@ -70,17 +74,15 @@
-- --
-- Locate a project by name, case insensitive. -- Locate a project by name, case insensitive.
-- --
-- @param sln
-- The solution to query.
-- @param name -- @param name
-- The name of the projec to find. -- The name of the projec to find.
-- @return -- @return
-- The project object, or nil if a matching project could not be found. -- The project object, or nil if a matching project could not be found.
-- --
function solution.findproject(sln, name) function workspace.findproject(self, name)
name = name:lower() name = name:lower()
for _, prj in ipairs(sln.projects) do for _, prj in ipairs(self.projects) do
if name == prj.name:lower() then if name == prj.name:lower() then
return prj return prj
end end
@ -92,35 +94,33 @@
-- --
-- Retrieve the tree of project groups. -- Retrieve the tree of project groups.
-- --
-- @param sln
-- The solution to query.
-- @return -- @return
-- The tree of project groups defined for the solution. -- The tree of project groups defined for the workspace.
-- --
function solution.grouptree(sln) function workspace.grouptree(self)
-- check for a previously cached tree -- check for a previously cached tree
if sln.grouptree then if self.grouptree then
return sln.grouptree return self.grouptree
end end
-- build the tree of groups -- build the tree of groups
local tr = tree.new() local tr = p.tree.new()
for prj in solution.eachproject(sln) do for prj in workspace.eachproject(self) do
local prjpath = path.join(prj.group, prj.name) local prjpath = path.join(prj.group, prj.name)
local node = tree.add(tr, prjpath) local node = p.tree.add(tr, prjpath)
node.project = prj node.project = prj
end end
-- assign UUIDs to each node in the tree -- assign UUIDs to each node in the tree
tree.traverse(tr, { p.tree.traverse(tr, {
onnode = function(node) onnode = function(node)
node.uuid = os.uuid(node.path) node.uuid = os.uuid(node.path)
end end
}) })
sln.grouptree = tr self.grouptree = tr
return tr return tr
end end
@ -128,26 +128,22 @@
-- --
-- Retrieve the project configuration at a particular index. -- Retrieve the project configuration at a particular index.
-- --
-- @param sln
-- The solution.
-- @param idx -- @param idx
-- An index into the array of projects. -- An index into the array of projects.
-- @return -- @return
-- The project configuration at the given index. -- The project configuration at the given index.
-- --
function solution.getproject(sln, idx) function workspace.getproject(self, idx)
sln = premake.oven.bakeSolution(sln) self = p.oven.bakeSolution(self)
return sln.projects[idx] return self.projects[idx]
end end
--- ---
-- Determines if the solution contains a project that meets certain criteria. -- Determines if the workspace contains a project that meets certain criteria.
-- --
-- @param self
-- The solution.
-- @param func -- @param func
-- A test function. Receives a project as its only argument and returns a -- A test function. Receives a project as its only argument and returns a
-- boolean indicating whether it meets to matching criteria. -- boolean indicating whether it meets to matching criteria.
@ -155,6 +151,6 @@
-- True if the test function returned true. -- True if the test function returned true.
--- ---
function solution.hasProject(self, func) function workspace.hasProject(self, func)
return p.container.hasChild(self, p.project, func) return p.container.hasChild(self, p.project, func)
end end

View File

@ -1,6 +1,7 @@
return { return {
-- Base API tests -- Base API tests
"test_string.lua", "test_string.lua",
"base/test_aliasing.lua",
"base/test_configset.lua", "base/test_configset.lua",
"base/test_context.lua", "base/test_context.lua",
"base/test_criteria.lua", "base/test_criteria.lua",

View File

@ -0,0 +1,64 @@
--
-- tests/base/test_aliasing.lua
-- Verify handling of function aliases.
-- Copyright (c) 2015 Jason Perkins and the Premake project
--
local suite = test.declare("premake_alias")
local p = premake
function suite.setup()
suite.testfunc = function()
return 48
end
suite.aliased = nil
suite.aliased2 = nil
end
function suite.returnsOriginalFunction_onNoAlias()
local scope, f = p.resolveAlias(suite, "testfunc")
test.isequal("testfunc", f)
end
function suite.pointsAliasToOriginalFunction()
p.alias(suite, "testfunc", "aliased")
test.isequal(48, suite.aliased())
end
function suite.returnsOriginalFunction_onAlias()
p.alias(suite, "testfunc", "aliased")
local scope, f = p.resolveAlias(suite, "aliased")
test.isequal("testfunc", f)
end
function suite.returnsOriginalFunction_onChainedAliases()
p.alias(suite, "testfunc", "aliased")
p.alias(suite, "aliased", "aliased2")
local scope, f = p.resolveAlias(suite, "aliased2")
test.isequal("testfunc", f)
end
function suite.overrideResolvesAliases()
p.alias(suite, "testfunc", "aliased")
p.override(suite, "aliased", function(base)
return base() + 1
end)
test.isequal(49, suite.testfunc())
end
function suite.aliasTracksOverrides()
p.alias(suite, "testfunc", "aliased")
p.override(suite, "testfunc", function(base)
return base() + 1
end)
test.isequal(49, suite.aliased())
end

View File

@ -1,9 +1,11 @@
-- --
-- tests/testfx.lua -- tests/testfx.lua
-- Automated test framework for Premake. -- Automated test framework for Premake.
-- Copyright (c) 2008-2014 Jason Perkins and the Premake project -- Copyright (c) 2008-2015 Jason Perkins and the Premake project
-- --
local p = premake
-- --
-- Define a namespace for the testing functions -- Define a namespace for the testing functions
@ -244,17 +246,19 @@
-- Some helper functions -- Some helper functions
-- --
function test.createsolution() function test.createWorkspace()
local sln = solution "MySolution" local wks = workspace("MySolution")
configurations { "Debug", "Release" } configurations { "Debug", "Release" }
local prj = project "MyProject" local prj = project("MyProject")
language "C++" language("C++")
kind "ConsoleApp" kind("ConsoleApp")
return sln, prj return wks, prj
end end
p.alias(test, "createWorkspace", "createsolution")
function test.createproject(sln) function test.createproject(sln)
local n = #sln.projects + 1 local n = #sln.projects + 1