diff options
author | Jason Perkins <starkos@industriousone.com> | 2011-07-20 02:07:30 +0400 |
---|---|---|
committer | Jason Perkins <starkos@industriousone.com> | 2011-07-20 02:07:30 +0400 |
commit | 38692f2e193c7d2ba2c463f3bcdd1e445a785f15 (patch) | |
tree | 3dce989d8d4ec7f8440728ded3142421eec64712 /src/base | |
parent | a06602621f46f5f9e3f0144a7c73677c6872dbfa (diff) |
Flipped vpaths syntax, now ['group']={'pattern(s)'...}
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/api.lua | 30 | ||||
-rw-r--r-- | src/base/bake.lua | 2 | ||||
-rw-r--r-- | src/base/project.lua | 31 | ||||
-rw-r--r-- | src/base/table.lua | 21 |
4 files changed, 65 insertions, 19 deletions
diff --git a/src/base/api.lua b/src/base/api.lua index b78ad19..86cc26b 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -458,8 +458,8 @@ return container, msg end - - + + -- -- Adds values to an array field of a solution/project/configuration. `ctype` @@ -542,36 +542,30 @@ -- specifies the container type (see premake.getobject) for the field. -- - function premake.setkeyvalue(ctype, fieldname, value) + function premake.setkeyvalue(ctype, fieldname, values) local container, err = premake.getobject(ctype) if not container then error(err, 4) end if not container[fieldname] then - container[fieldname] = { } + container[fieldname] = {} end - if type(value) ~= "table" then + if type(values) ~= "table" then error("invalid value; table expected", 4) end - local result = container[fieldname] + local field = container[fieldname] - local function doinsert(tbl, errordepth) - for key,value in pairs(tbl) do - if type(value) == "table" then - doinsert(value, errordepth + 1) - elseif type(key) == "string" and type(value) == "string" then - result[key] = value - else - error("invalid value; both key and value must be a string", errordepth) - end + for key,value in pairs(values) do + if not field[key] then + field[key] = {} end + table.insertflat(field[key], value) end - - doinsert(value, 4) - return container[fieldname] + + return field end diff --git a/src/base/bake.lua b/src/base/bake.lua index 8c7ca77..fe511cb 100644 --- a/src/base/bake.lua +++ b/src/base/bake.lua @@ -146,7 +146,7 @@ local tbl = dest or { } if kind == "keyvalue" then for key, value in pairs(src) do - tbl[key] = value + tbl[key] = mergefield("list", tbl[key], value) end else for _, item in ipairs(src) do diff --git a/src/base/project.lua b/src/base/project.lua index 1d221d5..6111ff4 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -537,6 +537,36 @@ -- if there is no match, return the input filename local vpath = filename + for replacement,patterns in pairs(prj.vpaths) do + for _,pattern in ipairs(patterns) do + -- does the filename match this vpath pattern? + local i = vpath:find(path.wildcards(pattern)) + if i == 1 then + -- yes; trim the leading portion of the path + i = pattern:find("*", 1, true) or (pattern:len() + 1) + local leaf = vpath:sub(i) + if leaf:startswith("/") then + leaf = leaf:sub(2) + end + + -- check for (and remove) stars in the replacement pattern. + -- If there are none, then trim all path info from the leaf + -- and use just the filename in the replacement (stars should + -- really only appear at the end; I'm cheating here) + local stem = "" + if replacement:len() > 0 then + stem, stars = replacement:gsub("%*", "") + if stars == 0 then + leaf = path.getname(leaf) + end + end + + vpath = path.join(stem, leaf) + end + end + end + +--[[ for pattern, replacement in pairs(prj.vpaths) do -- does the filename match this vpath pattern? local i = vpath:find(path.wildcards(pattern)) @@ -563,6 +593,7 @@ vpath = path.join(stem, leaf) end end +--]] -- remove any dot ("./", "../") patterns from the start of the path local changed diff --git a/src/base/table.lua b/src/base/table.lua index 3aeb962..ff874aa 100644 --- a/src/base/table.lua +++ b/src/base/table.lua @@ -74,6 +74,27 @@ -- +-- Inserts a value of array of values into a table. If the value is +-- itself a table, its contents are enumerated and added instead. So +-- these inputs give these outputs: +-- +-- "x" -> { "x" } +-- { "x", "y" } -> { "x", "y" } +-- { "x", { "y" }} -> { "x", "y" } +-- + + function table.insertflat(tbl, values) + if type(values) == "table" then + for _, value in ipairs(values) do + table.insertflat(tbl, value) + end + else + table.insert(tbl, values) + end + end + + +-- -- Returns true if the table is empty, and contains no indexed or keyed values. -- |