diff options
| author | ruki <[email protected]> | 2019-10-09 22:22:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-10-09 08:17:14 +0800 |
| commit | 06e6a3b6aaf5465421f93e7a7158101fbea4cee9 (patch) | |
| tree | 925582755ea768a4ceaff4155534c2e3bce47a75 /core/src | |
| parent | b7d21719c405866e1ebc6597cba561c577850ae6 (diff) | |
add os.cpuinfo and improve the default build jobs number
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/machine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/os/cpuinfo.c | 58 |
3 files changed, 61 insertions, 0 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index d9dc111c3..b98e60236 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -78,6 +78,7 @@ tb_int_t xm_os_exists(lua_State* lua); tb_int_t xm_os_setenv(lua_State* lua); tb_int_t xm_os_getenv(lua_State* lua); tb_int_t xm_os_getenvs(lua_State* lua); +tb_int_t xm_os_cpuinfo(lua_State* lua); tb_int_t xm_os_readlink(lua_State* lua); tb_int_t xm_os_filesize(lua_State* lua); tb_int_t xm_os_emptydir(lua_State* lua); @@ -193,6 +194,7 @@ static luaL_Reg const g_os_functions[] = , { "setenv", xm_os_setenv } , { "getenv", xm_os_getenv } , { "getenvs", xm_os_getenvs } +, { "cpuinfo", xm_os_cpuinfo } , { "readlink", xm_os_readlink } , { "emptydir", xm_os_emptydir } , { "strerror", xm_os_strerror } diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index ae9ebbbe4..996123191 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -36,6 +36,7 @@ xmake_C_FILES += \ os/setenv \ os/getenv \ os/getenvs \ + os/cpuinfo \ os/readlink \ os/emptydir \ os/strerror \ diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c new file mode 100644 index 000000000..7d9dce5f0 --- /dev/null +++ b/core/src/xmake/os/cpuinfo.c @@ -0,0 +1,58 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015 - 2019, TBOOX Open Source Group. + * + * @author ruki + * @file cpuinfo.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "cpuinfo" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ + +/* local cpuinfo = os.cpuinfo() + * { + * ncpu = 4, + * ... + * } + */ +tb_int_t xm_os_cpuinfo(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + // init table + lua_newtable(lua); + + // get cpu number + tb_int_t ncpu = (tb_int_t)tb_cpu_count(); + lua_pushstring(lua, "ncpu"); + lua_pushinteger(lua, ncpu > 0? ncpu : 1); + lua_settable(lua, -3); + + return 1; +} |
