diff options
| author | ruki <[email protected]> | 2020-02-14 23:02:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-14 12:12:28 +0800 |
| commit | ffb92f48bcfbe4c34d027a7e01ff27b18b97c431 (patch) | |
| tree | d1878aeac54ac4faf1905a964800ff8956cc78f7 /xmake/core/base | |
| parent | b44a566e16e9022428d0f4453c8f1df0af1577d5 (diff) | |
improve host and arch
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/os.lua | 23 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 47 |
2 files changed, 35 insertions, 35 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 5c193a48d..05e12fa3a 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -800,16 +800,31 @@ function os.isexec(filepath) return os.isfile(filepath) end --- get the system host +-- get host of subsystem, maybe msys/cygwin on windows function os.host() return xmake._HOST end --- get the system architecture +-- get host architecture of subsystem function os.arch() return xmake._ARCH end +-- get system host, msys/cygwin are always windows +function os.syshost() + return xmake._SYSHOST +end + +-- get system host architecture +function os.sysarch() + return xmake._SYSARCH +end + +-- get features +function os.features() + return xmake._FEATURES +end + -- the current host is belong to the given hosts? function os.is_host(...) @@ -883,7 +898,7 @@ function os.user_agent() if os._USER_AGENT == nil then -- init systems - local systems = {macosx = "Macintosh", linux = "Linux", windows = "Windows"} + local systems = {macosx = "Macintosh", linux = "Linux", windows = "Windows", msys = "MSYS", cygwin = "Cygwin"} -- os user agent local os_user_agent = "" @@ -892,7 +907,7 @@ function os.user_agent() if ok then os_user_agent = ("Intel Mac OS X " .. (osver or "")):trim() end - elseif os.host() == "linux" then + elseif os.host() == "linux" or os.host() == "msys" or os.host() == "cygwin" then local ok, osarch = os.iorun("uname -m") if ok then os_user_agent = (os_user_agent .. " " .. (osarch or "")):trim() diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index 8332925d5..d960509e1 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -22,14 +22,11 @@ local path = path or {} -- load modules -local string = require("base/string") +local string = require("base/string") -- get the directory of the path function path.directory(p) - - -- check assert(p) - local i = p:find_last("[/\\]") if i then if i > 1 then i = i - 1 end @@ -41,10 +38,7 @@ end -- get the filename of the path function path.filename(p) - - -- check assert(p) - local i = p:find_last("[/\\]") if i then return p:sub(i + 1) @@ -55,10 +49,7 @@ end -- get the basename of the path function path.basename(p) - - -- check assert(p) - local name = path.filename(p) local i = name:find_last(".", true) if i then @@ -70,11 +61,7 @@ end -- get the file extension of the path: .xxx function path.extension(p) - - -- check assert(p) - - -- get extension local i = p:find_last(".", true) if i then return p:sub(i) @@ -85,36 +72,37 @@ end -- join path function path.join(p, ...) - - -- check assert(p) - - -- join them for _, name in ipairs({...}) do p = p .. "/" .. name end - - -- translate path return path.translate(p) end -- split path by the separator function path.split(p) - - -- check assert(p) - return p:split("[/\\]") end -- get the path seperator function path.sep() - return xmake._HOST == "windows" and '\\' or '/' + local sep = path._SEP + if not sep then + sep = xmake._FEATURES.path_sep + path._SEP = sep + end + return sep end -- get the path seperator of environment variable function path.envsep() - return xmake._HOST == "windows" and ';' or ':' + local envsep = path._ENVSEP + if not envsep then + envsep = xmake._FEATURES.path_envsep + path._ENVSEP = envsep + end + return envsep end -- split environment variable with `path.envsep()`, @@ -125,7 +113,7 @@ function path.splitenv(env_path) assert(env_path) local result = {} - if xmake._HOST == "windows" then + if xmake._SYSHOST == "windows" then while #env_path > 0 do if env_path:startswith(path.envsep()) then env_path = env_path:sub(2) @@ -168,7 +156,7 @@ function path.joinenv(env_table) end local envsep = path.envsep() - if xmake._HOST == "windows" then + if xmake._SYSHOST == "windows" then local tab = {} for _, v in ipairs(env_table) do if v ~= "" then @@ -186,12 +174,9 @@ end -- the last character is the path seperator? function path.islastsep(p) - - -- check assert(p) - local sep = p:sub(#p, #p) - return xmake._HOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/') + return xmake._SYSHOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/') end -- convert path pattern to a lua pattern |
