diff options
| author | ruki <[email protected]> | 2023-03-04 00:57:05 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-03-04 00:57:05 +0800 |
| commit | 95bde15f54e6dfffe5eeeee2a04e697f615e8868 (patch) | |
| tree | 8996e4ed8b9ec01539b62b4186c088020da84ba4 | |
| parent | 9f5e98c4cc256d3321d4d5e23037304e723cdb93 (diff) | |
improve fscase
| m--------- | core/src/tbox/tbox | 0 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/os/fscase.c | 46 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 22 |
4 files changed, 68 insertions, 2 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox -Subproject 04cc154a906fd2670989bc1648c857a35a47671 +Subproject 577ec239822be88861a0f4a80e33485409e36c2 diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 17370a8ea..8baac18c6 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -101,6 +101,7 @@ tb_int_t xm_os_isfile(lua_State* lua); tb_int_t xm_os_touch(lua_State* lua); tb_int_t xm_os_rmfile(lua_State* lua); tb_int_t xm_os_cpfile(lua_State* lua); +tb_int_t xm_os_fscase(lua_State* lua); tb_int_t xm_os_rename(lua_State* lua); tb_int_t xm_os_exists(lua_State* lua); tb_int_t xm_os_setenv(lua_State* lua); @@ -321,6 +322,7 @@ static luaL_Reg const g_os_functions[] = , { "touch", xm_os_touch } , { "rmfile", xm_os_rmfile } , { "cpfile", xm_os_cpfile } +, { "fscase", xm_os_fscase } , { "rename", xm_os_rename } , { "exists", xm_os_exists } , { "setenv", xm_os_setenv } diff --git a/core/src/xmake/os/fscase.c b/core/src/xmake/os/fscase.c new file mode 100644 index 000000000..917a5dc75 --- /dev/null +++ b/core/src/xmake/os/fscase.c @@ -0,0 +1,46 @@ +/*!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-present, TBOOX Open Source Group. + * + * @author ruki + * @file fscase.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "fscase" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_fscase(lua_State* lua) +{ + // check + tb_assert_and_check_return_val(lua, 0); + + tb_char_t const* path = luaL_checkstring(lua, 1); + tb_check_return_val(path, 0); + + lua_pushinteger(lua, (tb_int_t)tb_file_fscase(path)); + return 1; +} diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 3d0ad886d..dee65cbdc 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -39,6 +39,7 @@ os._mkdir = os._mkdir or os.mkdir os._rmdir = os._rmdir or os.rmdir os._touch = os._touch or os.touch os._tmpdir = os._tmpdir or os.tmpdir +os._fscase = os._fscase or os.fscase os._setenv = os._setenv or os.setenv os._getenvs = os._getenvs or os.getenvs os._cpuinfo = os._cpuinfo or os.cpuinfo @@ -1068,8 +1069,24 @@ function os.isroot() end -- is case-insensitive filesystem? -function os.fscase() - if os._FSCASE == nil then +function os.fscase(filepath) + if os._FSCASE == nil or filepath then + if os._fscase then + if filepath then + assert(os.exists(filepath), filepath .. " not found in os.fscase()") + else + local tmpdir = os.tmpdir() + if not os.isdir(tmpdir) then + os.mkdir(tmpdir) + end + filepath = tmpdir + end + local fscase = os._fscase(filepath) + if fscase ~= -1 then + os._FSCASE = (fscase == 1) + return os._FSCASE + end + end if os.host() == "windows" then os._FSCASE = false else @@ -1379,3 +1396,4 @@ end -- return module return os + |
