diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1073c0a45d..8704b3df17 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -642,7 +642,15 @@ end -- is local package? -- we will use local installdir and cachedir in current project function _instance:is_local() - return self:is_source_embed() or self:is_binary_embed() or self:is_thirdparty() + return self._IS_LOCAL or self:is_source_embed() or self:is_binary_embed() or self:is_thirdparty() +end + +-- mark it as local package +function _instance:_mark_as_local(is_local) + if self:is_local() ~= is_local then + self._INSTALLDIR = nil + self._IS_LOCAL = is_local + end end -- use external includes? @@ -1807,6 +1815,23 @@ function _instance:fetch(opt) external = self:use_external_includes() end + -- always install to the local project directory? + -- @see https://github.com/xmake-io/xmake/pull/4376 + local install_locally + if project and project.policy("package.install_locally") then + install_locally = true + end + if install_locally == nil and self:policy("package.install_locally") then + install_locally = true + end + if not self:is_local() and install_locally and system ~= true then + local has_global = os.isfile(self:manifest_file()) + self:_mark_as_local(true) + if has_global and not os.isfile(self:manifest_file()) then + self:_mark_as_local(false) + end + end + -- fetch binary tool? fetchinfo = nil local is_system = nil diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 5d1e47c53e..84f29dd06d 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -100,6 +100,8 @@ function policy.policies() ["package.install_only"] = {description = "Only install packages from remote.", type = "boolean"}, -- Always install packages every time ["package.install_always"] = {description = "Always install packages every time.", type = "boolean"}, + -- Install packages in the local project folder + ["package.install_locally"] = {description = "Install packages in the local project folder.", default = false, type = "boolean"}, -- Set custom headers when downloading package ["package.download.http_headers"] = {description = "Set the custom http headers when downloading package."}, -- Use includes as external header files? e.g. -isystem ..