-
Notifications
You must be signed in to change notification settings - Fork 115
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
ESP Code + Repo Formatter π©βπ» #242
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jzuckerman
pushed a commit
that referenced
this pull request
Dec 19, 2024
jzuckerman
pushed a commit
that referenced
this pull request
Dec 20, 2024
jzuckerman
pushed a commit
that referenced
this pull request
Dec 20, 2024
jzuckerman
pushed a commit
that referenced
this pull request
Dec 22, 2024
jzuckerman
pushed a commit
that referenced
this pull request
Dec 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ESP Code + Repo Formatter π©βπ»
Overview
This pull request includes two scripts used to automatically format source files in the ESP repository, and format files that have been modified in Git (format_repo.sh and format.sh, accordingly).
The
format_repo.sh
script applies standardized formatting rules to various file types, such as C, C++, VHDL, Verilog, and Python, using open-source formatting tools. It recursively traverses directories to format files, excluding submodules, with a few exceptions.The
format.sh
script applies the same formatting tools to determine if any files have been modified in the ESP git repo (checks the git diff), and help users find formatting issues in their code, and format files in-place.The
format_repo.sh
script should only be run once to format the entire repository, and create a "clean" starting point for the repo. Thenformat.sh
can be used in the future to maintain the organization as contributions are made.Requirements
Ensure the following tools are installed and available in the system's PATH:
clang-format-10
verible-verilog-format
vsg
autopep8 (Python)
I have provided a script
install.sh
(script location:utils/scripts/format/tools/install.sh
). Run it as./install.sh
to install the necessary tools before proceeding. If an error occurs, and the tools are not installed correctly, the formatting scripts will display an error message.Sample error message
Functionality:
format_repo.sh
The script:
Script Location
utils/scripts/format/format_repo.sh
Usage
Run the script with
--help
or-h
to learn more about its usage, ie.format_repo.sh --help
.Supported File Types
The following file types are supported for automatic formatting:
.c
,.h
,.cpp
,.hpp
).py
).vhd
).v
, .sv
)Note on submodules (format_repo.sh)
The
format_repo.sh
script skips formatting for most Git submodules (.gitmodules), with the exception of the following directories:rtl/caches/esp-caches/*
rtl/caches/spandex-caches/*
accelerators/stratus_hls/common/inc/*
Any other submodules will be ignored during the formatting process to prevent unintended modifications.
Functionality:
format.sh
The
format.sh
script is more targeted thanformat_repo.sh
. It checks whether any files have been modified in git and either reports formatting issues or applies formatting in place. The script is typically run in two contexts:The script:
Script Location
utils/scripts/format/format.sh
Usage
Run the script with
--help
or-h
to learn more about its usage, ie.format.sh --help
.Supported file types
Each file type is formatted using the following tools:
clang-format-10
autopep8
vsg
(VHDL Style Guide)verible-verilog-format
GitHub Actions Integration
The GitHub Actions pipeline is already set up as defined in
.github/workflows/format_check.yaml
. This pipeline will create an instance of a Docker container with the ubuntu18-small image and run theinstall.sh
script to install all the necessary tools. Then, it will run the formatting check script for all files in "GitHub Actions" mode (-g
)format.sh -g -ca
to check that all pushed files todev
ormaster
are formatted. The pipeline fails if there are errors.Pre-push Hook
Users can set up a Git Pre-Push hook locally to ensure that all code pushed to a remote branch follows the formatting expectations. Simply, navigate to
.githooks
directory, and run the./setup.sh
script. This will create a pre-push hook. It can also be done automatically as part of Dockerfile in the future.