summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/core/package/package.lua9
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua5
2 files changed, 12 insertions, 2 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 2cf65f2a4..2021452d7 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -2958,6 +2958,10 @@ function package.cachedir(opt)
local cachedir = package._CACHEDIR
if not cachedir then
cachedir = os.getenv("XMAKE_PKG_CACHEDIR") or global.get("pkg_cachedir") or path.join(global.cachedir(), "packages")
+ -- normalize it to ensure all derived paths are consistent, e.g. the user
+ -- may pass a path with `..` or relative segments via XMAKE_PKG_CACHEDIR.
+ -- @see https://github.com/xmake-io/xmake/issues/7576
+ cachedir = path.normalize(path.absolute(cachedir))
package._CACHEDIR = cachedir
end
if opt.rootonly then
@@ -2981,6 +2985,11 @@ function package.installdir(opt)
local installdir = package._INSTALLDIR
if not installdir then
installdir = os.getenv("XMAKE_PKG_INSTALLDIR") or global.get("pkg_installdir") or path.join(global.directory(), "packages")
+ -- normalize it to ensure all derived paths are consistent, e.g. the user
+ -- may pass a path with `..` or relative segments via XMAKE_PKG_INSTALLDIR.
+ -- otherwise the relocated pkgconfig *.pc files would contain a broken
+ -- relative prefix. @see https://github.com/xmake-io/xmake/issues/7576
+ installdir = path.normalize(path.absolute(installdir))
package._INSTALLDIR = installdir
end
return installdir
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 57257b7f6..7fb54a951 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -56,8 +56,9 @@ function _patch_pkgconfig(package)
local pcfile_content, count = pcfile_content:replace(installdir, "${installdir}", {plain = true})
if count > 0 then
local line_ending = pcfile_content:find("\r\n") and "\r\n" or "\n"
+ local pcfiledir = path.unix(path.normalize(path.directory(pcfile)))
pcfile_content = "# Modified by Xmake: Using relative paths to make package relocatable" .. line_ending
- .. "installdir=${pcfiledir}/" .. path.unix(path.relative(installdir, path.directory(pcfile))) .. line_ending
+ .. "installdir=${pcfiledir}/" .. path.unix(path.relative(installdir, pcfiledir)) .. line_ending
.. pcfile_content
io.writefile(pcfile, pcfile_content)
end
@@ -111,7 +112,7 @@ function _patch_pkgconfig(package)
-- @see https://github.com/xmake-io/xmake-repo/pull/8165#discussion_r2366249416
local version = package:version_str():ltrim("v")
file:print("# Generated by Xmake")
- file:print("prefix=%s", "${pcfiledir}/" .. path.unix(path.relative(installdir, path.directory(pcfile))))
+ file:print("prefix=%s", "${pcfiledir}/" .. path.unix(path.relative(installdir, path.unix(path.normalize(path.directory(pcfile))))))
file:print("exec_prefix=${prefix}")
file:print("libdir=${exec_prefix}/lib")
file:print("includedir=${prefix}/include")