diff options
| author | ruki <[email protected]> | 2022-08-01 10:32:49 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-01 10:32:49 +0800 |
| commit | 6dee2f21fdc649f087983fb1ac9114b1229f6c71 (patch) | |
| tree | 108a8ce8af907ed7774228df539f6d98d1ed8d41 | |
| parent | e45d9400697a256c4873237329c45374c8c869ce (diff) | |
| parent | edeadc165a26f1b5cc420e732eacc13a487c989e (diff) | |
Merge pull request #2626 from xmake-io/touch
Add os.touch and fix build cache
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/bsd/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/cygwin/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/iphoneos/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/linux/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/macosx/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/mingw/tbox.config.h | 2 | ||||
| -rwxr-xr-x | core/src/tbox/inc/msys/tbox.config.h | 2 | ||||
| m--------- | core/src/tbox/tbox | 0 | ||||
| -rw-r--r-- | core/src/xmake/engine.c | 2 | ||||
| -rw-r--r-- | core/src/xmake/makefile | 1 | ||||
| -rw-r--r-- | core/src/xmake/os/touch.c | 49 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 13 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/private/cache/build_cache.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 3 |
16 files changed, 94 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc1bfef3..38059a2d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ ### Bugs fixed * [#2614](https://github.com/xmake-io/xmake/issues/2614): Fix building submodules2 tests for msvc +* [#2620](https://github.com/xmake-io/xmake/issues/2620): Fix build cache for incremental compilation ## v2.6.9 @@ -1371,6 +1372,7 @@ ### Bugs 修复 * [#2614](https://github.com/xmake-io/xmake/issues/2614): 为 msvc 修复构建 submodules2 测试工程 +* [#2620](https://github.com/xmake-io/xmake/issues/2620): 修复构建缓存导致的增量编译问题 ## v2.6.9 diff --git a/core/src/tbox/inc/bsd/tbox.config.h b/core/src/tbox/inc/bsd/tbox.config.h index 59160967c..7101e4d67 100755 --- a/core/src/tbox/inc/bsd/tbox.config.h +++ b/core/src/tbox/inc/bsd/tbox.config.h @@ -185,6 +185,8 @@ #define TB_CONFIG_POSIX_HAVE_PIPE2 1 #define TB_CONFIG_POSIX_HAVE_MKFIFO 1 #define TB_CONFIG_POSIX_HAVE_MMAP 1 +#define TB_CONFIG_POSIX_HAVE_FUTIMENS 1 +#define TB_CONFIG_POSIX_HAVE_UTIMENSAT 1 // windows functions /* #undef TB_CONFIG_WINDOWS_HAVE__INTERLOCKEDEXCHANGE */ diff --git a/core/src/tbox/inc/cygwin/tbox.config.h b/core/src/tbox/inc/cygwin/tbox.config.h index fea570e1f..035d786f3 100755 --- a/core/src/tbox/inc/cygwin/tbox.config.h +++ b/core/src/tbox/inc/cygwin/tbox.config.h @@ -185,6 +185,8 @@ /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ /* #undef TB_CONFIG_POSIX_HAVE_MKFIFO */ /* #undef TB_CONFIG_POSIX_HAVE_MMAP */ +/* #undef TB_CONFIG_POSIX_HAVE_FUTIMENS */ +/* #undef TB_CONFIG_POSIX_HAVE_UTIMENSAT */ // windows functions /* #undef TB_CONFIG_WINDOWS_HAVE__INTERLOCKEDEXCHANGE */ diff --git a/core/src/tbox/inc/iphoneos/tbox.config.h b/core/src/tbox/inc/iphoneos/tbox.config.h index 2545b1625..8bb9ad3aa 100755 --- a/core/src/tbox/inc/iphoneos/tbox.config.h +++ b/core/src/tbox/inc/iphoneos/tbox.config.h @@ -189,6 +189,8 @@ /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ #define TB_CONFIG_POSIX_HAVE_MKFIFO 1 #define TB_CONFIG_POSIX_HAVE_MMAP 1 +#define TB_CONFIG_POSIX_HAVE_FUTIMENS 1 +#define TB_CONFIG_POSIX_HAVE_UTIMENSAT 1 // windows functions /* #undef TB_CONFIG_WINDOWS_HAVE__INTERLOCKEDEXCHANGE */ diff --git a/core/src/tbox/inc/linux/tbox.config.h b/core/src/tbox/inc/linux/tbox.config.h index b5e0faa7f..b2977ecbb 100755 --- a/core/src/tbox/inc/linux/tbox.config.h +++ b/core/src/tbox/inc/linux/tbox.config.h @@ -192,6 +192,8 @@ #define TB_CONFIG_POSIX_HAVE_PIPE 1 /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ #define TB_CONFIG_POSIX_HAVE_MKFIFO 1 +#define TB_CONFIG_POSIX_HAVE_FUTIMENS 1 +#define TB_CONFIG_POSIX_HAVE_UTIMENSAT 1 // bsd functions #define TB_CONFIG_BSD_HAVE_FLOCK 1 diff --git a/core/src/tbox/inc/macosx/tbox.config.h b/core/src/tbox/inc/macosx/tbox.config.h index c1e9c7454..261b82b29 100755 --- a/core/src/tbox/inc/macosx/tbox.config.h +++ b/core/src/tbox/inc/macosx/tbox.config.h @@ -184,6 +184,8 @@ #define TB_CONFIG_POSIX_HAVE_PIPE 1 /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ #define TB_CONFIG_POSIX_HAVE_MKFIFO 1 +#define TB_CONFIG_POSIX_HAVE_FUTIMENS 1 +#define TB_CONFIG_POSIX_HAVE_UTIMENSAT 1 // bsd functions #define TB_CONFIG_BSD_HAVE_FLOCK 1 diff --git a/core/src/tbox/inc/mingw/tbox.config.h b/core/src/tbox/inc/mingw/tbox.config.h index fea570e1f..035d786f3 100755 --- a/core/src/tbox/inc/mingw/tbox.config.h +++ b/core/src/tbox/inc/mingw/tbox.config.h @@ -185,6 +185,8 @@ /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ /* #undef TB_CONFIG_POSIX_HAVE_MKFIFO */ /* #undef TB_CONFIG_POSIX_HAVE_MMAP */ +/* #undef TB_CONFIG_POSIX_HAVE_FUTIMENS */ +/* #undef TB_CONFIG_POSIX_HAVE_UTIMENSAT */ // windows functions /* #undef TB_CONFIG_WINDOWS_HAVE__INTERLOCKEDEXCHANGE */ diff --git a/core/src/tbox/inc/msys/tbox.config.h b/core/src/tbox/inc/msys/tbox.config.h index fea570e1f..035d786f3 100755 --- a/core/src/tbox/inc/msys/tbox.config.h +++ b/core/src/tbox/inc/msys/tbox.config.h @@ -185,6 +185,8 @@ /* #undef TB_CONFIG_POSIX_HAVE_PIPE2 */ /* #undef TB_CONFIG_POSIX_HAVE_MKFIFO */ /* #undef TB_CONFIG_POSIX_HAVE_MMAP */ +/* #undef TB_CONFIG_POSIX_HAVE_FUTIMENS */ +/* #undef TB_CONFIG_POSIX_HAVE_UTIMENSAT */ // windows functions /* #undef TB_CONFIG_WINDOWS_HAVE__INTERLOCKEDEXCHANGE */ diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox -Subproject 4331aa8f816cb71040b97028f53f21a9b54888a +Subproject ac38b67ffe39d2bca5860a4bc91ec1f87cd7186 diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c index 6458dee1c..b3d798e4f 100644 --- a/core/src/xmake/engine.c +++ b/core/src/xmake/engine.c @@ -98,6 +98,7 @@ tb_int_t xm_os_curdir(lua_State* lua); tb_int_t xm_os_tmpdir(lua_State* lua); tb_int_t xm_os_islink(lua_State* lua); 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_rename(lua_State* lua); @@ -319,6 +320,7 @@ static luaL_Reg const g_os_functions[] = , { "tmpdir", xm_os_tmpdir } , { "islink", xm_os_islink } , { "isfile", xm_os_isfile } +, { "touch", xm_os_touch } , { "rmfile", xm_os_rmfile } , { "cpfile", xm_os_cpfile } , { "rename", xm_os_rename } diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile index 44fb9a0b3..5ce8942bb 100644 --- a/core/src/xmake/makefile +++ b/core/src/xmake/makefile @@ -30,6 +30,7 @@ xmake_C_FILES += \ os/tmpdir \ os/isfile \ os/islink \ + os/touch \ os/rmfile \ os/cpfile \ os/rename \ diff --git a/core/src/xmake/os/touch.c b/core/src/xmake/os/touch.c new file mode 100644 index 000000000..04b655908 --- /dev/null +++ b/core/src/xmake/os/touch.c @@ -0,0 +1,49 @@ +/*!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 touch.c + * + */ + +/* ////////////////////////////////////////////////////////////////////////////////////// + * trace + */ +#define TB_TRACE_MODULE_NAME "touch" +#define TB_TRACE_MODULE_DEBUG (0) + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "prefix.h" + +/* ////////////////////////////////////////////////////////////////////////////////////// + * implementation + */ +tb_int_t xm_os_touch(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); + + tb_time_t atime = (tb_time_t)luaL_checknumber(lua, 2); + tb_time_t mtime = (tb_time_t)luaL_checknumber(lua, 3); + + lua_pushboolean(lua, tb_file_touch(path, atime, mtime)); + return 1; +} diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 7dd0f3aad..fff5c8408 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -37,6 +37,7 @@ os._getpid = os._getpid or os.getpid os._exit = os._exit or os.exit 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._setenv = os._setenv or os.setenv os._getenvs = os._getenvs or os.getenvs @@ -551,11 +552,19 @@ function os.cd(dir) if os._SCHED_CHDIR then os._SCHED_CHDIR(os.curdir()) end - - -- ok return oldir end +-- touch file or directory, it will modify atime/mtime or create a new file +-- we will do not change it if atime/mtime is zero +function os.touch(filepath, opt) + opt = opt or {} + if not os._touch(filepath, opt.atime or 0, opt.mtime or 0) then + return false, string.format("cannot touch %s, %s", filepath, os.strerror()) + end + return true +end + -- create directories function os.mkdir(dir) diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 4c2509cc9..a5744c3b5 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -200,6 +200,15 @@ function sandbox_os.cd(dir) return oldir end +-- touch file or directory +function sandbox_os.touch(filepath, opt) + assert(filepath) + local ok, errors = os.touch(vformat(filepath), opt) + if not ok then + os.raise(errors) + end +end + -- create directories function sandbox_os.mkdir(dir) assert(dir) diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua index e78c31968..4cb1be5ca 100644 --- a/xmake/modules/private/cache/build_cache.lua +++ b/xmake/modules/private/cache/build_cache.lua @@ -232,6 +232,9 @@ function build(program, argv, opt) local objectfile_cached, objectfile_infofile = get(cachekey) if objectfile_cached then os.cp(objectfile_cached, cppinfo.objectfile) + -- we need update mtime for incremental compilation + -- @see https://github.com/xmake-io/xmake/issues/2620 + os.touch(cppinfo.objectfile, {mtime = os.time()}) -- we need get outdata/errdata to show warnings, -- @see https://github.com/xmake-io/xmake/issues/2452 if objectfile_infofile and os.isfile(objectfile_infofile) then diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index bb4daf7a5..50bf82f21 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -249,6 +249,9 @@ function distcc_build_client:compile(program, argv, opt) local objectfile_cached, objectfile_infofile = build_cache.get(cachekey) if objectfile_cached then os.cp(objectfile_cached, cppinfo.objectfile) + -- we need update mtime for incremental compilation + -- @see https://github.com/xmake-io/xmake/issues/2620 + os.touch(cppinfo.objectfile, {mtime = os.time()}) -- we need get outdata/errdata to show warnings, -- @see https://github.com/xmake-io/xmake/issues/2452 if objectfile_infofile and os.isfile(objectfile_infofile) then |
