diff options
| author | ruki <[email protected]> | 2022-08-31 12:51:20 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-31 12:51:20 +0800 |
| commit | cfb302ba06a479ffddcf28e8acf727bea5d638fa (patch) | |
| tree | 7191ddbb89c4812cf0b28f2e7aa5d3027363adad | |
| parent | 3e398cf349c1ff3b9e9ebfa92f9dff99dfa8a97f (diff) | |
| parent | 6046e78b4d3ba893ef99f3e821736830dca1e5c2 (diff) | |
Merge pull request #2745 from xmake-io/symlink
improve symlink
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rwxr-xr-x | core/src/tbox/inc/linux/tbox.config.h | 1 | ||||
| -rwxr-xr-x | core/src/tbox/inc/macosx/tbox.config.h | 1 | ||||
| m--------- | core/src/tbox/tbox | 0 | ||||
| -rw-r--r-- | core/src/xmake/os/cpdir.c | 10 | ||||
| -rw-r--r-- | core/src/xmake/os/cpfile.c | 8 | ||||
| -rw-r--r-- | core/src/xmake/os/islink.c | 16 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 25 | ||||
| -rw-r--r-- | xmake/rules/xcode/application/build.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/xcode/framework/xmake.lua | 4 |
10 files changed, 43 insertions, 54 deletions
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 卡死问题 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 diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox -Subproject 96ed094143923dacafaec6eed10fc34e1106edc +Subproject dc99c25f3c6fecafe1cf6791148f5656c007299 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; } 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/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 <sys/stat.h> -#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; } diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 271e5546d..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 @@ -79,16 +80,14 @@ 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 + 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? @@ -104,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 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) |
