summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-04 18:15:37 +0800
committerGitHub <[email protected]>2026-04-04 18:15:37 +0800
commit4633e0cc62b715be538fd5a6e8ed7a3bb4cc6040 (patch)
tree8fadcbf8bfc6cbefd82acd137a3c84528573859c
parent2976f6c0d0fa7c17262899245cd1da17cd79de48 (diff)
parentc4aca7fbbacf179b1f9d26048e84f76213c255fc (diff)
Merge pull request #7445 from xmake-io/package
fix package local dir
-rw-r--r--xmake/core/package/package.lua20
-rw-r--r--xmake/modules/package/tools/xmake.lua10
2 files changed, 25 insertions, 5 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 7e20a1cda..395ddbfa3 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -843,7 +843,7 @@ function _instance:builddir()
if not builddir then
if self:is_local() then
local name = self:name():lower():gsub("::", "_")
- local rootdir = path.join(config.builddir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, self:version_str())
+ local rootdir = path.join(package.installdir({localdir = true}), name:sub(1, 1):lower(), name, self:version_str())
builddir = path.join(rootdir, "cache", "build_" .. hash.rand32())
else
builddir = "build_" .. hash.rand32()
@@ -886,7 +886,7 @@ function _instance:cachedir()
version_str = version_str:gsub("[>=<|%*]", "")
end
if self:is_local() then
- cachedir = path.join(config.builddir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, version_str, "cache")
+ cachedir = path.join(package.installdir({localdir = true}), name:sub(1, 1):lower(), name, version_str, "cache")
else
cachedir = path.join(package.cachedir(), name:sub(1, 1):lower(), name, version_str)
end
@@ -908,7 +908,7 @@ function _instance:installdir(...)
if not installdir then
local name = self:name():lower():gsub("::", "_")
if self:is_local() then
- installdir = path.join(config.builddir({absolute = true}), ".packages", name:sub(1, 1):lower(), name)
+ installdir = path.join(package.installdir({localdir = true}), name:sub(1, 1):lower(), name)
else
installdir = path.join(package.installdir(), name:sub(1, 1):lower(), name)
end
@@ -2939,8 +2939,18 @@ function package.cachedir(opt)
return path.join(cachedir, os.date("%y%m"))
end
--- the install directory
-function package.installdir()
+-- the global/local install directory for packages
+--
+-- @param opt the options, e.g. {localdir = true}
+-- - localdir: return the local project packages directory (build/.packages)
+-- instead of the global directory (~/.xmake/packages)
+--
+-- @return the install directory path
+--
+function package.installdir(opt)
+ if opt and opt.localdir then
+ return path.join(config.builddir({absolute = true}), ".packages")
+ end
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")
diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua
index 133de5f39..ea0ce9d65 100644
--- a/xmake/modules/package/tools/xmake.lua
+++ b/xmake/modules/package/tools/xmake.lua
@@ -23,6 +23,7 @@ import("core.base.option")
import("core.base.global")
import("core.tool.toolchain")
import("core.project.project")
+import("core.package.package", {alias = "package_core"})
import("core.package.repository")
import("private.action.require.impl.package", {alias = "require_package"})
import("private.utils.toolchain", {alias = "toolchain_utils"})
@@ -524,6 +525,15 @@ function install(package, configs, opt)
-- get build environments
local envs = opt.envs or buildenvs(package)
+ -- if the package is installed locally, pass the local packages directory
+ -- to the child xmake process so it can find already-installed deps
+ -- without re-installing them to the global directory
+ -- @see https://github.com/xmake-io/xmake/discussions/7441
+ if package:is_local() and not package:is_source_embed() then
+ envs = table.clone(envs)
+ envs.XMAKE_PKG_INSTALLDIR = package_core.installdir({localdir = true})
+ end
+
-- pass local repositories
for _, repo in ipairs(repository.repositories()) do
local repo_argv = {"repo"}