Fix a bug in configuration map pattern matching

This commit is contained in:
Jason Perkins 2012-06-11 19:11:21 -04:00
parent 1fa3951541
commit e15d115bbd
2 changed files with 56 additions and 42 deletions

View File

@ -216,10 +216,6 @@
buildcfg = pairing[1]
platform = pairing[2]
-- if the project has a platforms list, and the solution does
-- not, default to the first project platform
platform = platform or prj.platforms[1]
-- look up and return the associated config
local key = (buildcfg or "*") .. (platform or "")
return prj.configs[key]
@ -483,34 +479,36 @@
function project.mapconfig(prj, buildcfg, platform)
local pairing = { buildcfg, platform }
for patterns, replacements in pairs(prj.configmap or {}) do
if type(patterns) ~= "table" then
patterns = { patterns }
local testpattern = function(pattern, pairing, i)
local j = 1
while i <= #pairing and j <= #pattern do
if pairing[i] ~= pattern[j] then
return false
end
i = i + 1
j = j + 1
end
return true
end
for pattern, replacements in pairs(prj.configmap or {}) do
if type(pattern) ~= "table" then
pattern = { pattern }
end
-- does this pattern match any part of the pair?
-- does this pattern match any part of the pair? If so,
-- replace it with the corresponding values
for i = 1, #pairing do
local matched = true
for j = 1, #patterns do
if pairing[i] ~= patterns[j] then
matched = false
end
end
-- yes, replace one or more parts (with a copy)
if matched then
if #patterns == 1 and #replacements == 1 then
result = { pairing[1], pairing[2] }
if testpattern(pattern, pairing, i) then
if #pattern == 1 and #replacements == 1 then
pairing[i] = replacements[1]
else
pairing = { replacements[1], replacements[2] }
end
return pairing
end
end
end
end
return pairing
end

View File

@ -6,8 +6,6 @@
T.project_getconfig = { }
local suite = T.project_getconfig
local premake = premake5
--
-- Setup and teardown
@ -16,12 +14,13 @@
local sln, prj, cfg
function suite.setup()
sln, prj = test.createsolution()
sln = solution("MySolution")
configurations { "Debug", "Release" }
end
local function prepare(buildcfg)
buildcfg = buildcfg or "Debug"
cfg = premake.project.getconfig(prj, buildcfg)
local function prepare(buildcfg, platform)
prj = premake.solution.getproject_ng(sln, 1)
cfg = premake5.project.getconfig(prj, buildcfg or "Debug", platform)
end
@ -31,6 +30,7 @@
--
function suite.solutionConfig_onNoProjectConfigs()
project ("MyProject")
prepare()
test.isequal("Debug", cfg.buildcfg)
end
@ -42,6 +42,7 @@
--
function suite.appliesCfgMapping_onMappingExists()
project ("MyProject")
configmap { ["Debug"] = "Development" }
prepare()
test.isequal("Development", cfg.buildcfg)
@ -54,6 +55,7 @@
--
function suite.fetchesMappedCfg_onMappedName()
project ("MyProject")
configmap { ["Debug"] = "Development" }
prepare("Development")
test.isequal("Development", cfg.buildcfg)
@ -66,24 +68,13 @@
--
function suite.returnsNil_onRemovedConfig()
project ("MyProject")
removeconfigurations { "Debug" }
prepare()
test.isnil(cfg)
end
--
-- If the project has a platforms list, and the solution does not,
-- use the first project platform.
--
function suite.usesFirstPlatform_onNoSolutionPlatforms()
platforms { "x32", "x64" }
prepare()
test.isequal("x32", cfg.platform)
end
--
-- If the target system is not specified, the current operating environment
-- should be used as the default.
@ -91,6 +82,7 @@
function suite.usesCurrentOS_onNoSystemSpecified()
_OS = "linux"
project ("MyProject")
configuration { "linux" }
defines { "correct" }
prepare()
@ -107,6 +99,7 @@
function suite.actionOverridesOS()
_OS = "linux"
_ACTION = "vs2005"
project ("MyProject")
configuration { "windows" }
defines { "correct" }
prepare()
@ -122,6 +115,7 @@
function suite.usesCfgSystem()
_OS = "linux"
_ACTION = "vs2005"
project ("MyProject")
system "macosx"
configuration { "macosx" }
defines { "correct" }
@ -136,6 +130,7 @@
function suite.appliesActionToFilters()
_ACTION = "vs2005"
project ("MyProject")
configuration { "vs2005" }
defines { "correct" }
prepare()
@ -149,10 +144,31 @@
--
function suite.returnsMappedConfig_onOtherwiseMissing()
project ("MyProject")
removeconfigurations "Debug"
configmap { Debug = "Release" }
prepare()
test.isequal("Release", cfg.buildcfg)
end
--
-- Check mapping from solution build cfg + platform pairs to a simple
-- project configuration.
--
function suite.canMapSolutionPairToProjectBuildCfg()
platforms { "Win32", "PS3" }
project ("MyProject")
removeconfigurations "*"
removeplatforms "*"
configurations { "Debug Win32", "Release Win32", "Debug PS3", "Release PS3" }
configmap {
[{"Debug", "Win32"}] = "Debug Win32",
[{"Debug", "PS3"}] = "Debug PS3",
[{"Release", "Win32"}] = "Release Win32",
[{"Release", "PS3"}] = "Release PS3"
}
prepare("Debug", "PS3")
test.isequal("Debug PS3", cfg.buildcfg)
end