diff options
| author | ruki <[email protected]> | 2024-07-15 22:50:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-15 12:21:42 +0800 |
| commit | d151aaa50441d159a2980ceefc55f1db45f4d9b0 (patch) | |
| tree | 3954d9eba1cf4545127eeaabfde26deded15bc70 | |
| parent | e128b029dbfa5e3ab5156afd12a7a412c2bb6aad (diff) | |
improve to install sofiles
| -rw-r--r-- | xmake/modules/target/action/install/main.lua | 38 | ||||
| -rw-r--r-- | xmake/modules/target/action/uninstall/main.lua | 30 |
2 files changed, 32 insertions, 36 deletions
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 09deaabdb..5a0bec7ab 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -48,6 +48,20 @@ function _get_target_package_libfiles(target, opt) return libfiles end +-- copy file with symlinks +function _copyfile_with_symlinks(srcfile, outputdir) + if os.islink(srcfile) then + local srcfile_symlink = os.readlink(srcfile) + if not path.is_absolute(srcfile_symlink) then + srcfile_symlink = path.join(path.directory(srcfile), srcfile_symlink) + end + _copyfile_with_symlinks(srcfile_symlink, outputdir) + os.vcp(srcfile, outputdir, {symlink = true, force = true}) + else + os.vcp(srcfile, outputdir) + end +end + -- install files function _install_files(target) local srcfiles, dstfiles = target:installfiles() @@ -100,14 +114,14 @@ function _install_shared_libraries(target, opt) -- deduplicate libfiles, prevent packages using the same libfiles from overwriting each other libfiles = table.unique(libfiles) - -- do install, TODO soname and symlinks + -- do install for _, libfile in ipairs(libfiles) do local filename = path.filename(libfile) local filepath = path.join(bindir, filename) - if os.isfile(filepath) then + if os.isfile(filepath) and hash.sha256(filepath) ~= hash.sha256(libfile) then wprint("'%s' already exists in install dir, we are copying '%s' to overwrite it.", filepath, libfile) end - os.cp(libfile, filepath) + _copyfile_with_symlinks(libfile, bindir) end end @@ -138,23 +152,7 @@ function _install_shared(target, opt) end else -- install target with soname and symlink - 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, bindir, {symlink = true, force = true}) - end - os.vcp(targetfile_with_soname, bindir, {symlink = true, force = true}) - os.vcp(targetfile, bindir, {symlink = true, force = true}) - else - os.vcp(targetfile, bindir) - end + _copyfile_with_symlinks(targetfile, bindir) end os.trycp(target:symbolfile(), path.join(bindir, path.filename(target:symbolfile()))) diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 41f074640..9a0c791cd 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -49,6 +49,18 @@ function _get_target_package_libfiles(target, opt) return libfiles end +-- remove file with symbols +function _remove_file_with_symbols(filepath) + if os.islink(filepath) then + local filepath_symlink = os.readlink(filepath) + if not path.is_absolute(filepath_symlink) then + filepath_symlink = path.join(path.directory(filepath), filepath_symlink) + end + _remove_file_with_symbols(filepath_symlink) + end + remove_files(filepath, {emptydir = true}) +end + -- uninstall files function _uninstall_files(target) local _, dstfiles = target:installfiles() @@ -90,7 +102,7 @@ function _uninstall_shared_libraries(target, opt) for _, libfile in ipairs(libfiles) do local filename = path.filename(libfile) local filepath = path.join(bindir, filename) - remove_files(filepath, {emptydir = true}) + _remove_file_with_symbols(filepath) end end @@ -115,21 +127,7 @@ function _uninstall_shared(target, opt) remove_files(path.join(libdir, path.basename(targetfile) .. (target:is_plat("mingw") and ".dll.a" or ".lib")), {emptydir = true}) else local targetfile = path.join(bindir, path.filename(target:targetfile())) - 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(bindir, 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(bindir, targetfile_with_version) - end - remove_files(targetfile_with_version, {emptydir = true}) - end - remove_files(targetfile_with_soname, {emptydir = true}) - end - remove_files(targetfile, {emptydir = true}) + _remove_file_with_symbols(targetfile) end remove_files(path.join(bindir, path.filename(target:symbolfile())), {emptydir = true}) |
