solution() and project() now only set the active object when called with a name; remains unchanged otherwise

This commit is contained in:
starkos 2009-01-19 16:56:40 +00:00
parent f2931efbc9
commit 60e383f8b8
6 changed files with 221 additions and 163 deletions

View File

@ -14,6 +14,8 @@ This version is a complete rewrite of Premake.
RC3 -> RC4
- Embed scripts instead of bytecodes to avoid portability issues
- solution() and project() now only set the active object when
called with a name; remains unchanged otherwise
RC2 -> RC3

View File

@ -110,10 +110,7 @@ end
-- escape backslashes
s = s:gsub("\\", "\\\\")
-- strip duplicate line feeds
s = s:gsub("\n+", "\n")
-- escape line feeds
s = s:gsub("\n", "\\n")
@ -130,6 +127,10 @@ end
-- strip tabs
s = s:gsub("[\t]", "")
-- strip duplicate line feeds
s = s:gsub("\n+", "\n")
out:write("\t\"")
out:write(s)
out:write("\",\n")

View File

@ -6,6 +6,6 @@ project "CppConsoleApp"
files "*.cpp"
includedirs { "I:/Code" }
libdirs { "../lib" }
links { "CppSharedLib" }

View File

@ -495,6 +495,10 @@
--
function configuration(keywords)
if not keywords then
return premake.CurrentConfiguration
end
local container, err = premake.getobject("container")
if (not container) then
error(err, 2)
@ -535,85 +539,83 @@
function project(name)
if (name) then
-- identify the parent solution
local sln
if (type(premake.CurrentContainer) == "project") then
sln = premake.CurrentContainer.solution
else
sln = premake.CurrentContainer
end
if (type(sln) ~= "solution") then
error("no active solution", 2)
end
-- if this is a new project, create it
premake.CurrentContainer = sln.projects[name]
if (not premake.CurrentContainer) then
local prj = { }
premake.CurrentContainer = prj
-- add to master list keyed by both name and index
table.insert(sln.projects, prj)
sln.projects[name] = prj
-- attach a type
setmetatable(prj, {
__type = "project",
})
prj.solution = sln
prj.name = name
prj.basedir = os.getcwd()
prj.location = prj.basedir
prj.uuid = os.uuid()
prj.blocks = { }
end
if not name then
return iif(type(premake.CurrentContainer) == "project", premake.CurrentContainer, nil)
end
-- identify the parent solution
local sln
if (type(premake.CurrentContainer) == "project") then
-- add an empty, global configuration to the project
configuration { }
return premake.CurrentContainer
sln = premake.CurrentContainer.solution
else
return nil
end
sln = premake.CurrentContainer
end
if (type(sln) ~= "solution") then
error("no active solution", 2)
end
-- if this is a new project, create it
premake.CurrentContainer = sln.projects[name]
if (not premake.CurrentContainer) then
local prj = { }
premake.CurrentContainer = prj
-- add to master list keyed by both name and index
table.insert(sln.projects, prj)
sln.projects[name] = prj
-- attach a type
setmetatable(prj, {
__type = "project",
})
prj.solution = sln
prj.name = name
prj.basedir = os.getcwd()
prj.location = prj.basedir
prj.uuid = os.uuid()
prj.blocks = { }
end
-- add an empty, global configuration to the project
configuration { }
return premake.CurrentContainer
end
function solution(name)
if (name) then
premake.CurrentContainer = _SOLUTIONS[name]
if (not premake.CurrentContainer) then
local sln = { }
premake.CurrentContainer = sln
-- add to master list keyed by both name and index
table.insert(_SOLUTIONS, sln)
_SOLUTIONS[name] = sln
-- attach a type
setmetatable(sln, {
__type="solution"
})
sln.name = name
sln.location = os.getcwd()
sln.projects = { }
sln.blocks = { }
sln.configurations = { }
if not name then
if type(premake.CurrentContainer) == "project" then
return premake.CurrentContainer.solution
else
return premake.CurrentContainer
end
end
-- make the solution active and return it
if (type(premake.CurrentContainer) == "project") then
premake.CurrentContainer = premake.CurrentContainer.solution
end
if (premake.CurrentContainer) then
-- add an empty, global configuration
configuration { }
premake.CurrentContainer = _SOLUTIONS[name]
if (not premake.CurrentContainer) then
local sln = { }
premake.CurrentContainer = sln
-- add to master list keyed by both name and index
table.insert(_SOLUTIONS, sln)
_SOLUTIONS[name] = sln
-- attach a type
setmetatable(sln, {
__type="solution"
})
sln.name = name
sln.location = os.getcwd()
sln.projects = { }
sln.blocks = { }
sln.configurations = { }
end
-- add an empty, global configuration
configuration { }
return premake.CurrentContainer
end

File diff suppressed because one or more lines are too long

View File

