From 9d6f7535bc7991216c5005414f6e26aa8639599c Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Apr 2026 00:52:19 +0800 Subject: fix package local dir --- xmake/core/package/package.lua | 20 +++++++++++++++----- xmake/modules/package/tools/xmake.lua | 10 ++++++++++ 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..c2f6133d1 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") 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() then + envs = table.clone(envs) + envs.XMAKE_PKG_INSTALLDIR = package.installdir({localdir = true}) + end + -- pass local repositories for _, repo in ipairs(repository.repositories()) do local repo_argv = {"repo"} -- cgit v1.3.1 From 7b9ad034be9e65c704f7addd66c394a273104b7a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Apr 2026 22:07:40 +0800 Subject: fix sourcelocal --- xmake/modules/package/tools/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index c2f6133d1..f5bc81343 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -529,7 +529,7 @@ function install(package, configs, opt) -- 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() then + if package:is_local() and not package:is_source_embed() then envs = table.clone(envs) envs.XMAKE_PKG_INSTALLDIR = package.installdir({localdir = true}) end -- cgit v1.3.1 From c4aca7fbbacf179b1f9d26048e84f76213c255fc Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Apr 2026 23:09:55 +0800 Subject: fix package installdir --- xmake/modules/package/tools/xmake.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index f5bc81343..ea0ce9d65 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -23,7 +23,7 @@ import("core.base.option") import("core.base.global") import("core.tool.toolchain") import("core.project.project") -import("core.package.package") +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"}) @@ -531,7 +531,7 @@ function install(package, configs, opt) -- @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.installdir({localdir = true}) + envs.XMAKE_PKG_INSTALLDIR = package_core.installdir({localdir = true}) end -- pass local repositories -- cgit v1.3.1