Add default file filter for format task#6864
Conversation
format taskformat task
Summary of ChangesHello @Stehsaer, 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 enhances the reliability and user-friendliness of the Highlights
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 introduces a default file filter for the format task to prevent clang-format from corrupting non-C/C++ files. The approach is sound, but the implementation is incomplete as it only filters source files and not header files, which could still lead to file corruption. I've suggested a fix to apply filtering to header files as well for consistency and robustness. The typo fix in the task description is correct.
Under almost all cases, users won't add non-cxx files through |
Background
Currently, when using
formattask,xmakecallsclang-formatto format all files added throughadd_files. This is fine if the project/target only contains C or C++ files. However, when we have other files added as source files, such as binary assets (forutils.bin2c) and assembly files, clang-format will also "format" those and complely corrupt the files. Take a look at this example:File tree:
In the most recent
xmakeversion (v3.0.3+HEAD.de7aca4), after executingxmake format test,asset/font.ttf.gzwill be corrupted byclang-format, becausexmakeincorrectly added this file into the command line ofclang-format.For more info, see related discussions and issues:
How this PR fixes the issue
This PR fixes the issue by adding a default file filter when no
--filesoption is specified forxmake format. The default file filter is set as**.c,**.cxx,**.cppand**.cc, which covers most file extensions for C/C++ source.Q&A
Why fix this issue?
Convenience. For projects (especially when developing for embedded sys. and computer graphics, where asm. files or art assets need to be added as source files), it is inconvenient to manually specifying
--files=xxxevery time. Adding a default filter can greatly improve the overall experience of usingxmake, when a simplexmake formathelp you do all the jobs to format cxx files.Why add default filter?
clang-formatis designed for formatting C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code, andxmakeis primarily designed for building C/C++ code. Adding a default filter matches the overall design goal ofxmake, avoids passing unwanted files (archives, asm codes, etc.) toclang-formatwhich causes unwanted file corruptions, and improves experience. Usage of formatting non-cxx-files as if they were cxx files is extremely rare, and in my point of view, should be done through custom tasks.Other Changes
xmake formattask description