Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/premake-4.x-stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorJason Perkins <starkos@industriousone.com>2011-06-09 23:15:39 +0400
committerJason Perkins <starkos@industriousone.com>2011-06-09 23:15:39 +0400
commit96be30af0f63306753416a5948351cfcb46bc00a (patch)
tree127bb0671201503ddfadef74081026b3b856b1c5 /src/base
parent2580bd7798aa41ae14fd1503ed0534aaec7f94ba (diff)
Added project.getvpath() to map from real paths
Diffstat (limited to 'src/base')
-rw-r--r--src/base/project.lua43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/base/project.lua b/src/base/project.lua
index 1e70633..261f0fa 100644
--- a/src/base/project.lua
+++ b/src/base/project.lua
@@ -524,7 +524,48 @@
end
-
+
+--
+-- Given a source file path, return a corresponding virtual path based on
+-- the vpath entries in the project. If no matching vpath entry is found,
+-- the original path is returned.
+--
+
+ function premake.project.getvpath(prj, filename)
+ -- if there is no match, return the input filename
+ local vpath = filename
+
+ for pattern, replacement in pairs(prj.vpaths) 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
+
+ return vpath
+ end
+
+
--
-- Returns true if the solution contains at least one C/C++ project.
--