summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-14 23:02:04 +0800
committerruki <[email protected]>2020-02-14 12:12:28 +0800
commitffb92f48bcfbe4c34d027a7e01ff27b18b97c431 (patch)
treed1878aeac54ac4faf1905a964800ff8956cc78f7 /xmake
parentb44a566e16e9022428d0f4453c8f1df0af1577d5 (diff)
improve host and arch
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/_xmake_main.lua3
-rw-r--r--xmake/core/base/os.lua23
-rw-r--r--xmake/core/base/path.lua47
-rw-r--r--xmake/core/sandbox/modules/os.lua3
-rw-r--r--xmake/platforms/cygwin/config.lua10
-rw-r--r--xmake/platforms/msys/config.lua10
6 files changed, 43 insertions, 53 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index eb50d567d..5a553f507 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -23,6 +23,8 @@ xmake = xmake or {}
xmake._ARGV = _ARGV
xmake._HOST = _HOST
xmake._ARCH = _ARCH
+xmake._SYSHOST = _SYSHOST
+xmake._SYSARCH = _SYSARCH
xmake._VERSION = _VERSION
xmake._VERSION_SHORT = _VERSION_SHORT
xmake._PROGRAM_DIR = _PROGRAM_DIR
@@ -30,6 +32,7 @@ xmake._PROGRAM_FILE = _PROGRAM_FILE
xmake._PROJECT_DIR = _PROJECT_DIR
xmake._PROJECT_FILE = "xmake.lua"
xmake._WORKING_DIR = os.curdir()
+xmake._FEATURES = _FEATURES
function _loadfile_impl(filepath, mode, opt)
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
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index f6ce8e6b4..782082a7e 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -35,6 +35,8 @@ local sandbox_os = sandbox_os or {}
-- inherit some builtin interfaces
sandbox_os.host = os.host
sandbox_os.arch = os.arch
+sandbox_os.syshost = os.syshost
+sandbox_os.sysarch = os.sysarch
sandbox_os.exit = os.exit
sandbox_os.date = os.date
sandbox_os.time = os.time
@@ -58,6 +60,7 @@ sandbox_os.pbcopy = os.pbcopy
sandbox_os.cpuinfo = os.cpuinfo
sandbox_os.emptydir = os.emptydir
sandbox_os.filesize = os.filesize
+sandbox_os.features = os.features
sandbox_os.workingdir = os.workingdir
sandbox_os.programdir = os.programdir
sandbox_os.programfile = os.programfile
diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua
index 166d12274..96d9e81c4 100644
--- a/xmake/platforms/cygwin/config.lua
+++ b/xmake/platforms/cygwin/config.lua
@@ -34,15 +34,7 @@ function _check_arch()
if not arch then
-- init the default architecture
- local arch = config.get("cross") and "none" or os.arch()
- if is_host("windows") then
- if arch == "x64" then
- arch = "x86_64"
- elseif arch == "x86" then
- arch = "i386"
- end
- end
- config.set("arch", arch)
+ config.set("arch", config.get("cross") and "none" or os.arch())
-- trace
print("checking for the architecture ... %s", config.get("arch"))
diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua
index b33fb885f..15abb0e5c 100644
--- a/xmake/platforms/msys/config.lua
+++ b/xmake/platforms/msys/config.lua
@@ -34,15 +34,7 @@ function _check_arch()
if not arch then
-- init the default architecture
- local arch = config.get("cross") and "none" or os.arch()
- if is_host("windows") then
- if arch == "x64" then
- arch = "x86_64"
- elseif arch == "x86" then
- arch = "i386"
- end
- end
- config.set("arch", arch)
+ config.set("arch", config.get("cross") and "none" or os.arch())
-- trace
print("checking for the architecture ... %s", config.get("arch"))