fix(nuget): improve library file matching with score-based selection #7223
fix(nuget): improve library file matching with score-based selection #7223waruqi merged 1 commit intoxmake-io:devfrom
Conversation
- add path component matching to avoid x86/x86_64 confusion - implement score-based lib file selection for better architecture matching - support multiple include directory patterns - deduplicate includedirs and linkdirs in result
Summary of ChangesHello @KochabStar, 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 significantly refines how NuGet packages are processed by improving the selection of native library files and include directories. The core change introduces a sophisticated scoring system to accurately match library files based on various build parameters, resolving potential conflicts and ensuring optimal file selection. Additionally, it enhances the flexibility of include path detection and cleans up the final output by deduplicating paths. Highlights
🧠 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. Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves the logic for finding native library and include files within NuGet packages. The introduction of _match_path_component and a score-based system in _match_libfile makes architecture matching more robust, correctly handling cases like 'x86' vs 'x86_64'. The changes to include directory detection are also more flexible.
The overall approach is solid. I have a couple of suggestions to further improve efficiency and robustness. One is to move a constant table out of a frequently called function to avoid its recreation. The other is to use the new path component matching function more consistently to prevent potential partial matches.
Great work on making the NuGet package handling more reliable!
| if toolset and file_lower:find(toolset:lower(), 1, true) then | ||
| score = score + 4 | ||
| end | ||
| if file_lower:find(libmode:lower(), 1, true) then | ||
| score = score + 2 | ||
| end | ||
| if file_lower:find(runtime:lower(), 1, true) then | ||
| score = score + 1 | ||
| end |
There was a problem hiding this comment.
Using string.find for toolset, libmode, and runtime can lead to incorrect partial matches (e.g., a libmode of "Release" matching a path component "PreRelease"). For more robust matching, you should use the _match_path_component function here as well, which ensures that only whole path components are matched.
if toolset and _match_path_component(file_lower, toolset:lower()) then
score = score + 4
end
if _match_path_component(file_lower, libmode:lower()) then
score = score + 2
end
if _match_path_component(file_lower, runtime:lower()) then
score = score + 1
end
| local arch_patterns = { | ||
| x64 = {"x64", "amd64", "x86_64"}, | ||
| Win32 = {"win32", "x86", "i386", "i686"}, | ||
| arm64 = {"arm64", "aarch64"}, | ||
| } |
There was a problem hiding this comment.
For efficiency, it's better to define arch_patterns as a constant (upvalue) outside of the _match_libfile function, so it's not recreated on every call. Since this function is called inside a loop in _find_package, you can define arch_patterns once at the module level before _match_libfile to improve performance.
#7222