@ -123,44 +123,78 @@
-- solution() tests
--
function T.api.solution_SetsCurrentObject()
sln = solution "MySolution"
function T.api.solution_SetsCurrentContainer_OnName()
test.istrue(sln == premake.CurrentContainer)
end
function T.api.solution_SetsName()
sln = solution "MySolution"
test.isequal("MySolution", sln.name)
end
function T.api.solution_SetsLocation()
sln = solution "MySolution"
test.isequal(os.getcwd(), sln.location)
function T.api.solution_CreatesNewObject_OnNewName()
solution "MySolution2"
test.isfalse(sln == premake.CurrentContainer)
end
function T.api.solution_ReturnsNil_OnNoActiveSolution()
function T.api.solution_ReturnsPrevious_OnExistingName()
solution "MySolution2"
local sln2 = solution "MySolution"
test.istrue(sln == sln2)
end
function T.api.solution_SetsCurrentContainer_OnExistingName()
solution "MySolution2"
solution "MySolution"
test.istrue(sln == premake.CurrentContainer)
end
function T.api.solution_ReturnsNil_OnNoActiveSolutionAndNoName()
premake.CurrentContainer = nil
test.isfalse(solution())
test.isnil(solution())
end
function T.api.solutions_ReturnsSolution_OnActiveProject()
sln = solution "MySolution"
project("MyProject")
function T.api.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName()
test.istrue(sln == solution())
end
function T.api.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName()
project "MyProject"
test.istrue(sln == solution())
end
function T.api.solution_OnNewName()
sln = solution "MySolution"
local sln2 = solution "MySolution2"
test.isfalse(sln == sln2)
function T.api.solution_LeavesProjectActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
solution()
test.istrue(prj == premake.CurrentContainer)
end
function T.api.solution_OnExistingName()
sln = solution "MySolution"
local sln2 = solution "MySolution2"
test.istrue(sln == solution("MySolution"))
function T.api.solution_LeavesConfigActive_OnActiveSolutionAndNoName()
local cfg = configuration "windows"
solution()
test.istrue(cfg == premake.CurrentConfiguration)
end
function T.api.solution_LeavesConfigActive_OnActiveProjectAndNoName()
project "MyProject"
local cfg = configuration "windows"
solution()
test.istrue(cfg == premake.CurrentConfiguration)
end
function T.api.solution_SetsName_OnNewName()
test.isequal("MySolution", sln.name)
end
function T.api.solution_SetsLocation_OnNewName()
test.isequal(os.getcwd(), sln.location)
end
function T.api.solution_AddsNewConfig_OnNewName()
test.istrue(#sln.blocks == 1)
end
function T.api.solution_AddsNewConfig_OnName()
local num = #sln.blocks
solution "MySolution"
test.istrue(#sln.blocks == num + 1)
end
--
@ -174,17 +208,20 @@
test.isfalse(ok)
end
function T.api.configuration_SetsCurrentConfiguration()
sln = solution("MySolution")
cfg = configuration{"Debug"}
function T.api.configuration_SetsCurrentConfiguration_OnKeywords()
local cfg = configuration {"Debug"}
test.istrue(premake.CurrentConfiguration == cfg)
end
function T.api.configuration_AddsToContainer()
sln = solution("MySolution")
cfg = configuration{"Debug"}
function T.api.configuration_AddsToContainer_OnKeywords()
local cfg = configuration {"Debug"}
test.istrue(cfg == sln.blocks[#sln.blocks])
end
function T.api.configuration_ReturnsCurrent_OnNoKeywords()
local cfg = configuration()
test.istrue(cfg == sln.blocks[1])
end
@ -199,67 +236,83 @@
test.isfalse(ok)
end
function T.api.project_SetsCurrentContainer()
sln = solution "MySolution"
prj = project("MyProject")
function T.api.project_SetsCurrentContainer_OnName()
local prj = project "MyProject"
test.istrue(prj == premake.CurrentContainer)
end
function T.api.project_CreatesNewObject_OnNewName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
test.isfalse(prj == premake.CurrentContainer)
end
function T.api.project_AddsToSolution()
sln = solution "MySolution"
prj = project("MyProject")
function T.api.project_AddsToSolution_OnNewName()
local prj = project "MyProject"
test.istrue(prj == sln.projects[1])
end
function T.api.project_SetsName()
sln = solution "MySolution"
function T.api.project_ReturnsPrevious_OnExistingName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
local pr3 = project "MyProject"
test.istrue(prj == pr3)
end
function T.api.project_SetsCurrentContainer_OnExistingName()
local prj = project "MyProject"
local pr2 = project "MyProject2"
local pr3 = project "MyProject"
test.istrue(prj == premake.CurrentContainer)
end
function T.api.project_ReturnsNil_OnNoActiveProjectAndNoName()
test.isnil(project())
end
function T.api.project_ReturnsCurrentProject_OnActiveProjectAndNoName()
local prj = project "MyProject"
test.istrue(prj == project())
end
function T.api.project_LeavesProjectActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
project()
test.istrue(prj == premake.CurrentContainer)
end
function T.api.project_LeavesConfigActive_OnActiveProjectAndNoName()
local prj = project "MyProject"
local cfg = configuration "Windows"
project()
test.istrue(cfg == premake.CurrentConfiguration)
end
function T.api.project_SetsName_OnNewName()
prj = project("MyProject")
test.isequal("MyProject", prj.name)
end
function T.api.project_SetsLocation()
sln = solution "MySolution"
function T.api.project_SetsLocation_OnNewName()
prj = project("MyProject")
test.isequal(os.getcwd(), prj.location)
end
function T.api.project_SetsSolution()
sln = solution "MySolution"
function T.api.project_SetsSolution_OnNewName()
prj = project("MyProject")
test.istrue(sln == prj.solution)
end
function T.api.project_SetsConfiguration()
sln = solution "MySolution"
prj = project("MyProject")
test.istrue(premake.CurrentConfiguration == prj.blocks[1])
end
function T.api.project_ReturnsNil_OnNoActiveProject()
sln = solution "MySolution"
test.isfalse(project())
end
function T.api.project_OnNewName()
sln = solution "MySolution"
local prj = project "MyProject"
local prj2 = project "MyProject2"
test.isfalse(prj == prj2)
end
function T.api.project_OnExistingName()
sln = solution "MySolution"
local prj = project "MyProject"
local prj2 = project "MyProject2"
test.istrue(prj == project("MyProject"))
end
function T.api.project_SetsUUID()
sln = solution "MySolution"
local prj = project "MyProject"
test.istrue(prj.uuid)
end
--