Use boolean fields rather than string decorations for extra API field information (Richard Geary)

This commit is contained in:
Jason Perkins 2014-01-14 16:43:14 -05:00
parent d9a9919f49
commit 98ee892303
6 changed files with 113 additions and 83 deletions

View File

@ -85,21 +85,24 @@
api.register {
name = "buildcommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "buildoptions",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "buildoutputs",
scope = "config",
kind = "file-list",
kind = "file",
list = true,
tokens = true,
}
@ -113,33 +116,38 @@
api.register {
name = "cleancommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "configmap",
scope = "config",
kind = "key-array"
kind = "array",
keyed = true,
}
api.register {
name = "configurations",
scope = "project",
kind = "string-list",
kind = "string",
list = true,
}
api.register {
name = "copylocal",
scope = "config",
kind = "mixed-list",
kind = "mixed",
list = true,
tokens = true,
}
api.register {
name = "debugargs",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
@ -160,7 +168,8 @@
api.register {
name = "debugenvs",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
@ -176,21 +185,24 @@
api.register {
name = "defines",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "dependson",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "deploymentoptions",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
@ -209,14 +221,16 @@
api.register {
name = "files",
scope = "config",
kind = "file-list",
kind = "file",
list = true,
tokens = true,
}
api.register {
name = "flags",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
allowed = {
"Component", -- DEPRECATED
"DebugEnvsDontMerge",
@ -283,14 +297,16 @@
api.register {
name = "forceincludes",
scope = "config",
kind = "mixed-list",
kind = "mixed",
list = true,
tokens = true,
}
api.register {
name = "forceusings",
scope = "config",
kind = "file-list",
kind = "file",
list = true,
tokens = true,
}
@ -319,7 +335,8 @@
api.register {
name = "imageoptions",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
@ -368,7 +385,8 @@
api.register {
name = "includedirs",
scope = "config",
kind = "directory-list",
kind = "directory",
list = true,
tokens = true,
}
@ -400,21 +418,24 @@
api.register {
name = "libdirs",
scope = "config",
kind = "directory-list",
kind = "directory",
list = true,
tokens = true,
}
api.register {
name = "linkoptions",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "links",
scope = "config",
kind = "mixed-list",
kind = "mixed",
list = true,
tokens = true,
}
@ -428,11 +449,11 @@
api.register {
name = "makesettings",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "namespace",
scope = "project",
@ -489,55 +510,63 @@
api.register {
name = "platforms",
scope = "project",
kind = "string-list",
kind = "string",
list = true,
}
api.register {
name = "postbuildcommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "prebuildcommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "prelinkcommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "rebuildcommands",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "resdefines",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
api.register {
name = "resincludedirs",
scope = "config",
kind = "directory-list",
kind = "directory",
list = true,
tokens = true,
}
api.register {
name = "resoptions",
scope = "config",
kind = "string-list",
kind = "string",
list = true,
tokens = true,
}
@ -616,7 +645,8 @@
api.register {
name = "usingdirs",
scope = "config",
kind = "directory-list",
kind = "directory",
list = true,
tokens = true,
}
@ -656,7 +686,9 @@
api.register {
name = "vpaths",
scope = "project",
kind = "key-path-list",
kind = "path",
keyed = true,
list = true,
}
api.register {

View File

@ -44,6 +44,19 @@
error("name '" .. name .. "' in use", 2)
end
-- Translate the old "key-" and "-list" field kind modifiers to the
-- new boolean values (13 Jan 2014; should deprecate eventually)
if field.kind:startswith("key-") then
field.kind = field.kind:sub(5)
field.keyed = true
end
if field.kind:endswith("-list") then
field.kind = field.kind:sub(1, -6)
field.list = true
end
-- make sure there is a handler available for this kind of value
if not api.getsetter(field) then
error("invalid kind '" .. field.kind .. "'", 2)
@ -58,7 +71,7 @@
end
-- list values also get a removal function
if api.islistfield(field) and not api.iskeyedfield(field) then
if api.isListField(field) and not api.isKeyedField(field) then
_G["remove" .. name] = function(value)
return api.remove(field, value)
end
@ -67,8 +80,8 @@
-- if the field needs special handling, tell the config
-- set system about it
configset.registerfield(field.name, {
keyed = api.iskeyedfield(field),
merge = api.islistfield(field),
keyed = api.isKeyedField(field),
merge = api.isListField(field),
})
end
@ -86,7 +99,7 @@
function api.alias(original, alias)
_G[alias] = _G[original]
if api.islistfield(premake.fields[original]) then
if api.isListField(premake.fields[original]) then
_G["remove" .. alias] = _G["remove" .. original]
end
end
@ -236,7 +249,7 @@
end
local status, result = pcall(function ()
if api.iskeyedfield(field) then
if api.isKeyedField(field) then
api.setkeyvalue(target, field, value)
else
local setter = api.getsetter(field, true)
@ -266,7 +279,7 @@
if not value then return end
local target = api.gettarget(field.scope)
local kind = api.getbasekind(field)
local kind = field.kind
-- Build a list of values to be removed. If this field has deprecated
-- values, check to see if any of those are going to be removed by this
@ -392,7 +405,7 @@
-- for keyed list, I just make sure all keys are present,
-- no checking of values is done (yet)
if field.kind:startswith("key") then
if api.isKeyedField(field) then
for k,v in pairs(value1) do
if not value2[k] then
return false
@ -406,7 +419,7 @@
return true
-- for arrays, just see if the lengths match, for now
elseif field.kind:endswith("list") then
elseif api.isListField(field) then
return #value1 == #value2
-- everything else can use a simple compare
@ -416,33 +429,16 @@
end
--
-- Retrieve the base data kind of a field, by removing any key- prefix
-- or -list suffix and returning what's left.
--
function api.getbasekind(field)
local kind = field.kind
if kind:startswith("key-") then
kind = kind:sub(5)
end
if kind:endswith("-list") then
kind = kind:sub(1, -6)
end
return kind
end
--
-- Check the collection properties of a field.
--
function api.iskeyedfield(field)
return field.kind:startswith("key-")
function api.isKeyedField(field)
return field.keyed
end
function api.islistfield(field)
return field.kind:endswith("-list")
function api.isListField(field)
return field.list
end
@ -459,10 +455,10 @@
--
function api.getsetter(field, lists)
if lists and api.islistfield(field) then
if lists and api.isListField(field) then
return api.setlist
else
return api["set" .. api.getbasekind(field)]
return api["set" .. field.kind]
end
end

View File

@ -14,7 +14,7 @@
--
function suite.setup()
api.settest = function(target, name, field, value)
api.settest = function(target, name, field, value)
test_args = {
["target"] = target,
["name"] = name,
@ -31,9 +31,9 @@
api.settest = nil
end
--
-- Verify that the callback hands off control to setter for
-- the field's value kind.
@ -47,7 +47,7 @@
end
--
--
-- Verify that the target field name is getting passed to the setter.
--
@ -59,7 +59,7 @@
end
--
--
-- Verify that the field description is passed along to the setter.
--
@ -71,7 +71,7 @@
end
--
--
-- Verify that the value is passed along to the setter.
--
@ -111,7 +111,7 @@
--
-- If the field scope is "configuration" and there is an active configuration,
-- If the field scope is "configuration" and there is an active configuration,
-- it should be the target.
--
@ -129,7 +129,7 @@
--
function suite.keyObjectName_onKeyValue()
api.register { name = "testapi", kind = "key-test", scope = "project" }
api.register { name = "testapi", kind = "test", keyed = true, scope = "project" }
local sln = solution "MySolution"
testapi { key = "test" }
test.isequal("key", test_args.name)
@ -141,9 +141,9 @@
--
function suite.keyValueRaisesError_onSimpleValue()
api.register { name = "testapi", kind = "key-test", scope = "project" }
api.register { name = "testapi", kind = "test", keyed = true, scope = "project" }
local sln = solution "MySolution"
ok, err = pcall(function ()
ok, err = pcall(function ()
testapi "test"
end)
test.isfalse(ok)

View File

@ -15,7 +15,8 @@
function suite.setup()
api.register {
name = "testapi",
kind = "directory-list",
kind = "directory",
list = true,
scope = "project"
}
test.createsolution()

View File

@ -16,7 +16,8 @@
function suite.setup()
api.register {
name = "testapi",
kind = "string-list",
kind = "string",
list = true,
scope = "project",
allowed = { "first", "second", "third" }
}
@ -48,7 +49,7 @@
end
--
--
-- New values should be appended to any previous values.
--
@ -73,7 +74,7 @@
--
function suite.raisesError_onDisallowedValue()
ok, err = pcall(function ()
ok, err = pcall(function ()
testapi "NotAllowed"
end)
test.isfalse(ok)

View File

@ -69,9 +69,9 @@
--
function suite.raisesError_onInvalidKind()
ok, err = pcall(function ()
ok, err = pcall(function ()
api.register { name = "testapi", kind = "bogus", scope = "project" }
end)
end)
test.isfalse(ok)
end
@ -81,8 +81,8 @@
--
function suite.succeeds_onKeyValueForm()
ok, err = pcall(function ()
api.register { name = "testapi", kind = "key-string", scope = "project" }
end)
ok, err = pcall(function ()
api.register { name = "testapi", kind = "string", keyed = true, scope = "project" }
end)
test.istrue(ok)
end