From 6a4f1b5f085c5fb2a579487c2d818ae6ac716513 Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Thu, 12 Feb 2026 13:13:30 +0800 Subject: [PATCH 1/4] fix: re-compute buildhash if config_set is called in `on_load` --- xmake/core/package/package.lua | 53 +++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1b55257a83..3cc9eda585 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -160,7 +160,29 @@ function _instance:set(name, ...) os.raise("'%s' can only be initied in on_source() or the description scope.", name) end end + print("----------------------\n function _instance:set(name, ...)") + utils.dump(self._NAME) + utils.dump(name, ...) self._INFO:apival_set(name, ...) + print("-----------------------") + + if name == "kind" then + -- the package kind is modified, the buildhash need to be re-computed + self._CONFIG_DIRTY = true + if (...) == "binary" then + -- remove shared config if this package is originally a library + local configs = self:configs() + if configs then + -- this can remove shared config from `manifest.txt` + configs.shared = nil + end + local requireinfo = self:requireinfo() + if requireinfo then + requireinfo.ignored_configs_for_buildhash = requireinfo.ignored_configs_for_buildhash or {} + table.insert(requireinfo.ignored_configs_for_buildhash, "shared") + end + end + end end -- add the value to the package info @@ -1086,7 +1108,18 @@ function _instance:_load() if on_load then on_load(self) end - + + if self._CONFIG_DIRTY then + -- drop the old buildhash and its configs + self._BUILDHASH = nil + self._CONFIGS_FOR_BUILDHASH = nil + + -- re-compute buildhash for `config_set` + self:_compute_buildhash() + + self._CONFIG_DIRTY = nil + end + -- load all components self:_load_components() @@ -1548,7 +1581,25 @@ function _instance:config_set(name, value) local configs = self:configs() if configs then configs[name] = value + utils.warning("package(%s) had automatically set config[%s] to %s", self._NAME, name, value) + end + print("-----------------------\n _instance:config_set(name, value)") + utils.dump(self._NAME) + utils.dump(name, value) + + -- update overridden configs for buildhash. + -- `self:requireinfo().configs` should remain readonly + local requireinfo = self:requireinfo() + if requireinfo then + requireinfo.configs_overrided = requireinfo.configs_overrided or {} + requireinfo.configs_overrided[name] = value end + + print("\n after update overridden configs:") + utils.dump(requireinfo.configs, requireinfo.configs_overrided) + print("-----------------------") + + self._CONFIG_DIRTY = true end -- get the configurations of package From 95971711029c88bc1795922274aceea49f3378f3 Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Thu, 12 Feb 2026 13:29:15 +0800 Subject: [PATCH 2/4] fix: config boolean value false should be able to override true --- xmake/core/package/package.lua | 67 ++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 3cc9eda585..0a3f857ceb 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -160,11 +160,14 @@ function _instance:set(name, ...) os.raise("'%s' can only be initied in on_source() or the description scope.", name) end end - print("----------------------\n function _instance:set(name, ...)") - utils.dump(self._NAME) - utils.dump(name, ...) - self._INFO:apival_set(name, ...) - print("-----------------------") + + if self._NAME == "libuv" then + print("----------------------\n function _instance:set(name, ...)") + utils.dump(self._NAME) + utils.dump(name, ...) + self._INFO:apival_set(name, ...) + print("-----------------------") + end if name == "kind" then -- the package kind is modified, the buildhash need to be re-computed @@ -893,6 +896,11 @@ function _instance:installdir(...) installdir = path.join(installdir, version_str) end installdir = path.join(installdir, self:buildhash()) + if self._NAME == "libuv" then + print("----------------------------------") + utils.dump(self._NAME, self:buildhash(), installdir) + print("----------------------------------") + end end self._INSTALLDIR = installdir end @@ -1109,16 +1117,23 @@ function _instance:_load() on_load(self) end + if self._NAME == "libuv" then + print("- before:") + utils.dump(self._NAME, self._BUILDHASH) + end if self._CONFIG_DIRTY then -- drop the old buildhash and its configs self._BUILDHASH = nil self._CONFIGS_FOR_BUILDHASH = nil - -- re-compute buildhash for `config_set` self:_compute_buildhash() self._CONFIG_DIRTY = nil end + if self._NAME == "libuv" then + print("- after:") + utils.dump(self._NAME, self._BUILDHASH) + end -- load all components self:_load_components() @@ -1583,10 +1598,11 @@ function _instance:config_set(name, value) configs[name] = value utils.warning("package(%s) had automatically set config[%s] to %s", self._NAME, name, value) end - print("-----------------------\n _instance:config_set(name, value)") - utils.dump(self._NAME) - utils.dump(name, value) - + if self._NAME == "libuv" then + print("-----------------------\n _instance:config_set(name, value)") + utils.dump(self._NAME) + utils.dump(name, value) + end -- update overridden configs for buildhash. -- `self:requireinfo().configs` should remain readonly local requireinfo = self:requireinfo() @@ -1595,9 +1611,11 @@ function _instance:config_set(name, value) requireinfo.configs_overrided[name] = value end - print("\n after update overridden configs:") - utils.dump(requireinfo.configs, requireinfo.configs_overrided) - print("-----------------------") + if self._NAME == "libuv" then + print("\n after update overridden configs:") + utils.dump(requireinfo.configs, requireinfo.configs_overrided) + print("-----------------------") + end self._CONFIG_DIRTY = true end @@ -1613,7 +1631,10 @@ function _instance:configs() local configs_required = requireinfo and requireinfo.configs or {} local configs_overrided = requireinfo and requireinfo.configs_overrided or {} for _, name in ipairs(table.wrap(configs_defined)) do - local value = configs_overrided[name] or configs_required[name] + local value = configs_overrided[name] + if value == nil then + value = configs_required[name] + end if value == nil then value = self:extraconf("configs", name, "default") -- support for the deprecated vs_runtime in add_configs @@ -1653,9 +1674,22 @@ function _instance:_configs_for_buildhash() local configs_required = requireinfo and requireinfo.configs or {} local configs_overrided = requireinfo and requireinfo.configs_overrided or {} local ignored_configs_for_buildhash = hashset.from(requireinfo and requireinfo.ignored_configs_for_buildhash or {}) + if self._NAME == "libuv" then + utils.dump(ignored_configs_for_buildhash) + end for _, name in ipairs(table.wrap(configs_defined)) do if not ignored_configs_for_buildhash:has(name) then - local value = configs_overrided[name] or configs_required[name] + local value = configs_overrided[name] + if value == nil then + -- if value==false, false should be able to override true + value = configs_required[name] + end + if name == "shared" then + print("**********************************") + utils.dump(name, value) + utils.dump(configs_overrided[name], configs_required[name]) + print("**********************************") + end if value == nil then value = self:extraconf("configs", name, "default") -- support for the deprecated vs_runtime in add_configs @@ -1671,6 +1705,9 @@ function _instance:_configs_for_buildhash() end self._CONFIGS_FOR_BUILDHASH = configs end + -- if self._NAME == "libuv" then + -- utils.dump(configs) + -- end return configs and configs or nil end From c64c2ac1e70e0e722fb40ba655cad2028c086f7f Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Thu, 12 Feb 2026 13:37:11 +0800 Subject: [PATCH 3/4] clean code, remove debug print --- xmake/core/package/package.lua | 44 +--------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 0a3f857ceb..20510473f6 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -161,13 +161,7 @@ function _instance:set(name, ...) end end - if self._NAME == "libuv" then - print("----------------------\n function _instance:set(name, ...)") - utils.dump(self._NAME) - utils.dump(name, ...) - self._INFO:apival_set(name, ...) - print("-----------------------") - end + self._INFO:apival_set(name, ...) if name == "kind" then -- the package kind is modified, the buildhash need to be re-computed @@ -896,11 +890,6 @@ function _instance:installdir(...) installdir = path.join(installdir, version_str) end installdir = path.join(installdir, self:buildhash()) - if self._NAME == "libuv" then - print("----------------------------------") - utils.dump(self._NAME, self:buildhash(), installdir) - print("----------------------------------") - end end self._INSTALLDIR = installdir end @@ -1117,10 +1106,6 @@ function _instance:_load() on_load(self) end - if self._NAME == "libuv" then - print("- before:") - utils.dump(self._NAME, self._BUILDHASH) - end if self._CONFIG_DIRTY then -- drop the old buildhash and its configs self._BUILDHASH = nil @@ -1130,10 +1115,6 @@ function _instance:_load() self._CONFIG_DIRTY = nil end - if self._NAME == "libuv" then - print("- after:") - utils.dump(self._NAME, self._BUILDHASH) - end -- load all components self:_load_components() @@ -1598,11 +1579,6 @@ function _instance:config_set(name, value) configs[name] = value utils.warning("package(%s) had automatically set config[%s] to %s", self._NAME, name, value) end - if self._NAME == "libuv" then - print("-----------------------\n _instance:config_set(name, value)") - utils.dump(self._NAME) - utils.dump(name, value) - end -- update overridden configs for buildhash. -- `self:requireinfo().configs` should remain readonly local requireinfo = self:requireinfo() @@ -1610,12 +1586,6 @@ function _instance:config_set(name, value) requireinfo.configs_overrided = requireinfo.configs_overrided or {} requireinfo.configs_overrided[name] = value end - - if self._NAME == "libuv" then - print("\n after update overridden configs:") - utils.dump(requireinfo.configs, requireinfo.configs_overrided) - print("-----------------------") - end self._CONFIG_DIRTY = true end @@ -1674,9 +1644,6 @@ function _instance:_configs_for_buildhash() local configs_required = requireinfo and requireinfo.configs or {} local configs_overrided = requireinfo and requireinfo.configs_overrided or {} local ignored_configs_for_buildhash = hashset.from(requireinfo and requireinfo.ignored_configs_for_buildhash or {}) - if self._NAME == "libuv" then - utils.dump(ignored_configs_for_buildhash) - end for _, name in ipairs(table.wrap(configs_defined)) do if not ignored_configs_for_buildhash:has(name) then local value = configs_overrided[name] @@ -1684,12 +1651,6 @@ function _instance:_configs_for_buildhash() -- if value==false, false should be able to override true value = configs_required[name] end - if name == "shared" then - print("**********************************") - utils.dump(name, value) - utils.dump(configs_overrided[name], configs_required[name]) - print("**********************************") - end if value == nil then value = self:extraconf("configs", name, "default") -- support for the deprecated vs_runtime in add_configs @@ -1705,9 +1666,6 @@ function _instance:_configs_for_buildhash() end self._CONFIGS_FOR_BUILDHASH = configs end - -- if self._NAME == "libuv" then - -- utils.dump(configs) - -- end return configs and configs or nil end From 475a6913089a843be262518f5d969d8d23c7ac6f Mon Sep 17 00:00:00 2001 From: Willaaaaaaa Date: Thu, 12 Feb 2026 13:43:11 +0800 Subject: [PATCH 4/4] fix typo --- xmake/core/package/package.lua | 10 +++++----- xmake/modules/private/action/require/impl/package.lua | 2 +- .../modules/private/action/require/impl/repository.lua | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 20510473f6..37c324ee91 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -157,7 +157,7 @@ function _instance:set(name, ...) -- @see https://github.com/xmake-io/xmake/issues/5148 -- https://github.com/xmake-io/xmake-repo/pull/4204 if self:_sourceset():has(name) and self:get(name) == nil then - os.raise("'%s' can only be initied in on_source() or the description scope.", name) + os.raise("'%s' can only be initialized in on_source() or the description scope.", name) end end @@ -186,7 +186,7 @@ end function _instance:add(name, ...) if self._SOURCE_INITED then if self:_sourceset():has(name) and self:get(name) == nil then - os.raise("'%s' can only be initied in on_source() or the description scope.", name) + os.raise("'%s' can only be initialized in on_source() or the description scope.", name) end end self._INFO:apival_add(name, ...) @@ -1671,7 +1671,7 @@ end -- compute the build hash function _instance:_compute_buildhash() - self._BUILDHASH_PREPRARED = true + self._BUILDHASH_PREPARED = true self:buildhash() end @@ -1685,7 +1685,7 @@ end function _instance:buildhash() local buildhash = self._BUILDHASH if buildhash == nil then - if not self._BUILDHASH_PREPRARED then + if not self._BUILDHASH_PREPARED then os.raise("package:buildhash() must be called after loading package") end local function _get_buildhash(configs, opt) @@ -2829,7 +2829,7 @@ function package.targetplat() return plat end --- get global target architecture of pacakge +-- get global target architecture of package function package.targetarch() local arch = package._memcache():get("target_arch") if arch == nil then diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 7cd26e55ff..4e2d70e5fe 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -912,7 +912,7 @@ function _load_package(packagename, requireinfo, opt) end end - -- strip trailng ~tag, e.g. zlib~debug + -- strip trailing ~tag, e.g. zlib~debug local displayname if packagename:find('~', 1, true) then displayname = packagename diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index c118284d24..ba0c9205f6 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -153,7 +153,7 @@ end -- get package directory from repositories function packagedir(packagename, opt) - -- strip trailng ~tag, e.g. zlib~debug + -- strip trailing ~tag, e.g. zlib~debug opt = opt or {} packagename = packagename:lower() if packagename:find('~', 1, true) then