Skip to content

Fix: write package manifest.pathenvs in deterministic order#6882

Merged
waruqi merged 2 commits intoxmake-io:devfrom
romeoxbm:fix/manifest-pathenvs-deterministic-order
Oct 2, 2025
Merged

Fix: write package manifest.pathenvs in deterministic order#6882
waruqi merged 2 commits intoxmake-io:devfrom
romeoxbm:fix/manifest-pathenvs-deterministic-order

Conversation

@romeoxbm
Copy link
Contributor

@romeoxbm romeoxbm commented Oct 2, 2025

Problem

The manifest.pathenvs array written to manifest.txt was generated from a hashset via to_array().
hashset:to_array() iterates with Lua's next() and therefore the element order is not deterministic.
This produced non-deterministic manifest.txt content across builds, which caused package hashes to change
even when the set of path env names was logically identical.

Change

When saving package manifests, manifest.pathenvs is now constructed using the ordered iterator
self:_pathenvs():orderitems() so the resulting array is written in a stable, deterministic order.
This eliminates spurious manifest diffs and unstable package hashes caused only by iteration order.

Why this fix

  • Ensures deterministic manifests across different runs, hosts and Lua versions.
  • No behavioral change in what path env keys are captured — only the order is made deterministic.
  • Low-risk and localized change: only affects the serialization order when writing manifests.

Notes

  • If maintainers prefer a different canonical order (e.g., ensuring PATH appears first), I can adjust the sorting to a custom comparator. For now, orderitems() sorts keys in a consistent manner.

Tests

  • Repeated package builds should no longer produce differing manifest.txt contents caused solely by the
    order of pathenvs.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @romeoxbm, 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 addresses an issue where package manifest files (manifest.txt) were not consistently generated across builds due to the non-deterministic ordering of pathenvs entries. By implementing an ordered iteration method for these entries, the change ensures that manifest.txt content and subsequent package hashes remain stable and predictable, resolving spurious diffs without altering the functional behavior of path environment variable capture.

Highlights

  • Deterministic manifest.pathenvs Order: The manifest.pathenvs array written to manifest.txt was previously generated from a hashset, leading to non-deterministic ordering and unstable package hashes across builds.
  • Implementation of Ordered Iteration: The change ensures manifest.pathenvs is now constructed using self:_pathenvs():orderitems() to guarantee a stable, deterministic order when saving package manifests, eliminating spurious diffs.
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 non-deterministic ordering of manifest.pathenvs by using an ordered iterator, which is a great improvement for build reproducibility. My review includes a suggestion to refactor the implementation for better conciseness and to leverage an existing helper function, which should improve code maintainability.

Comment on lines +998 to +1007
-- ensure pathenvs are written deterministically: use ordered iteration
do
local arr = {}
for name in self:_pathenvs():orderitems() do
if name ~= nil then
table.insert(arr, name)
end
end
manifest.pathenvs = arr
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

This block of code can be simplified by using the existing table.to_array helper function, which converts an iterator to an array. This makes the code more concise and readable.

    -- ensure pathenvs are written deterministically
    manifest.pathenvs = table.to_array(self:_pathenvs():orderitems())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should do the trick as well. Will update the code.

@waruqi waruqi added this to the v3.0.4 milestone Oct 2, 2025
@waruqi waruqi merged commit b04e997 into xmake-io:dev Oct 2, 2025
22 checks passed
@romeoxbm romeoxbm deleted the fix/manifest-pathenvs-deterministic-order branch October 2, 2025 21:46
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.

2 participants