Skip to content

Commit

Permalink
Add meson.build format check in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Jan 4, 2025
1 parent a5c47ff commit f5d4f9a
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 7 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/format-meson.yml
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
2 changes: 2 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@
"fmt"
],
"versions": [
"11.1.1-1",
"11.0.2-1",
"11.0.1-1",
"10.2.0-2",
Expand Down Expand Up @@ -3474,6 +3475,7 @@
"sqlite3"
],
"versions": [
"3.47.2-2",
"3.47.2-1",
"3.47.1-1",
"3.47.0-1",
Expand Down
8 changes: 4 additions & 4 deletions subprojects/fmt.wrap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[wrap-file]
directory = fmt-11.0.2
source_url = https://github.com/fmtlib/fmt/archive/11.0.2.tar.gz
source_filename = fmt-11.0.2.tar.gz
source_hash = 6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f
directory = fmt-11.1.1
source_url = https://github.com/fmtlib/fmt/archive/11.1.1.tar.gz
source_filename = fmt-11.1.1.tar.gz
source_hash = 482eed9efbc98388dbaee5cb5f368be5eca4893456bb358c18b7ff71f835ae43
patch_directory = fmt

[provide]
Expand Down
2 changes: 1 addition & 1 deletion subprojects/packagefiles/fmt/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('fmt', 'cpp', version: '11.0.2', license: 'MIT WITH fmt-exception', default_options: ['cpp_std=c++14'])
project('fmt', 'cpp', version: '11.1.1', license: 'MIT WITH fmt-exception', default_options: ['cpp_std=c++14'])

fmt_private_cpp_args = []
fmt_interface_cpp_args = []
Expand Down
53 changes: 51 additions & 2 deletions subprojects/packagefiles/sqlite3/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,60 @@ endif
libm = cc.find_library('m', required: false)

sources = files('sqlite3.c')

sqlite_args = [
'-DSQLITE_ENABLE_COLUMN_METADATA',
'-DSQLITE_ENABLE_DBSTAT_VTAB',
'-DSQLITE_ENABLE_UNLOCK_NOTIFY',
'-DSQLITE_SECURE_DELETE',
]

if get_option('strict')
sqlite_args += [
'-DSQLITE_LIKE_DOESNT_MATCH_BLOBS',
'-DSQLITE_STRICT_SUBTYPE=1',
]
endif

extensions = [
['fts34', true, [
'-DSQLITE_ENABLE_FTS3',
'-DSQLITE_ENABLE_FTS3_PARENTHESIS',
'-DSQLITE_ENABLE_FTS3_TOKENIZER',
]],
['fts5', true, '-DSQLITE_ENABLE_FTS5'],
['geopoly', false, '-DSQLITE_ENABLE_GEOPOLY'],
['rbu', false, '-DSQLITE_ENABLE_RBU'],
['rtree', false, '-DSQLITE_ENABLE_RTREE'],
['session', false, [
'-DSQLITE_ENABLE_SESSION',
'-DSQLITE_ENABLE_PREUPDATE_HOOK'
]],
]
extension_default = get_option('all-extensions')
foreach extension : extensions
option = get_option(extension[0])
if option.auto()
if extension_default.auto()
enabled = extension[1]
else
enabled = extension_default.enabled()
endif
else
enabled = option.enabled()
endif
if enabled
sqlite_args += extension[2]
endif
endforeach

if host_machine.system() == 'windows'
sqlite_args = get_option('default_library') != 'static' ? ['-DSQLITE_API=__declspec(dllexport)'] : []
if get_option('default_library') != 'static'
sqlite_args += ['-DSQLITE_API=__declspec(dllexport)']
endif
libthreads = dependency('', required: false)
else
sqlite_args = ['-DSQLITE_API=__attribute__((visibility("default")))']
sqlite_args += ['-DSQLITE_API=__attribute__((visibility("default")))']
libthreads = dependency('threads')
endif

Expand Down
50 changes: 50 additions & 0 deletions subprojects/packagefiles/sqlite3/meson_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
option(
'strict',
description: 'Enable extra checks',
type: 'boolean',
value: true
)

# extensions
option(
'all-extensions',
description: 'Enable or disable all known extensions by default',
type: 'feature',
value: 'auto'
)
option(
'fts34',
description: 'Enable FTS3 and FTS4',
type: 'feature',
value: 'auto'
)
option(
'fts5',
description: 'Enable FTS5',
type: 'feature',
value: 'auto'
)
option(
'geopoly',
description: 'Enable Geopoly extension',
type: 'feature',
value: 'auto'
)
option(
'rbu',
description: 'Enable Resumable Bulk Update extension',
type: 'feature',
value: 'auto'
)
option(
'rtree',
description: 'Enable R*Tree index extension',
type: 'feature',
value: 'auto'
)
option(
'session',
description: 'Enable session extension',
type: 'feature',
value: 'auto'
)
66 changes: 66 additions & 0 deletions tools/run_meson_fmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
format or check all meson.build file in projects
arguments:
--check: do check without formatting
--dirty: do not format/check all files, only process files changed (only valid in git repo)
"""

import sys
import shlex
import pathlib
import subprocess
from shutil import which
from itertools import chain

is_check = "--check" in sys.argv
only_dirty = "--dirty" in sys.argv

meson = which("meson")
if not meson:
print("failed to find meson")
sys.exit(1)

base_command = [meson, "fmt", "--editor-config"]
if is_check:
base_command.append("--check-only")
else:
base_command.append("--inplace")

project_root = pathlib.Path(__file__).parent.parent


def get_file_list_from_git(cmd):
out = subprocess.check_output(
cmd,
cwd=str(project_root),
)
return [
project_root.joinpath(file)
for file in out.decode().splitlines()
if file.endswith("meson.build")
]


if only_dirty:
all_meson_files = get_file_list_from_git(shlex.split("git diff --name-only HEAD"))
else:
all_meson_files = sorted(
chain(
[project_root.joinpath("meson.build")],
project_root.glob("subprojects/packagefiles/**/meson.build"),
)
)

for i, meson_file in enumerate(all_meson_files):
readable_filename = meson_file.relative_to(project_root).as_posix()
print("processing {}/{}: {}".format(i + 1, len(all_meson_files), 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))

0 comments on commit f5d4f9a

Please sign in to comment.