diff options
| author | ruki <[email protected]> | 2025-07-26 00:47:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-07-26 00:47:48 +0800 |
| commit | e3759b8bd56d614b49d95256c04c7d093100d64a (patch) | |
| tree | cb290dce757bfff2bb07377569c033665cae1c41 | |
| parent | 53d106bc017dc2e7db4bdff583ebe863c957ab9f (diff) | |
add resolve_hint_paths
| -rw-r--r-- | xmake/modules/target/action/install/main.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/target/action/uninstall/main.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/utils/binary/deplibs.lua | 17 | ||||
| -rw-r--r-- | xmake/plugins/pack/batchcmds.lua | 11 |
4 files changed, 30 insertions, 19 deletions
diff --git a/xmake/modules/target/action/install/main.lua b/xmake/modules/target/action/install/main.lua index 0d102ffd7..d9faa80ad 100644 --- a/xmake/modules/target/action/install/main.lua +++ b/xmake/modules/target/action/install/main.lua @@ -71,13 +71,11 @@ function _get_target_package_libfiles(target, opt) -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... -- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), { - recursive = true, plat = target:plat(), arch = target:arch()}) + plat = target:plat(), arch = target:arch(), + recursive = true, resolve_path = true, resolve_hint_paths = libfiles}) if deplibs then - local depends = hashset.new() - for _, deplib in ipairs(deplibs) do - depends:insert(path.filename(deplib)) - end - table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + local depends = hashset.from(deplibs) + table.remove_if(libfiles, function (_, libfile) return not depends:has(libfile) end) end end end diff --git a/xmake/modules/target/action/uninstall/main.lua b/xmake/modules/target/action/uninstall/main.lua index 6eff73529..2273ff76d 100644 --- a/xmake/modules/target/action/uninstall/main.lua +++ b/xmake/modules/target/action/uninstall/main.lua @@ -70,13 +70,12 @@ function _get_target_package_libfiles(target, opt) if target:is_binary() or target:is_shared() or opt.binaryfile then -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... -- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 - local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), {recursive = true, plat = target:plat(), arch = target:arch()}) + local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), { + plat = target:plat(), arch = target:arch(), + recursive = true, resolve_path = true, resolve_hint_paths = libfiles}) if deplibs then - local depends = hashset.new() - for _, deplib in ipairs(deplibs) do - depends:insert(path.filename(deplib)) - end - table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + local depends = hashset.from(deplibs) + table.remove_if(libfiles, function (_, libfile) return not depends:has(libfile) end) end end end diff --git a/xmake/modules/utils/binary/deplibs.lua b/xmake/modules/utils/binary/deplibs.lua index b81d644d8..15ca0b12b 100644 --- a/xmake/modules/utils/binary/deplibs.lua +++ b/xmake/modules/utils/binary/deplibs.lua @@ -235,6 +235,7 @@ end -- resolve file path with @rpath, @loader_path, and $ORIGIN function _resolve_filepath(binaryfile, dependfile, opt) local loaderfile = opt._loaderfile + local resolve_hint_paths = opt.resolve_hint_paths if dependfile:startswith("@rpath/") then local rpathlist = opt._rpathlist if rpathlist == nil then @@ -263,6 +264,19 @@ function _resolve_filepath(binaryfile, dependfile, opt) end end end + if not path.is_absolute(dependfile) then + if os.isfile(dependfile) then + dependfile = path.absolute(dependfile) + elseif resolve_hint_paths then + local filename = path.filename(dependfile) + for _, filepath in ipairs(resolve_hint_paths) do + if filename == path.filename(filepath) then + dependfile = path.absolute(filepath) + break + end + end + end + end dependfile = path.normalize(dependfile) if binaryfile ~= dependfile then return dependfile @@ -303,9 +317,10 @@ end -- get the library dependencies of the give binary files -- -- @param binaryfile the binary file --- @param opt the option, e.g. {recursive = false, resolve_path = true} +-- @param opt the option, e.g. {recursive = false, resolve_path = true, resolve_hint_paths = {}} -- - recursive: recursively get all sub-dependencies, sorted by topology -- - resolve_path: try to resolve the file full path, e.g. @rpath, @loader_path, $ORIGIN, relative path .. +-- - resolve_hint_paths: we can resolve and match path from them -- function main(binaryfile, opt) opt = opt or {} diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index df0c506e0..2418f39ac 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -83,13 +83,12 @@ function _get_target_package_libfiles(target, opt) if target:is_binary() or target:is_shared() or opt.binaryfile then -- we need to get all deplibs, e.g. app -> libfoo.so -> libbar.so ... -- @see https://github.com/xmake-io/xmake/issues/5325#issuecomment-2242597732 - local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), {recursive = true, plat = target:plat(), arch = target:arch()}) + local deplibs = get_depend_libraries(opt.binaryfile or target:targetfile(), { + plat = target:plat(), arch = target:arch(), + recursive = true, resolve_path = true, resolve_hint_paths = libfiles}) if deplibs then - local depends = hashset.new() - for _, deplib in ipairs(deplibs) do - depends:insert(path.filename(deplib)) - end - table.remove_if(libfiles, function (_, libfile) return not depends:has(path.filename(libfile)) end) + local depends = hashset.from(deplibs) + table.remove_if(libfiles, function (_, libfile) return not depends:has(libfile) end) end end end |
