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 | |
| parent | 0c539a2b863b1306057f4d96a95ca4a350a53946 (diff) | |
add path.unix
| -rw-r--r-- | xmake/core/base/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 23 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/format/main.lua | 2 |
4 files changed, 25 insertions, 6 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index d6c18cef3..2d7023ac4 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -330,7 +330,7 @@ function os.match(pattern, mode, callback) end -- translate path and remove some repeat separators - pattern = path.translate(pattern:gsub("|.*$", "")) + pattern = path.translate((pattern:gsub("|.*$", ""))) -- translate mode if type(mode) == "string" then 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 diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index e6fb98a7b..a1b2e414b 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1929,7 +1929,7 @@ function _instance:sourcefiles() if removed_count > 0 then table.remove_if(sourcefiles, function (i, sourcefile) for _, removed_file in ipairs(sourcefiles_removed) do - local pattern = path.translate(removed_file:gsub("|.*$", "")) + local pattern = path.translate((removed_file:gsub("|.*$", ""))) if pattern:sub(1, 2):find('%.[/\\]') then pattern = pattern:sub(3) end @@ -2116,7 +2116,7 @@ function _instance:headerfiles(outputdir, opt) if removed_count > 0 then table.remove_if(srcheaders, function (i, srcheader) for _, removed_file in ipairs(srcheaders_removed) do - local pattern = path.translate(removed_file:gsub("|.*$", "")) + local pattern = path.translate((removed_file:gsub("|.*$", ""))) if pattern:sub(1, 2):find('%.[/\\]') then pattern = pattern:sub(3) end diff --git a/xmake/plugins/format/main.lua b/xmake/plugins/format/main.lua index 85c5e00f9..57c63dda7 100644 --- a/xmake/plugins/format/main.lua +++ b/xmake/plugins/format/main.lua @@ -68,7 +68,7 @@ function _get_file_patterns(sourcefiles) end -- translate path and remove some repeat separators - pattern = path.translate(pattern:gsub("|.*$", "")) + pattern = path.translate((pattern:gsub("|.*$", ""))) -- remove "./" or '.\\' prefix if pattern:sub(1, 2):find('%.[/\\]') then |
