diff --git a/src/base/api.lua b/src/base/api.lua index 83c3f009..b07dc2a5 100755 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -555,15 +555,20 @@ table.foreachi(value, recurse) elseif hasDeprecatedValues and value:contains("*") then - local current = configset.fetch(target, field) + local current = configset.fetch(target, field, { + matcher = function(cset, block, filter) + local current = cset.current + return criteria.matches(current._criteria, block._criteria.terms or {}) or + criteria.matches(block._criteria, current._criteria.terms or {}) + end + }) + local mask = path.wildcards(value) for _, item in ipairs(current) do if item:match(mask) == item then recurse(item) end end - table.insert(removes, value) - else local value, err, additional = api.checkValue(field, value) if err then @@ -1100,9 +1105,7 @@ function configuration(terms) if terms then - if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or - (terms == "*") - then + if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or (terms == "*") then terms = nil end configset.addblock(api.scope.current, {terms}, os.getcwd()) @@ -1119,9 +1122,7 @@ function filter(terms) if terms then - if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or - (terms == "*") - then + if (type(terms) == "table" and #terms == 1 and terms[1] == "*") or (terms == "*") then terms = nil end local ok, err = configset.addFilter(api.scope.current, {terms}, os.getcwd()) diff --git a/src/base/configset.lua b/src/base/configset.lua index 20f7e30d..a6e835cf 100644 --- a/src/base/configset.lua +++ b/src/base/configset.lua @@ -81,6 +81,15 @@ end + function configset._dofilter(cset, block, filter) + if not filter.matcher then + return (cset.compiled or criteria.matches(block._criteria, filter)) + else + return filter.matcher(cset, block, filter) + end + end + + function configset._fetchDirect(cset, field, filter, ctx, origin) -- If the originating configset hasn't been compiled, then the value will still -- be on that configset. @@ -107,7 +116,7 @@ filter.files = path.getrelative(basedir, abspath) end - if value ~= nil and (cset.compiled or criteria.matches(block._criteria, filter)) then + if value ~= nil and configset._dofilter(cset, block, filter) then -- If value is an object, return a copy of it so that any -- changes later made to it by the caller won't alter the -- original value (that was a tough bug to find) @@ -181,7 +190,7 @@ filter.files = path.getrelative(basedir, abspath) end - if cset.compiled or criteria.matches(block._criteria, filter) then + if configset._dofilter(cset, block, filter) then if block._removes and block._removes[key] then remove(block._removes[key]) end diff --git a/src/base/criteria.lua b/src/base/criteria.lua index 643020cc..7c224fbe 100644 --- a/src/base/criteria.lua +++ b/src/base/criteria.lua @@ -94,6 +94,7 @@ local crit = {} crit.patterns = patterns crit.data = criteria._compile(patterns) + crit.terms = terms return crit end diff --git a/tests/_tests.lua b/tests/_tests.lua index 421fe715..f7f2effc 100644 --- a/tests/_tests.lua +++ b/tests/_tests.lua @@ -50,6 +50,7 @@ return { "api/test_register.lua", "api/test_string_kind.lua", "api/test_table_kind.lua", + "api/test_deprecations.lua", -- Control system tests "test_premake.lua", diff --git a/tests/api/test_deprecations.lua b/tests/api/test_deprecations.lua new file mode 100644 index 00000000..13323e51 --- /dev/null +++ b/tests/api/test_deprecations.lua @@ -0,0 +1,65 @@ +-- +-- tests/api/test_table_kind.lua +-- Tests the table API value type. +-- Copyright (c) 2012-2014 Jason Perkins and the Premake project +-- + + local suite = test.declare("api_deprecations") + local api = premake.api + + + function suite.setup() + workspace("MyWorkspace") + configurations { "Debug", "Release" } + end + + function suite.setsNewValue_whenOldValueIsRemovedViaWildcard_inSubConfig() + local prj = project "MyProject" + filter { "configurations:Debug" } + flags { "Symbols" } + + filter { "*" } + removeflags { "*" } + + -- test output. + local cfg = test.getconfig(prj, "Debug", platform) + test.isequal("Default", cfg.Symbols) + end + + + function suite.setsNewValue_whenOldValueIsRemovedInOtherConfig_inSubConfig() + local prj = project "MyProject" + flags { "Symbols" } + + filter { "configurations:Release" } + removeflags { "*" } + + -- test output. + test.isequal("On", test.getconfig(prj, "Debug", platform).Symbols) + test.isequal("Default", test.getconfig(prj, "Release", platform).Symbols) + end + + + function suite.dontRemoveFlagIfSetThroughNewApi() + local prj = project "MyProject" + floatingpoint "Fast" + removeflags "*" + + -- test output. + local cfg = test.getconfig(prj, "Debug", platform) + test.isequal("Fast", cfg.floatingpoint) + end + + + function suite.setsNewValue_whenOldValueFromParentIsRemovedInOtherConfig_inSubConfig() + flags { "Symbols" } + + local prj = project "MyProject" + filter { "configurations:Release" } + removeflags { "*" } + + -- test output. + test.isequal("On", test.getconfig(prj, "Debug", platform).Symbols) + test.isequal("Default", test.getconfig(prj, "Release", platform).Symbols) + end +