Allow virtual paths to specify empty source tree root folders

This commit is contained in:
Jason Perkins 2013-09-12 10:40:52 -04:00
parent db22c65496
commit 18c6d90734
3 changed files with 37 additions and 4 deletions

View File

@ -31,11 +31,13 @@
-- The tree to contain the new node.
-- @param p
-- The path of the new node.
-- @param extraFields
-- A table containing key-value pairs to be added to any new nodes.
-- @returns
-- The new tree node.
--
function tree.add(tr, p)
function tree.add(tr, p, extraFields)
-- Special case "." refers to the current node
if p == "." then
return tr
@ -43,7 +45,7 @@
-- Look for the immediate parent for this new node, creating it if necessary.
-- Recurses to create as much of the tree as necessary.
local parentnode = tree.add(tr, path.getdirectory(p), onaddfunc)
local parentnode = tree.add(tr, path.getdirectory(p), extraFields)
-- Create the child if necessary
local childname = path.getname(p)
@ -51,6 +53,11 @@
if not childnode or childnode.path ~= p then
childnode = tree.insert(parentnode, tree.new(childname))
childnode.path = p
if extraFields then
for k,v in pairs(extraFields) do
childnode[k] = v
end
end
end
return childnode
@ -275,7 +282,7 @@
local node = tr.children[1]
-- if this node has no children (it is the last node in the tree) I'm done
if #node.children == 0 then
if #node.children == 0 or node.trim == false then
break
end

View File

@ -722,13 +722,22 @@
-- in the IDE, not the physical organization of the file system. So
-- virtual paths are used when adding nodes.
-- If the project script specifies a virtual path for a file, disable
-- the logic that could trim out empty root nodes from that path. If
-- the script writer wants an empty root node they should get it.
local flags
if fcfg.vpath ~= fcfg.relpath then
flags = { trim = false }
end
-- Virtual paths can overlap, potentially putting files with the same
-- name in the same folder, even though they have different paths on
-- the underlying filesystem. The tree.add() call won't overwrite
-- existing nodes, so provide the extra logic here. Start by getting
-- the parent folder node, creating it if necessary.
local parent = tree.add(tr, path.getdirectory(fcfg.vpath))
local parent = tree.add(tr, path.getdirectory(fcfg.vpath), flags)
local node = tree.insert(parent, tree.new(path.getname(fcfg.vpath)))
-- Pass through value fetches to the file configuration

View File

@ -267,3 +267,20 @@
tree.trimroot(tr)
test.isequal("tests", tr.children[1].path)
end
--
-- Nodes with the key "trim" set to false should be removed.
--
function suite.trimroot_respectsTrimFlag()
local n = tree.add(tr, "A")
tree.add(tr, "A/1")
n.trim = false
tree.trimroot(tr)
prepare()
test.capture [[
A
1
]]
end