diff options
author | Jason Perkins <starkos@industriousone.com> | 2013-11-12 16:49:14 +0400 |
---|---|---|
committer | Jason Perkins <starkos@industriousone.com> | 2013-11-12 16:49:14 +0400 |
commit | 77f3d5249efb979be79c73a2762babab5d6d5d6d (patch) | |
tree | 402f6dc97a6bb27754fb3ec8a97ce166c5a93341 | |
parent | ee42d412fa82529f388573d9d71f0cfc85fb4304 (diff) |
Fix virtual path building for patterns like "filename.*"
-rw-r--r-- | src/base/project.lua | 44 | ||||
-rw-r--r-- | tests/project/test_vpaths.lua | 23 |
2 files changed, 47 insertions, 20 deletions
diff --git a/src/base/project.lua b/src/base/project.lua index 90fdefc..e9a3c7a 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -568,24 +568,42 @@ -- the original path is returned. -- - function premake.project.getvpath(prj, filename) - -- if there is no match, return the input filename - local vpath = filename + function premake.project.getvpath(prj, abspath) + -- If there is no match, the result is the original filename + local vpath = abspath - for replacement,patterns in pairs(prj.vpaths) do - for _,pattern in ipairs(patterns) do + -- The file's name must be maintained in the resulting path; use these + -- to make sure I don't cut off too much - -- does the filename match this vpath pattern? - local i = vpath:find(path.wildcards(pattern)) + local fname = path.getname(abspath) + local max = abspath:len() - fname:len() + + -- Look for matching patterns + for replacement, patterns in pairs(prj.vpaths or {}) do + for _, pattern in ipairs(patterns) do + local i = abspath:find(path.wildcards(pattern)) if i == 1 then - -- yes; trim the pattern out of the target file's path - local leaf + + -- Trim out the part of the name that matched the pattern; what's + -- left is the part that gets appended to the replacement to make + -- the virtual path. So a pattern like "src/**.h" matching the + -- file src/include/hello.h, I want to trim out the src/ part, + -- leaving include/hello.h. + + -- Find out where the wildcard appears in the match. If there is + -- no wildcard, the match includes the entire pattern + i = pattern:find("*", 1, true) or (pattern:len() + 1) - if i < filename:len() then - leaf = filename:sub(i) + + -- Trim, taking care to keep the actual file name intact. + + local leaf + if i < max then + leaf = abspath:sub(i) else - leaf = path.getname(filename) + leaf = fname end + if leaf:startswith("/") then leaf = leaf:sub(2) end @@ -594,6 +612,7 @@ -- 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("%*", "") @@ -605,6 +624,7 @@ end vpath = path.join(stem, leaf) + end end end diff --git a/tests/project/test_vpaths.lua b/tests/project/test_vpaths.lua index 3055986..66322d4 100644 --- a/tests/project/test_vpaths.lua +++ b/tests/project/test_vpaths.lua @@ -5,7 +5,7 @@ -- T.project_vpaths = { } - local suite = T.project_vpaths + local suite = T.project_vpaths local project = premake.project @@ -26,7 +26,7 @@ return project.getvpath(prj, cfg.files[1]) end - + -- -- Test simple replacements -- @@ -94,7 +94,7 @@ files { "src/myproject/hello.h" } vpaths { ["Source/Headers"] = "**.h" } test.isequal("Source/Headers/hello.h", run()) - end + end function suite.MatchFilePattern_ToGroup_WithTrailingSlash() files { "src/myproject/hello.h" } @@ -106,32 +106,39 @@ files { "src/myproject/hello.h" } vpaths { ["Group/Headers"] = "**.h" } test.isequal("Group/Headers/hello.h", run()) - end + end function suite.MatchFilePattern_ToGroup_Nested() files { "src/myproject/hello.h" } vpaths { ["Headers/*"] = "**.h" } test.isequal("Headers/src/myproject/hello.h", run()) - end + end function suite.MatchFilePattern_ToGroup_Nested_OneStar() files { "src/myproject/hello.h" } vpaths { ["Headers/*"] = "**.h" } test.isequal("Headers/src/myproject/hello.h", run()) - end + end function suite.MatchFilePatternWithPath_ToGroup_Nested() files { "src/myproject/hello.h" } vpaths { ["Headers/*"] = "src/**.h" } test.isequal("Headers/myproject/hello.h", run()) - end + end + + function suite.matchBaseFileName_onWildcardExtension() + files { "hello.cpp" } + vpaths { ["Sources"] = "hello.*" } + test.isequal("Sources/hello.cpp", run()) + end + -- -- Test with project locations -- - function suite.MatchPath_OnProjectLocationSet() + function suite.MatchPath_OnProjectLocationSet() location "build" files "src/hello.h" vpaths { [""] = "src" } |