-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Check meson.build Format | ||
|
||
on: [push, pull_request] | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
format-meson: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install Meson | ||
run: pip install git+https://github.com/mesonbuild/meson | ||
|
||
- name: Format Checks | ||
run: python ./tools/run_meson_fmt.py --check |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
format or check all meson.build file in projects | ||
""" | ||
|
||
import sys | ||
import pathlib | ||
import subprocess | ||
from shutil import which | ||
from itertools import chain | ||
|
||
is_check = "--check" in sys.argv | ||
|
||
base_command = [which("meson"), "fmt", "--editor-config"] | ||
if is_check: | ||
base_command.append("--check-only") | ||
else: | ||
base_command.append("--inplace") | ||
|
||
project_root = pathlib.Path(__file__).parent.parent | ||
|
||
for meson_file in chain( | ||
[project_root.joinpath("meson.build")], | ||
project_root.glob("subprojects/packagefiles/**/meson.build"), | ||
): | ||
readable_filename = meson_file.relative_to(project_root).as_posix() | ||
print("processing:", readable_filename) | ||
try: | ||
subprocess.check_call(base_command + [str(meson_file)], cwd=str(project_root)) | ||
except subprocess.CalledProcessError as e: | ||
if is_check: | ||
print("{} is not formatted".format(readable_filename)) | ||
sys.exit(e.returncode) | ||
else: | ||
print("failed to format {}".format(readable_filename)) |