Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions xmake/core/package/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +166 to +182
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current logic correctly handles changing a package's kind to "binary" by adding "shared" to ignored_configs_for_buildhash. However, it doesn't handle the case where the kind is changed from "binary" to another type (e.g., "library"). In that scenario, "shared" would remain in ignored_configs_for_buildhash, which could lead to incorrect build hashes if the shared configuration is later modified for the library.

To make this more robust, you should also handle the else case to remove "shared" from ignored_configs_for_buildhash when the kind is not "binary".

    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
        else
            local requireinfo = self:requireinfo()
            if requireinfo and requireinfo.ignored_configs_for_buildhash then
                table.remove_if(requireinfo.ignored_configs_for_buildhash, function(_, v) return v == "shared" end)
            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, ...)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -1625,7 +1671,7 @@ end

-- compute the build hash
function _instance:_compute_buildhash()
self._BUILDHASH_PREPRARED = true
self._BUILDHASH_PREPARED = true
self:buildhash()
end

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/private/action/require/impl/package.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/private/action/require/impl/repository.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading