diff options
| author | ruki <[email protected]> | 2024-02-17 22:40:28 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-02-17 22:40:28 +0800 |
| commit | 07064cf6fef8d0a1eb9e697f6c7190f51632aaf8 (patch) | |
| tree | b42f1cb63101a501521d997a98ec8b87de9716bc /xmake/core/base/path.lua | |
| parent | 0c539a2b863b1306057f4d96a95ca4a350a53946 (diff) | |
add path.unix
Diffstat (limited to 'xmake/core/base/path.lua')
| -rw-r--r-- | xmake/core/base/path.lua | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 59c891a3c..94efb562b 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -29,6 +29,7 @@ local _instance = _instance or {} -- save original interfaces path._absolute = path._absolute or path.absolute path._relative = path._relative or path.relative +path._translate = path._translate or path.translate -- new a path function _instance.new(p, transform) @@ -88,6 +89,10 @@ function _instance:translate(opt) return path.new(path.translate(self:str(), opt), self._TRANSFORM) end +function _instance:unix() + return self:translate({unix = true}) +end + function _instance:filename() return path.filename(self:str()) end @@ -151,6 +156,21 @@ function _instance:__todisplay() return "<path: " .. (self:empty() and "empty" or self:str()) .. ">" end +-- get unix-style path, it is usually used on windows +-- @see https://github.com/xmake-io/xmake/issues/4731 +function path.unix(p) + return (tostring(p):gsub(path.sep(), "/")) +end + +-- translate path +-- +-- @param p the path +-- @param opt the option, e.g. {normalize = true} +-- +function path.translate(p, opt) + return path._translate(tostring(p), opt) +end + -- path.translate: -- - transform the path separator -- - expand the user directory with the prefix: ~ @@ -162,8 +182,7 @@ end -- - reduce "/xxx/.." => "/" -- function path.normalize(p) - p = tostring(p) - return path.translate(p, {normalize = true}) + return path.translate(tostring(p), {normalize = true}) end -- get the directory of the path, compatible with lower version core binary |
