From 0f8169ba29ffaa72a60619b6eefdfd8c9f0a51a0 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Tue, 15 Mar 2022 18:30:39 +0800 Subject: Fix paths for precompiled package on linux. --- .../action/require/impl/actions/install.lua | 35 ++++++++++++++++++++-- 1 file 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 -- cgit v1.3.1 From a15768131bc8b1743fee9d6c3c63428dda9d04c8 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Wed, 16 Mar 2022 08:42:37 +0800 Subject: Fix path for all platforms. --- .../action/require/impl/actions/install.lua | 55 +++++++++------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 9d09a55c5..1830a01cd 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -19,6 +19,7 @@ -- -- imports +import("core.base.global") import("core.base.option") import("core.base.tty") import("core.project.target") @@ -98,18 +99,32 @@ end -- fix paths for the precompiled package -- @see https://github.com/xmake-io/xmake/issues/1671 -function _fix_paths_for_precompiled_package_windows(package) +function _fix_paths_for_precompiled_package(package) + local buildhash_pattern = string.rep('%x', 32) + -- Matches to path like (string inside brackets is matched): + -- /home/user/.xmake[/pacakges/f/foo/9adc96bd69124211aad7dd58a36f02ce/]v1.0 + -- Replaces path string before "packages" with global configured directory. + local match_pattern = "[\\/]packages[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. buildhash_pattern .. "[\\/]" + local prefix = global.directory() + 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(package:buildhash(), 1, true) and value:find(package:name(), 1, true) then + local mat = value:match(match_pattern) + if mat then local result - local splitinfo = value:split(package:buildhash(), {plain = true}) + local splitinfo = value:split(mat, {plain = true}) if #splitinfo == 2 then - result = path.join(package:installdir(), splitinfo[2]) + result = path.join(prefix, mat, splitinfo[2]) elseif #splitinfo == 1 then - result = package:installdir() + if value:sub(1, #mat) == mat then + -- path begins with matched pattern: [/packages/f/foo/buildhash/]v1.0 + result = path.join(prefix, value) + else + -- path ends with matched pattern: /home/user[/packages/f/foo/buildhash/] + result = path.join(prefix, mat) + end end if result then result = result:gsub("\\", "/") @@ -122,30 +137,6 @@ function _fix_paths_for_precompiled_package_windows(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) @@ -257,11 +248,7 @@ function main(package) -- fix paths for the precompiled 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 + _fix_paths_for_precompiled_package(package) end -- patch pkg-config files for package -- cgit v1.3.1 From 0a97ca79d0e52e8f21d068047595446423720957 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Wed, 16 Mar 2022 10:26:22 +0800 Subject: Use core_package.installdir to fix path prefix. --- xmake/modules/private/action/require/impl/actions/install.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index 1830a01cd..5e8b84f26 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -19,9 +19,9 @@ -- -- imports -import("core.base.global") import("core.base.option") import("core.base.tty") +import("core.package.package", {alias = "core_package"}) import("core.project.target") import("lib.detect.find_file") import("private.action.require.impl.actions.test") @@ -100,12 +100,15 @@ end -- fix paths for the precompiled package -- @see https://github.com/xmake-io/xmake/issues/1671 function _fix_paths_for_precompiled_package(package) - local buildhash_pattern = string.rep('%x', 32) -- Matches to path like (string inside brackets is matched): -- /home/user/.xmake[/pacakges/f/foo/9adc96bd69124211aad7dd58a36f02ce/]v1.0 - -- Replaces path string before "packages" with global configured directory. + -- Replaces path string before "packages" with local pacakge install + -- directory. + -- Note: It's possible that package A references files package B, thus we + -- need to match against all possible package install paths. + local buildhash_pattern = string.rep('%x', 32) local match_pattern = "[\\/]packages[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. buildhash_pattern .. "[\\/]" - local prefix = global.directory() + local prefix = path.directory(core_package.installdir()) local filepaths = {path.join(package:installdir(), "**.cmake|include/**")} for _, filepath in ipairs(filepaths) do -- cgit v1.3.1 From 4e7ef0824c74db2aa27c7230da129e91ef8a13f9 Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Wed, 16 Mar 2022 10:28:36 +0800 Subject: fix typo and grammar. --- xmake/modules/private/action/require/impl/actions/install.lua | 6 +++--- 1 file changed, 3 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 5e8b84f26..81068a6e3 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -100,11 +100,11 @@ end -- fix paths for the precompiled package -- @see https://github.com/xmake-io/xmake/issues/1671 function _fix_paths_for_precompiled_package(package) - -- Matches to path like (string inside brackets is matched): + -- Match to path like (string insides brackets is matched): -- /home/user/.xmake[/pacakges/f/foo/9adc96bd69124211aad7dd58a36f02ce/]v1.0 - -- Replaces path string before "packages" with local pacakge install + -- Replace path string before "packages" with local pacakge install -- directory. - -- Note: It's possible that package A references files package B, thus we + -- Note: It's possible that package A references files in package B, thus we -- need to match against all possible package install paths. local buildhash_pattern = string.rep('%x', 32) local match_pattern = "[\\/]packages[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. buildhash_pattern .. "[\\/]" -- cgit v1.3.1 From ea5c33fb86182032a59b88332b534d561c0c180d Mon Sep 17 00:00:00 2001 From: Chen Yufei Date: Wed, 16 Mar 2022 11:03:53 +0800 Subject: Fix typo, code tweaks. --- xmake/modules/private/action/require/impl/actions/install.lua | 6 +++--- 1 file changed, 3 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 81068a6e3..fb8abd6b4 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -101,8 +101,8 @@ end -- @see https://github.com/xmake-io/xmake/issues/1671 function _fix_paths_for_precompiled_package(package) -- Match to path like (string insides brackets is matched): - -- /home/user/.xmake[/pacakges/f/foo/9adc96bd69124211aad7dd58a36f02ce/]v1.0 - -- Replace path string before "packages" with local pacakge install + -- /home/user/.xmake[/packages/f/foo/9adc96bd69124211aad7dd58a36f02ce/]v1.0 + -- Replace path string before "packages" with local package install -- directory. -- Note: It's possible that package A references files in package B, thus we -- need to match against all possible package install paths. @@ -121,7 +121,7 @@ function _fix_paths_for_precompiled_package(package) if #splitinfo == 2 then result = path.join(prefix, mat, splitinfo[2]) elseif #splitinfo == 1 then - if value:sub(1, #mat) == mat then + if value:startswith(mat) then -- path begins with matched pattern: [/packages/f/foo/buildhash/]v1.0 result = path.join(prefix, value) else -- cgit v1.3.1