diff --git a/CHANGES.txt b/CHANGES.txt index 6ad83e2b..befa9d12 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/src/base/criteria.lua b/src/base/criteria.lua index 54c9c93c..b0f3d2c5 100644 --- a/src/base/criteria.lua +++ b/src/base/criteria.lua @@ -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 diff --git a/src/base/field.lua b/src/base/field.lua index 2c4303ab..e6b9c7fa 100644 --- a/src/base/field.lua +++ b/src/base/field.lua @@ -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 diff --git a/tests/base/test_criteria.lua b/tests/base/test_criteria.lua index fb58dc79..29d61dd4 100644 --- a/tests/base/test_criteria.lua +++ b/tests/base/test_criteria.lua @@ -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 +