diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1b55257a83..37c324ee91 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -157,17 +157,36 @@ 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 + self._INFO:apival_set(name, ...) + + 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 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, ...) @@ -1086,7 +1105,17 @@ 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 + + self:_compute_buildhash() + + self._CONFIG_DIRTY = nil + end + -- load all components self:_load_components() @@ -1548,7 +1577,17 @@ 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 + -- 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 + + self._CONFIG_DIRTY = true end -- get the configurations of package @@ -1562,7 +1601,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 @@ -1604,7 +1646,11 @@ function _instance:_configs_for_buildhash() local ignored_configs_for_buildhash = hashset.from(requireinfo and requireinfo.ignored_configs_for_buildhash or {}) 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 value == nil then value = self:extraconf("configs", name, "default") -- support for the deprecated vs_runtime in add_configs @@ -1625,7 +1671,7 @@ end -- compute the build hash function _instance:_compute_buildhash() - self._BUILDHASH_PREPRARED = true + self._BUILDHASH_PREPARED = true self:buildhash() end @@ -1639,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) @@ -2783,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