Allow filters to specify field value aliases in the conditions

This commit is contained in:
Jason Perkins 2015-02-25 17:38:16 -05:00
parent 0ef03eb13a
commit f9270e21cc
4 changed files with 42 additions and 5 deletions

View File

@ -4,3 +4,7 @@
See https://bitbucket.org/premake/premake-dev/wiki/What's_New_in_5.0
for the complete list of changes from the Premake 4.x series.
Since 5.0-alpha1:
* filter() now accepts field value aliases in the conditions

View File

@ -5,11 +5,13 @@
-- and wildcard matches. Provides functions match match these criteria
-- against various contexts.
--
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
premake.criteria = criteria
local criteria = premake.criteria
local p = premake
p.criteria = criteria -- criteria namespace is defined in C host
local criteria = p.criteria
--
@ -69,6 +71,15 @@
if prefix and not criteria._validPrefixes[prefix] then
return nil, string.format("Invalid field prefix '%s'", prefix)
end
-- check for field value aliases
if prefix then
local fld = p.field.get(prefix)
if fld and fld.aliases then
word[1] = fld.aliases[word[1]] or word[1]
end
end
table.insert(pattern, word)
end

View File

@ -19,6 +19,7 @@
-- Lists to hold all of the registered fields and data kinds
field._list = {}
field._loweredList = {}
field._kinds = {}
-- For historical reasons
@ -94,6 +95,8 @@
end
field._list[f.name] = f
field._loweredList[f.name:lower()] = f
return f
end
@ -105,6 +108,7 @@
function field.unregister(f)
field._list[f.name] = nil
field._loweredList[f.name:lower()] = nil
end
@ -253,7 +257,7 @@
---
function field.get(name)
return field._list[name]
return field._list[name] or field._loweredList[name:lower()]
end

View File

@ -1,7 +1,7 @@
--
-- tests/base/test_criteria.lua
-- Test suite for the criteria matching API.
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
-- Copyright (c) 2012-2015 Jason Perkins and the Premake project
--
local suite = test.declare("criteria")
@ -308,3 +308,21 @@
test.isnil(crit)
test.isnotnil(err)
end
--
-- Should respect field value aliases, if present.
--
function suite.passes_onAliasedValue()
premake.api.addAliases("system", { ["gnu-linux"] = "linux" })
crit = criteria.new { "system:gnu-linux" }
test.istrue(criteria.matches(crit, { system="linux" }))
end
function suite.passes_onAliasedValue_withMixedCase()
premake.api.addAliases("system", { ["gnu-linux"] = "linux" })
crit = criteria.new { "System:GNU-Linux" }
test.istrue(criteria.matches(crit, { system="linux" }))
end