From 8c11d185b753f7c53439929aa91f04edba772836 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:50:27 +0800 Subject: improve symlink --- core/src/xmake/os/islink.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/core/src/xmake/os/islink.c b/core/src/xmake/os/islink.c index c7fec236e..b5662c369 100644 --- a/core/src/xmake/os/islink.c +++ b/core/src/xmake/os/islink.c @@ -29,9 +29,6 @@ * includes */ #include "prefix.h" -#ifndef TB_CONFIG_OS_WINDOWS -# include -#endif /* ////////////////////////////////////////////////////////////////////////////////////// * implementation @@ -46,16 +43,7 @@ tb_int_t xm_os_islink(lua_State* lua) tb_check_return_val(path, 0); // is link? -#if defined(TB_CONFIG_OS_WINDOWS) - lua_pushboolean(lua, tb_false); -#elif defined(TB_CONFIG_POSIX_HAVE_STAT64) - struct stat64 st = {0}; - lua_pushboolean(lua, !lstat64(path, &st) && S_ISLNK(st.st_mode)); -#else - struct stat st = {0}; - lua_pushboolean(lua, !lstat(path, &st) && S_ISLNK(st.st_mode)); -#endif - - // ok + tb_file_info_t info = {0}; + lua_pushboolean(lua, tb_file_info(path, &info) && (info.flags & TB_FILE_FLAG_LINK)); return 1; } -- cgit v1.3.1 From 6182a9eb658e5687fd60be57c65f4360926925e8 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:55:15 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 96ed09414..c759c36f8 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 96ed094143923dacafaec6eed10fc34e1106edc2 +Subproject commit c759c36f80ce61be8e1f5e284951cd1aeacdb8a1 -- cgit v1.3.1 From 971ed5cf931f31b3d86919667f8469a1be31dbfd Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 00:56:57 +0800 Subject: fix config --- core/src/tbox/inc/linux/tbox.config.h | 1 + core/src/tbox/inc/macosx/tbox.config.h | 1 + 2 files changed, 2 insertions(+) diff --git a/core/src/tbox/inc/linux/tbox.config.h b/core/src/tbox/inc/linux/tbox.config.h index b2977ecbb..a1986b4be 100755 --- a/core/src/tbox/inc/linux/tbox.config.h +++ b/core/src/tbox/inc/linux/tbox.config.h @@ -148,6 +148,7 @@ #define TB_CONFIG_POSIX_HAVE_DLOPEN 1 #define TB_CONFIG_POSIX_HAVE_OPEN 1 #define TB_CONFIG_POSIX_HAVE_STAT64 1 +#define TB_CONFIG_POSIX_HAVE_LSTAT64 1 #define TB_CONFIG_POSIX_HAVE_GETHOSTNAME 1 #define TB_CONFIG_POSIX_HAVE_GETIFADDRS 1 #define TB_CONFIG_POSIX_HAVE_SEM_INIT 1 diff --git a/core/src/tbox/inc/macosx/tbox.config.h b/core/src/tbox/inc/macosx/tbox.config.h index 261b82b29..59abf4acf 100755 --- a/core/src/tbox/inc/macosx/tbox.config.h +++ b/core/src/tbox/inc/macosx/tbox.config.h @@ -145,6 +145,7 @@ #define TB_CONFIG_POSIX_HAVE_OPEN 1 #if !defined(__arm64__) && !defined(__aarch64__) # define TB_CONFIG_POSIX_HAVE_STAT64 1 +# define TB_CONFIG_POSIX_HAVE_LSTAT64 1 #else /* #undef TB_CONFIG_POSIX_HAVE_STAT64 */ #endif -- cgit v1.3.1 From df6efbec2309e41c67e6ffdc8386a600ca04c21d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 21:01:15 +0800 Subject: fix file info --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index c759c36f8..4ab2cdf8d 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit c759c36f80ce61be8e1f5e284951cd1aeacdb8a1 +Subproject commit 4ab2cdf8dc94402d2277fd71ddc11eae913a30dc -- cgit v1.3.1 From 44d9b7cd8ef84a84bd8d898dddc419c385e02daf Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:39:10 +0800 Subject: improve os.cpfile --- core/src/tbox/tbox | 2 +- core/src/xmake/os/cpfile.c | 8 +++++++- xmake/core/base/os.lua | 19 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 4ab2cdf8d..6e4eab7e0 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 4ab2cdf8dc94402d2277fd71ddc11eae913a30dc +Subproject commit 6e4eab7e07a2b535af6889de3f62cfec0384e99b diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 4490172da..153f51de0 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -43,7 +43,13 @@ tb_int_t xm_os_cpfile(lua_State* lua) tb_char_t const* dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); + // init copy flags + tb_size_t flags = TB_FILE_COPY_NONE; + tb_bool_t is_symlink = lua_toboolean(lua, 3); + if (is_symlink) + flags |= TB_FILE_COPY_LINK; + // do copy - lua_pushboolean(lua, tb_file_copy(src, dst)); + lua_pushboolean(lua, tb_file_copy(src, dst, flags)); return 1; } diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 271e5546d..ad33699f4 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -79,16 +79,15 @@ function os._cp(src, dst, rootdir, opt) end end - -- link file if reserve symlink - if opt and opt.symlink and os.islink(src) then - local reallink = os.readlink(src) - if not os.link(reallink, dst) then - return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, os.strerror()) - end - else - -- copy file - if not os.cpfile(src, dst) then - return false, string.format("cannot copy file %s to %s, %s", src, dst, os.strerror()) + -- copy or link file + local symlink = opt and opt.symlink + if not os.cpfile(src, dst, symlink) then + local errors = os.strerror() + if symlink and os.islink(src) then + local reallink = os.readlink(src) + return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, errors) + else + return false, string.format("cannot copy file %s to %s, %s", src, dst, errors) end end -- is directory? -- cgit v1.3.1 From 23f93ac88e0484178a37c01b6e33298c95e3b64c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:44:00 +0800 Subject: update tbox --- core/src/tbox/tbox | 2 +- xmake/core/base/os.lua | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 6e4eab7e0..f336b0d24 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 6e4eab7e07a2b535af6889de3f62cfec0384e99b +Subproject commit f336b0d24f667825e8e3f439180ab5dcb0bab0d9 diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index ad33699f4..b67a497d1 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -67,8 +67,9 @@ function os._cp(src, dst, rootdir, opt) end end - -- is file? - if os.isfile(src) or os.islink(src) then + -- is file or link? + local symlink = opt and opt.symlink + if os.isfile(src) or (symlink and os.islink(src)) then -- the destination is directory? append the filename if os.isdir(dst) or path.islastsep(dst) then @@ -80,7 +81,6 @@ function os._cp(src, dst, rootdir, opt) end -- copy or link file - local symlink = opt and opt.symlink if not os.cpfile(src, dst, symlink) then local errors = os.strerror() if symlink and os.islink(src) then @@ -103,7 +103,7 @@ function os._cp(src, dst, rootdir, opt) end -- copy directory - if not os.cpdir(src, dst) then + if not os.cpdir(src, dst, symlink) then return false, string.format("cannot copy directory %s to %s, %s", src, dst, os.strerror()) end -- cgit v1.3.1 From 8294b15c930de7df43333dc1e93b019df93a73f8 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:44:25 +0800 Subject: improve os.cp --- core/src/xmake/os/cpdir.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/xmake/os/cpdir.c b/core/src/xmake/os/cpdir.c index 1967cba49..eaf59f445 100644 --- a/core/src/xmake/os/cpdir.c +++ b/core/src/xmake/os/cpdir.c @@ -43,9 +43,13 @@ tb_int_t xm_os_cpdir(lua_State* lua) tb_char_t const* dst = luaL_checkstring(lua, 2); tb_check_return_val(src && dst, 0); - // done os.cpdir(src, dst) - lua_pushboolean(lua, tb_directory_copy(src, dst)); + // init copy flags + tb_size_t flags = TB_FILE_COPY_NONE; + tb_bool_t is_symlink = lua_toboolean(lua, 3); + if (is_symlink) + flags |= TB_FILE_COPY_LINK; - // ok + // do copy + lua_pushboolean(lua, tb_directory_copy(src, dst, flags)); return 1; } -- cgit v1.3.1 From ded1a93f8f9cdb86c38b37f97915f9452e822fa5 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:45:05 +0800 Subject: improve to install framework --- xmake/rules/xcode/application/build.lua | 24 ++++-------------------- xmake/rules/xcode/framework/xmake.lua | 4 +--- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 8089be966..fba9f319f 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -25,25 +25,6 @@ import("core.project.depend") import("private.tools.codesign") import("utils.progress") --- copy frameworks with symlink --- --- TODO we should improve os.cp to support for copying directory with symlink --- os.vcp(frameworkdir, frameworksdir, {symlink = true}) -function copy_frameworks(frameworkdir, frameworksdir) - os.mkdir(frameworksdir) - local frameworkdir_dst = path.join(frameworksdir, path.filename(frameworkdir)) - os.tryrm(frameworkdir_dst) - for _, filepath in ipairs(os.filedirs(path.join(frameworkdir, "*"))) do - if path.filename(filepath) == "Versions" then - copy_frameworks(filepath, frameworkdir_dst) - else - local dstpath = path.join(frameworkdir_dst, path.filename(filepath)) - os.tryrm(dstpath) - os.cp(filepath, dstpath, {symlink = true}) - end - end -end - -- main entry function main (target, opt) @@ -77,7 +58,10 @@ function main (target, opt) if dep:kind() == "shared" then local frameworkdir = dep:data("xcode.bundle.rootdir") if dep:rule("xcode.framework") and frameworkdir then - copy_frameworks(frameworkdir, frameworksdir, {symlink = true}) + if not os.isdir(frameworkdir) then + os.mkdir(frameworksdir) + end + os.cp(frameworkdir, frameworksdir, {symlink = true}) else os.vcp(dep:targetfile(), binarydir) end diff --git a/xmake/rules/xcode/framework/xmake.lua b/xmake/rules/xcode/framework/xmake.lua index 687b67208..6fffa8f46 100644 --- a/xmake/rules/xcode/framework/xmake.lua +++ b/xmake/rules/xcode/framework/xmake.lua @@ -172,9 +172,7 @@ rule("xcode.framework") if not os.isdir(installdir) then os.mkdir(installdir) end - -- TODO we should improve os.cp to support symlink - --os.vcp(bundledir, installdir, {symlink = true}) - appbuild.copy_frameworks(bundledir, installdir) + os.vcp(bundledir, installdir, {symlink = true}) end end) -- cgit v1.3.1 From 9706d7e9185eb5acf843b24bda8f1564293280f0 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:45:28 +0800 Subject: update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b57123de..9fd899e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * [#2140](https://github.com/xmake-io/xmake/issues/2140): Support Windows Arm64 +### Changes + +* [#2745](https://github.com/xmake-io/xmake/pull/2745): Improve os.cp to support symlink + ### Bugs fixed * [#2740](https://github.com/xmake-io/xmake/issues/2740): Fix build c++ modules stuck and slower for msvc @@ -1380,6 +1384,10 @@ * [#2140](https://github.com/xmake-io/xmake/issues/2140): 支持 Windows Arm64 +### 改进 + +* [#2745](https://github.com/xmake-io/xmake/pull/2745): 改进 os.cp 支持符号链接复制 + ### Bugs 修复 * [#2740](https://github.com/xmake-io/xmake/issues/2740): 修复 msvc 构建 C++ modules 卡死问题 -- cgit v1.3.1 From 6046e78b4d3ba893ef99f3e821736830dca1e5c2 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:48:20 +0800 Subject: fix os.cp --- core/src/tbox/tbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index f336b0d24..dc99c25f3 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit f336b0d24f667825e8e3f439180ab5dcb0bab0d9 +Subproject commit dc99c25f3c6fecafe1cf6791148f5656c007299f -- cgit v1.3.1