diff options
| author | ruki <[email protected]> | 2020-02-14 23:18:25 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-14 13:50:33 +0800 |
| commit | c00d159a9a510e39ac5e00cb29c26651f4fc56aa (patch) | |
| tree | 80c0ebc4ace229a7c16e71e7efcf049d41f06157 | |
| parent | ffb92f48bcfbe4c34d027a7e01ff27b18b97c431 (diff) | |
add subsystem host andarch
| -rw-r--r-- | core/src/xmake/machine.c | 28 | ||||
| -rw-r--r-- | makefile | 4 | ||||
| -rw-r--r-- | xmake/actions/config/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/actions/require/impl/utils/filter.lua | 1 | ||||
| -rw-r--r-- | xmake/core/_xmake_main.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/colors.lua | 4 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 115 | ||||
| -rw-r--r-- | xmake/core/base/path.lua | 6 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 3 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/interpreter/os.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/net/http/download.lua | 33 | ||||
| -rw-r--r-- | xmake/platforms/cygwin/config.lua | 2 | ||||
| -rw-r--r-- | xmake/platforms/msys/config.lua | 2 |
16 files changed, 117 insertions, 96 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index ba2510add..5826a93b2 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -581,15 +581,15 @@ static tb_void_t xm_machine_init_host(xm_machine_t* machine) syshost = "android"; #endif lua_pushstring(machine->lua, syshost? syshost : "unknown"); - lua_setglobal(machine->lua, "_SYSHOST"); + lua_setglobal(machine->lua, "_HOST"); - // init host - tb_char_t const* host = syshost; + // init subsystem host + tb_char_t const* subhost = syshost; #if defined(TB_CONFIG_OS_WINDOWS) # if defined(TB_COMPILER_ON_MSYS) - host = "msys"; + subhost = "msys"; # elif defined(TB_COMPILER_ON_CYGWIN) - host = "cygwin"; + subhost = "cygwin"; # else { tb_char_t data[64] = {0}; @@ -597,13 +597,13 @@ static tb_void_t xm_machine_init_host(xm_machine_t* machine) { // on msys or msys/mingw64 or msys/mingw32? if (!tb_strnicmp(data, "mingw", 5) || !tb_stricmp(data, "msys")) - host = "msys"; + subhost = "msys"; } } # endif #endif - lua_pushstring(machine->lua, host? host : "unknown"); - lua_setglobal(machine->lua, "_HOST"); + lua_pushstring(machine->lua, subhost? subhost : "unknown"); + lua_setglobal(machine->lua, "_SUBHOST"); } static tb_void_t xm_machine_init_arch(xm_machine_t* machine) { @@ -657,18 +657,18 @@ static tb_void_t xm_machine_init_arch(xm_machine_t* machine) sysarch = TB_ARCH_STRING; #endif lua_pushstring(machine->lua, sysarch); - lua_setglobal(machine->lua, "_SYSARCH"); + lua_setglobal(machine->lua, "_ARCH"); - // init architecture - tb_char_t const* arch = sysarch; + // init subsystem architecture + tb_char_t const* subarch = sysarch; #if defined(TB_CONFIG_OS_WINDOWS) && !defined(TB_COMPILER_LIKE_UNIX) // get architecture from msys environment tb_char_t data[64] = {0}; if (tb_environment_first("MSYSTEM_CARCH", data, sizeof(data))) - arch = data; + subarch = data; #endif - lua_pushstring(machine->lua, arch); - lua_setglobal(machine->lua, "_ARCH"); + lua_pushstring(machine->lua, subarch); + lua_setglobal(machine->lua, "_SUBARCH"); } static tb_void_t xm_machine_init_features(xm_machine_t* machine) { @@ -1,5 +1,5 @@ # is debug? -debug :=n +debug :=y verbose := #debug :=y @@ -96,7 +96,7 @@ build: @echo compiling xmake-core ... @if [ -f core/.config.mak ]; then rm core/.config.mak; fi @$(MAKE) -C core --no-print-directory f DEBUG=$(debug) - @$(MAKE) -C core --no-print-directory c +# @$(MAKE) -C core --no-print-directory c @$(MAKE) -C core --no-print-directory install: diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index a4d9604ea..bf9272c63 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -53,7 +53,7 @@ task("config") end } , {category = "."} - , {'p', "plat", "kv", "$(host)" , "Compile for the given platform." + , {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform." , values = function (complete, opt) -- import diff --git a/xmake/actions/require/impl/utils/filter.lua b/xmake/actions/require/impl/utils/filter.lua index 8569c9d79..dfcd3773d 100644 --- a/xmake/actions/require/impl/utils/filter.lua +++ b/xmake/actions/require/impl/utils/filter.lua @@ -42,6 +42,7 @@ function _filter() _g.common_maps = _g.common_maps or { host = os.host() + , subhost = os.subhost() , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end , scriptdir = function () return os.scriptdir() end diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 5a553f507..a525f56cf 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -23,8 +23,8 @@ xmake = xmake or {} xmake._ARGV = _ARGV xmake._HOST = _HOST xmake._ARCH = _ARCH -xmake._SYSHOST = _SYSHOST -xmake._SYSARCH = _SYSARCH +xmake._SUBHOST = _SUBHOST +xmake._SUBARCH = _SUBARCH xmake._VERSION = _VERSION xmake._VERSION_SHORT = _VERSION_SHORT xmake._PROGRAM_DIR = _PROGRAM_DIR diff --git a/xmake/core/base/colors.lua b/xmake/core/base/colors.lua index c49191cd1..d3d386011 100644 --- a/xmake/core/base/colors.lua +++ b/xmake/core/base/colors.lua @@ -164,7 +164,7 @@ function colors.color8() end -- has 8 colors? - if colorterm == "color8" or os.host() ~= "windows" then + if colorterm == "color8" or os.subhost() ~= "windows" then return true end @@ -183,7 +183,7 @@ function colors.color256() end -- has 256 colors? - return colorterm == "color256" or os.host() ~= "windows" + return colorterm == "color256" or os.subhost() ~= "windows" end -- support 24bits true color diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 05e12fa3a..6b1366ac8 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -161,6 +161,38 @@ function os._sched_chdir_set(chdir) os._SCHED_CHDIR = chdir end +-- the current host is belong to the given hosts? +function os._is_host(host, ...) + + -- no host + if not host then + return false + end + + -- exists this host? and escape '-' + for _, h in ipairs(table.join(...)) do + if h and type(h) == "string" and host:find(h:gsub("%-", "%%-")) then + return true + end + end +end + +-- the current platform is belong to the given architectures? +function os._is_arch(arch, ...) + + -- no arch + if not arch then + return false + end + + -- exists this architecture? and escape '-' + for _, a in ipairs(table.join(...)) do + if a and type(a) == "string" and arch:find("^" .. a:gsub("%-", "%%-") .. "$") then + return true + end + end +end + -- translate arguments for wildcard function os.argw(argv) @@ -800,24 +832,24 @@ function os.isexec(filepath) return os.isfile(filepath) end --- get host of subsystem, maybe msys/cygwin on windows +-- get system host function os.host() return xmake._HOST end --- get host architecture of subsystem +-- get system architecture function os.arch() return xmake._ARCH end --- get system host, msys/cygwin are always windows -function os.syshost() - return xmake._SYSHOST +-- get subsystem host, e.g. msys, cygwin on windows +function os.subhost() + return xmake._SUBHOST end --- get system host architecture -function os.sysarch() - return xmake._SYSARCH +-- get subsystem host architecture +function os.subarch() + return xmake._SUBARCH end -- get features @@ -827,32 +859,22 @@ end -- the current host is belong to the given hosts? function os.is_host(...) - - -- get the current host - local host = os.host() - if not host then return false end - - -- exists this host? and escape '-' - for _, h in ipairs(table.join(...)) do - if h and type(h) == "string" and host:find(h:gsub("%-", "%%-")) then - return true - end - end + return os._is_host(os.host(), ...) end --- the current platform is belong to the given architectures? +-- the current architecture is belong to the given architectures? function os.is_arch(...) + return os._is_arch(os.arch(), ...) +end - -- get the host architecture - local arch = os.arch() - if not arch then return false end +-- the current subsystem host is belong to the given hosts? +function os.is_subhost(...) + return os._is_host(os.subhost(), ...) +end - -- exists this architecture? and escape '-' - for _, a in ipairs(table.join(...)) do - if a and type(a) == "string" and arch:find("^" .. a:gsub("%-", "%%-") .. "$") then - return true - end - end +-- the current subsystem architecture is belong to the given architectures? +function os.is_subarch(...) + return os._is_arch(os.subarch(), ...) end -- get the system null device @@ -891,41 +913,6 @@ function os.nuldev(input) end end --- get user agent -function os.user_agent() - - -- init user agent - if os._USER_AGENT == nil then - - -- init systems - local systems = {macosx = "Macintosh", linux = "Linux", windows = "Windows", msys = "MSYS", cygwin = "Cygwin"} - - -- os user agent - local os_user_agent = "" - if os.host() == "macosx" then - local ok, osver = os.iorun("/usr/bin/sw_vers -productVersion") - if ok then - os_user_agent = ("Intel Mac OS X " .. (osver or "")):trim() - end - 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() - end - ok, osver = os.iorun("uname -r") - if ok then - os_user_agent = (os_user_agent .. " " .. (osver or "")):trim() - end - end - - -- make user agent - os._USER_AGENT = string.format("Xmake/%s (%s;%s)", xmake._VERSION_SHORT, systems[os.host()] or os.host(), os_user_agent) - end - - -- ok? - return os._USER_AGENT -end - -- get uid function os.uid(...) -- get uid diff --git a/xmake/core/base/path.lua b/xmake/core/base/path.lua index d960509e1..dd07badf6 100644 --- a/xmake/core/base/path.lua +++ b/xmake/core/base/path.lua @@ -113,7 +113,7 @@ function path.splitenv(env_path) assert(env_path) local result = {} - if xmake._SYSHOST == "windows" then + if xmake._HOST == "windows" then while #env_path > 0 do if env_path:startswith(path.envsep()) then env_path = env_path:sub(2) @@ -156,7 +156,7 @@ function path.joinenv(env_table) end local envsep = path.envsep() - if xmake._SYSHOST == "windows" then + if xmake._HOST == "windows" then local tab = {} for _, v in ipairs(env_table) do if v ~= "" then @@ -176,7 +176,7 @@ end function path.islastsep(p) assert(p) local sep = p:sub(#p, #p) - return xmake._SYSHOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/') + return xmake._HOST == "windows" and (sep == '\\' or sep == '/') or (sep == '/') end -- convert path pattern to a lua pattern diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 7ffcdfcc4..7a7005de0 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -197,6 +197,7 @@ function task._interpreter() local maps = { host = os.host() + , subhost = os.subhost() , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end , scriptdir = function () return sandbox_os.scriptdir() end diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 224e171e6..f19e576a5 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -451,6 +451,7 @@ function option.interpreter() , plat = function() return config.get("plat") or os.host() end , mode = function() return config.get("mode") or "release" end , host = os.host() + , subhost = os.subhost() , prefix = "$(prefix)" , globaldir = global.directory() , configdir = config.directory() diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 6085f867d..f0e80d63b 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -211,10 +211,10 @@ function project.interpreter() -- is_xxx {"is_os", project._api_is_os } , {"is_kind", project._api_is_kind } + , {"is_arch", project._api_is_arch } , {"is_host", project._api_is_host } , {"is_mode", project._api_is_mode } , {"is_plat", project._api_is_plat } - , {"is_arch", project._api_is_arch } , {"is_config", project._api_is_config } -- get_xxx , {"get_config", project._api_get_config } @@ -251,6 +251,7 @@ function project.interpreter() { os = platform.os() , host = os.host() + , subhost = os.subhost() , prefix = "$(prefix)" , tmpdir = function () return os.tmpdir() end , curdir = function () return os.curdir() end diff --git a/xmake/core/sandbox/modules/interpreter/os.lua b/xmake/core/sandbox/modules/interpreter/os.lua index 43133caf7..33a12807d 100644 --- a/xmake/core/sandbox/modules/interpreter/os.lua +++ b/xmake/core/sandbox/modules/interpreter/os.lua @@ -29,6 +29,8 @@ local sandbox_os = sandbox_os or {} -- export some readonly interfaces sandbox_os.host = os.host sandbox_os.arch = os.arch +sandbox_os.subhost = os.subhost +sandbox_os.subarch = os.subarch sandbox_os.date = os.date sandbox_os.time = os.time sandbox_os.mtime = os.mtime diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 782082a7e..038807745 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -35,8 +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.subhost = os.subhost +sandbox_os.subarch = os.subarch sandbox_os.exit = os.exit sandbox_os.date = os.date sandbox_os.time = os.time @@ -67,7 +67,6 @@ sandbox_os.programfile = os.programfile sandbox_os.projectdir = os.projectdir sandbox_os.projectfile = os.projectfile sandbox_os.getwinsize = os.getwinsize -sandbox_os.user_agent = os.user_agent -- copy file or directory function sandbox_os.cp(...) diff --git a/xmake/modules/net/http/download.lua b/xmake/modules/net/http/download.lua index cf7bda691..6a292c20e 100644 --- a/xmake/modules/net/http/download.lua +++ b/xmake/modules/net/http/download.lua @@ -22,6 +22,35 @@ import("core.base.option") import("lib.detect.find_tool") +-- get user agent +function _get_user_agent() + + -- init user agent + if _g._USER_AGENT == nil then + + -- init systems + local systems = {macosx = "Macintosh", linux = "Linux", windows = "Windows", msys = "MSYS", cygwin = "Cygwin"} + + -- os user agent + local os_user_agent = "" + if is_host("macosx") then + local osver = try { function() return os.iorun("/usr/bin/sw_vers -productVersion") end } + if osver then + os_user_agent = ("Intel Mac OS X " .. (osver or "")):trim() + end + elseif is_host("linux", "msys", "cygwin") then + local osver = try { function () return os.iorun("uname -r") end } + if osver then + os_user_agent = (os_user_agent .. " " .. (osver or "")):trim() + end + end + + -- make user agent + _g._USER_AGENT = string.format("Xmake/%s (%s;%s)", xmake.version(), systems[os.subhost()] or os.subhost(), os_user_agent) + end + return _g._USER_AGENT +end + -- download url using curl function _curl_download(tool, url, outputfile) @@ -34,7 +63,7 @@ function _curl_download(tool, url, outputfile) end -- set user-agent - local user_agent = os.user_agent() + local user_agent = _get_user_agent() if user_agent then if tool.version then user_agent = user_agent .. " curl/" .. tool.version @@ -71,7 +100,7 @@ function _wget_download(tool, url, outputfile) end -- set user-agent - local user_agent = os.user_agent() + local user_agent = _get_user_agent() if user_agent then if tool.version then user_agent = user_agent .. " wget/" .. tool.version diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua index 96d9e81c4..6c963188d 100644 --- a/xmake/platforms/cygwin/config.lua +++ b/xmake/platforms/cygwin/config.lua @@ -34,7 +34,7 @@ function _check_arch() if not arch then -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) + config.set("arch", config.get("cross") and "none" or os.subarch()) -- 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 15abb0e5c..f5fd3c0a4 100644 --- a/xmake/platforms/msys/config.lua +++ b/xmake/platforms/msys/config.lua @@ -34,7 +34,7 @@ function _check_arch() if not arch then -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) + config.set("arch", config.get("cross") and "none" or os.subarch()) -- trace print("checking for the architecture ... %s", config.get("arch")) |
