[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(code-format): 2 enhancements #7311

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vwheeler63
Copy link
Contributor
@vwheeler63 vwheeler63 commented Nov 15, 2024
  • code-format.cfg doesn't work on Windows because it makes astyle edit every single source file and changes the line endings. Git, perceives this as a change, and makes Windows users have to RESET 672 files just in the ./src/ directory and I didn't count the number in the other directories. Resetting files can be dangerous to work in progress. Especially when it involves that many files.

    Rationale: Git -- out of the box, with default configuration -- automatically stores source files in its repository with LF-only (Linux) line endings. On Windows, each time a file content moves from repository to working directory, its line endings are converted to the line endings native to the platform it is running on. And each time file content is moved from working directory to repository, the line endings are converted back into LF-only (Linux). This is a desirable trait and works seamlessly (no one knows its even happening) when Windows and Linux users share source files. This change follows in that spirit and makes it so AStyle does NOT try to edit all source files -- only the files that need formatting. I believe this follows the spirit of how it was meant to work.

  • code-format.py -- added some command-line argument options that allow AStyle to be limited to only certain directories if one already knows that's where it should look. This saves time -- important when time is precious. Simultaneously, giving it no arguments makes it run on all 4 directories as it did before. Normal users, or anyone running this from a script will see no change.

This enhancement was not discussed or asked for, but because it works so nicely on Windows when configured this way, it is submitted in hopes that those in charge will like it too, as it helps accommodate Windows users contribution to LVGL.

cc: @kisvegabor

Notes

  • Update the Documentation if needed. Changes documented inside .py and .cfg files.
  • Add Examples if relevant. n/a
  • Add Tests if applicable. n/a
  • If you added new options to lv_conf_template.h run lv_conf_internal_gen.py and update Kconfig. n/a
  • Run scripts/code-format.py (astyle v3.4.12 needs to installed by running cd scripts; ./install_astyle.sh) and follow the Code Conventions. n/a
  • Mark the Pull request as Draft while you are working on the first version, and mark is as Ready when it's ready for review. n/a
  • When changes were requested, re-request review to notify the maintainers. n/a
  • Help us to review this Pull Request! Anyone can approve or request changes.

- code-format.cfg doesn't work on Windows because it edits
  every single source file and changes the line endings.  Git,
  perceives this as a change, and makes Windows users have to
  RESET 672 files just in the ./src/ directory and I didn't count the
  number in the other directories.  Resetting files can be dangerous
  to work in progress.  Especially when it involves that many files.

  Rationale:  Git -- out of the box, with default configuration -- automatically
  stores source files in its repository with LF-only (Linux) line endings.
  On Windows, each time a file content moves from repository to
  working directory, its line endings are converted to the line endings
  native to the platform it is running on.  And each time file content
  is moved from working directory to repository, the line endings are
  converted back into LF-only (Linux).  This is a desirable trait and
  works very well when Windows and Linux users share source files.
  This change follows in that spirit and makes it so `AStyle` does NOT
  try to edit all source files -- only the files that need formatting.
  I believe this follows the spirit of how it was meant to work.

- code-format.py -- added some command-line argument options
  that allow `AStyle` to be limited to only certain directories if one
  already knows that's where it should look.  This saves time -- important
  when time is precious.  Simultaneously, giving it no arguments makes
  it run on all 4 directories as it did before.  Normal users, or anyone
  running this from a script will see no change.
@vwheeler63
Copy link
Contributor Author
vwheeler63 commented Nov 15, 2024

==============
Note: there is an alternate approach to this as well, because Python can reliably tell what platform it is running on and could use a different .cfg file if it is felt this is more appropriate (e.g. if forcing LF-only line endings is important for the Linux platform, i.e. if it is solving a problem I am unaware of).

cc: @kisvegabor

Copy link
Member
@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

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

Oh, I didn't how this Window-Linux magic is happening. Thank you! It makes sense.

For code formatting in use this pre-commit hook so for me only the changed file are formatted on every commit. So I never run the code formatter manually.

In light of that do we need the extra arguments to code-format.py?

@vwheeler63
Copy link
Contributor Author

In light of that do we need the extra arguments to code-format.py?

"Need" -- technically no. I found it useful on my system when I needed it to examine only one directory. So I offered it in case you liked it. I initially wanted to try to limit the number of source files I was having to reset under my local LVGL repository, but without the forced LF-only line endings, that problem is now solved, so for me it would only be a convenience. If you like I can re-submit without those changes. And also without the comments in .cfg file. I await your feedback. :-)

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