diff options
| author | Chen Yufei <[email protected]> | 2022-03-15 18:30:39 +0800 |
|---|---|---|
| committer | Chen Yufei <[email protected]> | 2022-03-15 18:40:18 +0800 |
| commit | 0f8169ba29ffaa72a60619b6eefdfd8c9f0a51a0 (patch) | |
| tree | 5aa11789d06596d11c0b32fac038034d77673a9f | |
| parent | 18b910e27d60ee244ee2245071f33ff0fc821991 (diff) | |
Fix paths for precompiled package on linux.
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/install.lua | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index cbe836ed2..9d09a55c5 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -98,7 +98,7 @@ end -- fix paths for the precompiled package -- @see https://github.com/xmake-io/xmake/issues/1671 -function _fix_paths_for_precompiled_package(package) +function _fix_paths_for_precompiled_package_windows(package) local filepaths = {path.join(package:installdir(), "**.cmake|include/**")} for _, filepath in ipairs(filepaths) do for _, file in ipairs(os.files(filepath)) do @@ -122,6 +122,31 @@ function _fix_paths_for_precompiled_package(package) end end +function _fix_paths_for_precompiled_package_linux(package) + -- Replace path before "/.xmake/packages/" with prefix in installdir. + -- It's possible for a package to contain paths to another package. Thus + -- This function does not match against buildhash. + local match_pattern = "/.xmake/packages/" + local prefix = package:installdir():split(match_pattern, {plain = true})[1] + + local filepaths = {path.join(package:installdir(), "**.cmake|include/**")} + for _, filepath in ipairs(filepaths) do + for _, file in ipairs(os.files(filepath)) do + io.gsub(file, "(\"(.-)\")", function(_, value) + if value:find(match_pattern, 1, true) then + local splitinfo = value:split(match_pattern, {plain = true}) + if #splitinfo == 2 then + local result = path.join(prefix, match_pattern, splitinfo[2]) + vprint("fix path: %s => %s in %s", splitinfo[1], prefix, file) + return '"' .. result .. '"' + end + end + end) + end + end +end + + -- check package toolchains function _check_package_toolchains(package) for _, toolchain_inst in pairs(package:toolchains()) do @@ -231,8 +256,12 @@ function main(package) if installed_now then -- fix paths for the precompiled package - if package:is_plat("windows") and not package:is_built() and not package:is_system() then - _fix_paths_for_precompiled_package(package) + if not package:is_built() and not package:is_system() then + if package:is_plat("windows") then + _fix_paths_for_precompiled_package_windows(package) + elseif package:is_plat("linux") then + _fix_paths_for_precompiled_package_linux(package) + end end -- patch pkg-config files for package |
