diff --git a/src/actions/xcode/xcode_common.lua b/src/actions/xcode/xcode_common.lua index 6f430dc5..bda20e4f 100644 --- a/src/actions/xcode/xcode_common.lua +++ b/src/actions/xcode/xcode_common.lua @@ -397,7 +397,7 @@ _p(3,'name = Products;') else _p(3,'name = "%s";', node.name) - if node.path then + if node.path and not node.isvpath then local p = node.path if node.parent.path then p = path.getrelative(node.parent.path, node.path) diff --git a/src/base/project.lua b/src/base/project.lua index 8e891684..1f40cde3 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -21,8 +21,15 @@ local tr = premake.tree.new(prj.name) tr.project = prj + local isvpath + + local function onadd(node) + node.isvpath = isvpath + end + for fcfg in premake.project.eachfile(prj) do - local node = premake.tree.add(tr, fcfg.vpath) + isvpath = (fcfg.name ~= fcfg.vpath) + local node = premake.tree.add(tr, fcfg.vpath, onadd) node.cfg = fcfg end diff --git a/src/base/tree.lua b/src/base/tree.lua index 2d610018..527aa4cf 100644 --- a/src/base/tree.lua +++ b/src/base/tree.lua @@ -31,11 +31,14 @@ -- The tree to contain the new node. -- @param p -- The path of the new node. +-- @param onaddfunc +-- A function to call when a new node is added to the tree. Receives the +-- new node as an argument. -- @returns -- The new tree node. -- - function premake.tree.add(tr, p) + function premake.tree.add(tr, p, onaddfunc) -- Special case "." refers to the current node if p == "." then return tr @@ -43,7 +46,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)) + local parentnode = tree.add(tr, path.getdirectory(p), onaddfunc) -- Another special case, ".." refers to the parent node and doesn't create anything local childname = path.getname(p) @@ -59,6 +62,9 @@ if not childnode or childnode.path ~= p then childnode = tree.insert(parentnode, tree.new(childname)) childnode.path = p + if onaddfunc then + onaddfunc(childnode) + end end return childnode diff --git a/tests/actions/xcode/test_xcode_project.lua b/tests/actions/xcode/test_xcode_project.lua index 8437ee0b..642e68e9 100644 --- a/tests/actions/xcode/test_xcode_project.lua +++ b/tests/actions/xcode/test_xcode_project.lua @@ -81,6 +81,19 @@ ]] end + function suite.PBXBuildFile_IgnoresVpaths() + files { "source.h", "source.c", "source.cpp", "Info.plist" } + vpaths { ["Source Files"] = { "**.c", "**.cpp" } } + prepare() + xcode.PBXBuildFile(tr) + test.capture [[ +/* Begin PBXBuildFile section */ + [source.c:build] /* source.c in Sources */ = {isa = PBXBuildFile; fileRef = [source.c] /* source.c */; }; + [source.cpp:build] /* source.cpp in Sources */ = {isa = PBXBuildFile; fileRef = [source.cpp] /* source.cpp */; }; +/* End PBXBuildFile section */ + ]] + end + --------------------------------------------------------------------------- -- PBXFileReference tests @@ -467,6 +480,34 @@ end + function suite.PBXGroup_OnVpaths() + files { "include/premake/source.h" } + vpaths { ["Headers"] = "**.h" } + prepare() + xcode.PBXGroup(tr) + test.capture [[ +/* Begin PBXGroup section */ + [MyProject] /* MyProject */ = { + isa = PBXGroup; + children = ( + [Headers] /* Headers */, + [Products] /* Products */, + ); + name = "MyProject"; + sourceTree = ""; + }; + [Headers] /* Headers */ = { + isa = PBXGroup; + children = ( + [source.h] /* source.h */, + ); + name = "Headers"; + sourceTree = ""; + }; + ]] + end + + --------------------------------------------------------------------------- -- PBXNativeTarget tests ---------------------------------------------------------------------------