Skip to content

fix: re-compute buildhash if config/kind is changed in on_load#7315

Closed
Willaaaaaaa wants to merge 4 commits intoxmake-io:devfrom
Willaaaaaaa:patch-1
Closed

fix: re-compute buildhash if config/kind is changed in on_load#7315
Willaaaaaaa wants to merge 4 commits intoxmake-io:devfrom
Willaaaaaaa:patch-1

Conversation

@Willaaaaaaa
Copy link
Contributor

Fix #7314

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Willaaaaaaa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where the build hash for packages was not consistently updated when package configurations, such as the package type or specific settings, were dynamically altered within the on_load function. The changes ensure that the build hash accurately reflects the current package state, preventing stale builds and enhancing the reliability of the build system's caching mechanism.

Highlights

  • Buildhash Re-computation: Implemented logic to automatically re-compute the package buildhash when the package kind or other configurations are modified during the on_load phase, ensuring build consistency.
  • Package Kind Handling: Enhanced the set function to specifically handle changes to the package kind, particularly for 'binary' packages, where 'shared' configurations are now explicitly ignored for buildhash calculation.
  • Configuration Overriding: Improved the mechanism for overriding package configurations, ensuring that false values are correctly processed and that any overridden configurations trigger a buildhash re-computation.
  • Typo Corrections: Addressed several minor typos in comments and variable names across multiple files for improved code readability and accuracy.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • xmake/core/package/package.lua
    • Implemented buildhash re-computation logic when package 'kind' or other configurations are set.
    • Added specific handling for 'binary' package kind to remove 'shared' config and ignore it for buildhash.
    • Introduced _CONFIG_DIRTY flag to manage buildhash re-computation after on_load.
    • Updated config_set to store overridden configurations and mark the config as dirty.
    • Modified config retrieval logic in configs() and _configs_for_buildhash() to correctly prioritize overridden false values.
    • Corrected typo from 'initied' to 'initialized' in error messages.
    • Fixed typo from '_BUILDHASH_PREPRARED' to '_BUILDHASH_PREPARED'.
    • Corrected typo from 'pacakge' to 'package' in a comment.
  • xmake/modules/private/action/require/impl/package.lua
    • Corrected typo from 'trailng' to 'trailing' in a comment.
  • xmake/modules/private/action/require/impl/repository.lua
    • Corrected typo from 'trailng' to 'trailing' in a comment.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the issue of re-computing the build hash when a package's kind or configs are modified in on_load. The introduction of the _CONFIG_DIRTY flag and its handling in _instance:_load is a solid approach. The fix to correctly handle false configuration values by replacing or with an explicit if value == nil check is also a great improvement. I also appreciate the various typo fixes throughout the codebase.

I have one suggestion to make the logic for handling kind changes more robust by considering the case where the kind is changed from binary to another type.

Comment on lines +166 to +182
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
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

@waruqi
Copy link
Member

waruqi commented Feb 12, 2026

buildhash 暂时不要去动,我知道有这个问题,但这个不是这么好改的。

on_load 执行之前,package 内部 _load_package 很多地方都已经用上了 buildhash ,比如 installdir ,而且还已经创建了目录,而且还有 package cache 存在,都会被影响。

即使你后面刷新了 buildhash ,也会导致很多地方状态不一致,引出各种问题。另外现在的改法,很多都是对 kind 硬处理,更不好维护。

@waruqi
Copy link
Member

waruqi commented Feb 12, 2026

目前

@waruqi waruqi closed this Feb 12, 2026
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Don't touch buildhash for now. I know there is this problem, but it is not easy to change.

Before on_load is executed, buildhash has been used in many places within the package _load_package, such as installdir, and the directory has been created, and the package cache exists, so it will be affected.

Even if you refresh the buildhash later, the status will be inconsistent in many places and lead to various problems. In addition, many of the current reform methods require hard processing of kind, which is even more difficult to maintain.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


at present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Buildhash is not updated if a package description reset its configs/kind in on_load scope

3 participants