summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-03-16 11:49:15 +0800
committerGitHub <[email protected]>2022-03-16 11:49:15 +0800
commit35fa885c6a76ab273f2169885ccebe0373dedfea (patch)
tree93dcec89c18f906c2e2ead7e3ef3cd15bc44f280
parentb7cce558973740d31721fc2364f27e176b2cfe7d (diff)
parentea5c33fb86182032a59b88332b534d561c0c180d (diff)
Merge pull request #2167 from cyfdecyf/dev
Fix paths for precompiled package on linux.
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua29
1 files changed, 24 insertions, 5 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..fb8abd6b4 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -21,6 +21,7 @@
-- imports
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")
@@ -99,17 +100,34 @@ end
-- fix paths for the precompiled package
-- @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[/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.
+ local buildhash_pattern = string.rep('%x', 32)
+ local match_pattern = "[\\/]packages[\\/]%w[\\/][^\\/]+[\\/][^\\/]+[\\/]" .. buildhash_pattern .. "[\\/]"
+ local prefix = path.directory(core_package.installdir())
+
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:startswith(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,6 +140,7 @@ function _fix_paths_for_precompiled_package(package)
end
end
+
-- check package toolchains
function _check_package_toolchains(package)
for _, toolchain_inst in pairs(package:toolchains()) do
@@ -231,7 +250,7 @@ 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
+ if not package:is_built() and not package:is_system() then
_fix_paths_for_precompiled_package(package)
end