diff options
Diffstat (limited to '3rdparty/genie/src/base/path.lua')
-rw-r--r-- | 3rdparty/genie/src/base/path.lua | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/3rdparty/genie/src/base/path.lua b/3rdparty/genie/src/base/path.lua index ee0a928fab3..742d36be523 100644 --- a/3rdparty/genie/src/base/path.lua +++ b/3rdparty/genie/src/base/path.lua @@ -9,12 +9,12 @@ -- Get the absolute file path from a relative path. The requested -- file path doesn't actually need to exist. -- - + function path.getabsolute(p) -- normalize the target path p = path.translate(p, "/") if (p == "") then p = "." end - + -- if the directory is already absolute I don't need to do anything local result = iif (path.isabsolute(p), nil, os.getcwd()) @@ -34,13 +34,13 @@ end end end - + -- if I end up with a trailing slash remove it result = iif(result:endswith("/"), result:sub(1, -2), result) - + return result end - + -- -- Retrieve the filename portion of a path, without any extension. @@ -70,7 +70,7 @@ end -- --- Retrieve the directory portion of a path, or an empty string if +-- Retrieve the directory portion of a path, or an empty string if -- the path does not include a directory. -- @@ -111,9 +111,9 @@ return "" end end - - - + + + -- -- Retrieve the filename portion of a path. -- @@ -126,8 +126,8 @@ return p end end - - + + -- -- Returns the relative path from src to dest. -- @@ -141,13 +141,13 @@ if (src == dst) then return "." end - + -- dollar macro? Can't tell what the real path is; use absolute -- This enables paths like $(SDK_ROOT)/include to work correctly. if dst:startswith("$") then return dst end - + src = src .. "/" dst = dst .. "/" @@ -165,19 +165,19 @@ break end end - + -- if they have nothing in common return absolute path local first = src:find("/", 0, true) if idx <= first then return dst:sub(1, -2) end - - -- trim off the common directories from the front + + -- trim off the common directories from the front src = src:sub(idx + 1) dst = dst:sub(idx + 1) - + -- back up from dst to get to this common parent - local result = "" + local result = "" idx = src:find("/") while (idx) do result = result .. "../" @@ -190,7 +190,7 @@ -- remove the trailing slash return result:sub(1, -2) end - + -- -- Returns true if the filename represents a C/C++ source code file. This check @@ -203,13 +203,13 @@ local ext = path.getextension(fname):lower() return table.contains(extensions, ext) end - - function path.iscppfile(fname) - local extensions = { ".cc", ".cpp", ".cxx", ".c", ".s", ".m", ".mm" } + + function path.iscxfile(fname) + local extensions = { ".cx" } local ext = path.getextension(fname):lower() return table.contains(extensions, ext) end - + function path.isobjcfile(fname) local extensions = { ".m", ".mm" } local ext = path.getextension(fname):lower() @@ -228,6 +228,16 @@ return table.contains(extensions, ext) end + function path.isSourceFile(fname) + local extensions = { ".cc", ".cpp", ".cxx", ".c", ".s", ".m", ".mm" } + local ext = path.getextension(fname):lower() + return table.contains(extensions, ext) + end + + function path.isSourceFileVS(fname) + return path.isSourceFile(fname) + or path.iscxfile(fname) + end -- -- Returns true if the filename represents a Windows resource file. This check @@ -240,10 +250,10 @@ return table.contains(extensions, ext) end - + -- -- Join one or more pieces of a path together into a single path. --- +-- -- @param ... -- One or more path strings. -- @return @@ -256,7 +266,7 @@ if numargs == 0 then return ""; end - + local allparts = {} for i = numargs, 1, -1 do local part = select(i, ...) @@ -265,14 +275,14 @@ while part:endswith("/") do part = part:sub(1, -2) end - + table.insert(allparts, 1, part) if path.isabsolute(part) then break end end end - + return table.concat(allparts, "/") end @@ -287,8 +297,8 @@ p = path.getrelative(newbase, p) return p end - - + + -- -- Convert the separators in a path from one form to another. If `sep` -- is nil, then a platform-specific separator is used. @@ -333,11 +343,11 @@ -- have competing star replacements to worry about pattern = pattern:gsub("%*%*", "\001") pattern = pattern:gsub("%*", "\002") - + -- Replace the placeholders with their Lua patterns pattern = pattern:gsub("\001", ".*") pattern = pattern:gsub("\002", "[^/]*") - + return pattern end |