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: add script that uses the clang-format executable to format all project files #817

Closed
wants to merge 6 commits into from

Conversation

pixelcaliber
Copy link
Contributor

#614 This PR is to add format_project.py script that uses the clang-format executable to format all project files according to the provided .clang-format configuration. It does the following actions:

  • Recursively searches for C++ files in a specified directory
  • Applies clang-format to each file using the provided configuration
  • Reports the formatting progress and any errors encountered

Prerequisites

  1. Python 3.x installed on your system
  2. clang-format executable installed
  3. Make sure to have the .clang-format configuration file present

Installing clang-format

On macOS:

brew install clang-format

On Ubuntu/Debian:

sudo apt-get install clang-format

On Windows:

  1. Download LLVM from https://releases.llvm.org/download.html
  2. Run the installer, ensuring clang-format is selected for installation

Usage

Basic Usage

python format_project.py /project/path

Advanced Usage

python format_project.py /project/path --clang-format /clang-format/path --config /.clang-format/path --extensions .cpp .hpp .h

  • The "clang-format path" should be the location of the clang-format executable on your system.

Command-line Arguments

  • -h or --help to view usage and see options
  • directory (required): The root directory of your project to search for files
  • --clang-format (optional): Path to the clang-format executable (default: "clang-format")
  • --config (optional): Path to the .clang-format configuration file (default: ".clang-format")
  • --extensions (optional): File extensions to format (default: .cpp .hpp .h .c)

How you can determine clang-format path:

  • If clang-format is in your system's PATH, you don't need to specify the full path. You can simply use "clang-format" as the argument, which is the default in the script.
  • If clang-format is not in your PATH, you'll need to provide the full path to the clang-format executable. The location depends on how you installed clang-format and your operating system.
    • Here are some common locations:
      • On macOS (if installed via Homebrew): /usr/local/bin/clang-format or /opt/homebrew/bin/clang-format
      • On Linux: /usr/bin/clang-format
      • On Windows: C:\Program Files\LLVM\bin\clang-format.exe
    • To find the path:
      • On macOS or Linux, you can use the which command: which clang-format
      • On Windows, you can use the where command: where clang-format

@pixelcaliber pixelcaliber changed the title Feature: Add script that uses the clang-format executable to format all project files feat: add script that uses the clang-format executable to format all project files Jul 16, 2024
Copy link
Owner

@cieslarmichal cieslarmichal left a comment

Choose a reason for hiding this comment

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

Please change to bash script and just run something like clang-format src/**/*.cpp src/**/*.h include/**/*.h -i -style=file

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