diff options
| author | ruki <[email protected]> | 2023-07-26 22:39:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-07-26 22:39:16 +0800 |
| commit | db47073a5ec27a85073d67c03e38c7bd55598598 (patch) | |
| tree | bae539942c1b834017efc8e3d2dbf23af5409fa4 | |
| parent | f831a9c4a7fd0a9f07d00fb2feab6a674fb77635 (diff) | |
improve package for soname
| -rw-r--r-- | xmake/actions/package/local/main.lua | 18 | ||||
| -rw-r--r-- | xmake/core/base/os.lua | 28 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/os.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/target/action/install/unix.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/linker/soname/xmake.lua | 5 |
5 files changed, 45 insertions, 22 deletions
diff --git a/xmake/actions/package/local/main.lua b/xmake/actions/package/local/main.lua index e1049419e..e40aa3b47 100644 --- a/xmake/actions/package/local/main.lua +++ b/xmake/actions/package/local/main.lua @@ -109,7 +109,23 @@ function _package_library(target) end else os.mkdir(librarydir) - os.vcp(targetfile, librarydir) + if os.islink(targetfile) then + local targetfile_with_soname = os.readlink(targetfile) + if not path.is_absolute(targetfile_with_soname) then + targetfile_with_soname = path.join(target:targetdir(), targetfile_with_soname) + end + if os.islink(targetfile_with_soname) then + local targetfile_with_version = os.readlink(targetfile_with_soname) + if not path.is_absolute(targetfile_with_version) then + targetfile_with_version = path.join(target:targetdir(), targetfile_with_version) + end + os.vcp(targetfile_with_version, librarydir, {symlink = true, force = true}) + end + os.vcp(targetfile_with_soname, librarydir, {symlink = true, force = true}) + os.vcp(targetfile, librarydir, {symlink = true, force = true}) + else + os.vcp(targetfile, librarydir) + end os.trycp(target:symbolfile(), librarydir) end diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 870f4bdf6..b375650c7 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -55,6 +55,7 @@ os.SYSERR_NOT_ACCESS = 3 -- copy single file or directory function os._cp(src, dst, rootdir, opt) + opt = opt or {} assert(src and dst) -- reserve the source directory structure if opt.rootdir is given @@ -68,7 +69,7 @@ function os._cp(src, dst, rootdir, opt) end -- is file or link? - local symlink = opt and opt.symlink + local symlink = opt.symlink if os.isfile(src) or (symlink and os.islink(src)) then -- the destination is directory? append the filename @@ -81,6 +82,9 @@ function os._cp(src, dst, rootdir, opt) end -- copy or link file + if opt.force and os.isfile(dst) then + os.rmfile(dst) + end if not os.cpfile(src, dst, symlink) then local errors = os.strerror() if symlink and os.islink(src) then @@ -106,8 +110,6 @@ function os._cp(src, dst, rootdir, opt) if not os.cpdir(src, dst, symlink) then return false, string.format("cannot copy directory %s to %s, %s", src, dst, os.strerror()) end - - -- not exists? else return false, string.format("cannot copy file %s, file not found!", src) end @@ -115,10 +117,10 @@ function os._cp(src, dst, rootdir, opt) end -- move single file or directory -function os._mv(src, dst) +function os._mv(src, dst, opt) + opt = opt or {} assert(src and dst) - -- exists file or directory? if os.exists(src) then -- the destination directory exists? append the filename @@ -127,10 +129,12 @@ function os._mv(src, dst) end -- move file or directory + if opt.force and os.isfile(dst) then + os.rmfile(dst) + end if not os.rename(src, dst) then return false, string.format("cannot move %s to %s %s", src, dst, os.strerror()) end - -- not exists? else return false, string.format("cannot move %s to %s, file %s not found!", src, dst, os.strerror()) end @@ -435,7 +439,7 @@ function os.cp(srcpath, dstpath, opt) end -- move files or directories -function os.mv(srcpath, dstpath) +function os.mv(srcpath, dstpath, opt) -- check arguments if not srcpath or not dstpath then @@ -447,10 +451,10 @@ function os.mv(srcpath, dstpath) dstpath = tostring(dstpath) local srcpathes = os._match_wildcard_pathes(srcpath) if type(srcpathes) == "string" then - return os._mv(srcpathes, dstpath) + return os._mv(srcpathes, dstpath, opt) else for _, _srcpath in ipairs(srcpathes) do - local ok, errors = os._mv(_srcpath, dstpath) + local ok, errors = os._mv(_srcpath, dstpath, opt) if not ok then return false, errors end @@ -484,9 +488,13 @@ function os.rm(filepath) end -- link file or directory to the new symfile -function os.ln(srcpath, dstpath) +function os.ln(srcpath, dstpath, opt) + opt = opt or {} srcpath = tostring(srcpath) dstpath = tostring(dstpath) + if opt.force and os.isfile(dstpath) then + os.rmfile(dstpath) + end if not os.link(srcpath, dstpath) then return false, string.format("cannot link %s to %s, %s", srcpath, dstpath, os.strerror()) end diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua index 85ee61a64..c23ffb261 100644 --- a/xmake/core/sandbox/modules/os.lua +++ b/xmake/core/sandbox/modules/os.lua @@ -123,11 +123,11 @@ function sandbox_os.rm(filepath) end -- link file or directory to the new symfile -function sandbox_os.ln(srcpath, dstpath) +function sandbox_os.ln(srcpath, dstpath, opt) assert(srcpath and dstpath) srcpath = tostring(srcpath) dstpath = tostring(dstpath) - local ok, errors = os.ln(vformat(srcpath), vformat(dstpath)) + local ok, errors = os.ln(vformat(srcpath), vformat(dstpath), opt) if not ok then os.raise(errors) end @@ -143,12 +143,12 @@ function sandbox_os.vcp(srcpath, dstpath, opt) end -- move file or directory with the verbose info -function sandbox_os.vmv(srcpath, dstpath) +function sandbox_os.vmv(srcpath, dstpath, opt) assert(srcpath and dstpath) if option.get("verbose") then utils.cprint("${dim}> move %s to %s", srcpath, dstpath) end - return sandbox_os.mv(srcpath, dstpath) + return sandbox_os.mv(srcpath, dstpath, opt) end -- remove file or directory with the verbose info diff --git a/xmake/modules/target/action/install/unix.lua b/xmake/modules/target/action/install/unix.lua index fa4834df2..04dd60a01 100644 --- a/xmake/modules/target/action/install/unix.lua +++ b/xmake/modules/target/action/install/unix.lua @@ -54,7 +54,7 @@ function _install_shared_for_package(target, pkg, outputdir) end -- we need to reserve symlink -- @see https://github.com/xmake-io/xmake/issues/1582 - os.vcp(sopath, outputdir, {symlink = true}) + os.vcp(sopath, outputdir, {symlink = true, force = true}) _g.installed_libfiles[sopath] = true end end @@ -123,10 +123,10 @@ function install_shared(target, opt) if not path.is_absolute(targetfile_with_version) then targetfile_with_version = path.join(target:targetdir(), targetfile_with_version) end - os.vcp(targetfile_with_version, librarydir, {symlink = true}) + os.vcp(targetfile_with_version, librarydir, {symlink = true, force = true}) end - os.vcp(targetfile_with_soname, librarydir, {symlink = true}) - os.vcp(targetfile, librarydir, {symlink = true}) + os.vcp(targetfile_with_soname, librarydir, {symlink = true, force = true}) + os.vcp(targetfile, librarydir, {symlink = true, force = true}) else os.vcp(targetfile, librarydir) end diff --git a/xmake/rules/linker/soname/xmake.lua b/xmake/rules/linker/soname/xmake.lua index d271fba0b..8bb160b64 100644 --- a/xmake/rules/linker/soname/xmake.lua +++ b/xmake/rules/linker/soname/xmake.lua @@ -48,10 +48,9 @@ rule("linker.soname") if soname ~= filename and soname ~= path.filename(targetfile_with_version) then os.cp(target:targetfile(), targetfile_with_version) os.rm(target:targetfile()) - os.rm(targetfile_with_soname) local oldir = os.cd(target:targetdir()) - os.ln(path.filename(targetfile_with_version), soname) - os.ln(soname, path.filename(targetfile)) + os.ln(path.filename(targetfile_with_version), soname, {force = true}) + os.ln(soname, path.filename(targetfile), {force = true}) os.cd(oldir) end end |
