summaryrefslogtreecommitdiff
path: root/xmake/core/base/path.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-22 20:14:31 +0800
committerruki <[email protected]>2022-05-22 20:14:31 +0800
commitf72603fcc27a74339b4bd1df794cf1382504c2f5 (patch)
treeeeda31ec7d6c2c996e668b0e1eab80f301f5e154 /xmake/core/base/path.lua
parentbf34cd08b63a0a1c8314ca8b81c7fe04cc8531f1 (diff)
fix path
Diffstat (limited to 'xmake/core/base/path.lua')
-rw-r--r--xmake/core/base/path.lua25
1 files changed, 20 insertions, 5 deletions
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua
index 4f534bb50..df99ef30e 100644
--- a/xmake/core/base/path.lua
+++ b/xmake/core/base/path.lua
@@ -28,6 +28,7 @@ local _instance = _instance or {}
-- save original interfaces
path._absolute = path._absolute or path.absolute
+path._relative = path._relative or path.relative
-- new a path
function _instance.new(p, transform)
@@ -98,8 +99,12 @@ function _instance:directory()
return path.new(path.directory(self:str()), self._TRANSFORM)
end
-function _instance:absolute()
- return path.new(path.absolute(self:str()), self._TRANSFORM)
+function _instance:absolute(rootdir)
+ return path.new(path.absolute(self:str(), rootdir), self._TRANSFORM)
+end
+
+function _instance:relative(rootdir)
+ return path.new(path.relative(self:str(), rootdir), self._TRANSFORM)
end
function _instance:join(...)
@@ -173,9 +178,19 @@ if not path.directory then
end
-- get absolute path
-function path.absolute(p)
- p = tostring(p)
- return path._absolute(p)
+function path.absolute(p, rootdir)
+ if rootdir then
+ rootdir = tostring(rootdir)
+ end
+ return path._absolute(tostring(p), rootdir)
+end
+
+-- get relative path
+function path.relative(p, rootdir)
+ if rootdir then
+ rootdir = tostring(rootdir)
+ end
+ return path._relative(tostring(p), rootdir)
end
-- get the filename of the path