From 017183e75c7a633dedabdbf57aa1ac80ee955f93 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Wed, 18 Oct 2023 21:40:36 -0700 Subject: [PATCH v4 3/4] WIP: meson: nitpick mode + test checking indentation Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch: --- meson.build | 20 +++++++++++++++++--- meson_options.txt | 3 +++ .cirrus.tasks.yml | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 492ce9a48b1..854b7ecf56c 100644 --- a/meson.build +++ b/meson.build @@ -44,6 +44,7 @@ cc = meson.get_compiler('c') not_found_dep = dependency('', required: false) thread_dep = dependency('threads') auto_features = get_option('auto_features') +nitpick_mode = get_option('nitpick') @@ -3025,16 +3026,18 @@ run_target('install-test-files', # use a combination of a locally built and the source tree's typededefs.list # file (see src/tools/pgindent/meson.build) for reindenting. That ensures # newly added typedefs are indented correctly. -indent_base_cmd = [perl, files('src/tools/pgindent/pgindent'), +indent_base_args = [files('src/tools/pgindent/pgindent'), '--indent', pg_bsd_indent.full_path(), - '--sourcetree=@SOURCE_ROOT@'] + '--sourcetree=@0@'.format(meson.current_source_dir())] indent_depend = [pg_bsd_indent] if typedefs_supported - indent_base_cmd += ['--typedefs', typedefs_merged.full_path()] + indent_base_args += ['--typedefs', typedefs_merged.full_path()] indent_depend += typedefs endif +indent_base_cmd = [perl, indent_base_args] + # Reindent the entire tree run_target('indent-tree', command: indent_base_cmd + ['.'], @@ -3364,6 +3367,17 @@ if meson.version().version_compare('>=0.57') endif +# If we were asked to be nitpicky, add a test that fails if sources aren't +# properly indented +if nitpick_mode + test('indent-check', + perl, args: [indent_base_args, '--silent-diff', '.'], + depends: indent_depend, + suite: 'source', + priority: 10) +endif + + ############################################################### # Pseudo targets diff --git a/meson_options.txt b/meson_options.txt index d2f95cfec36..90cb2177a44 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -52,6 +52,9 @@ option('atomics', type: 'boolean', value: true, option('spinlocks', type: 'boolean', value: true, description: 'Use spinlocks') +option('nitpick', type: 'boolean', value: false, + description: 'annoy the hell out of you, committers ought to enable this') + # Compilation options diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml index e137769850d..5dd29bed4cb 100644 --- a/.cirrus.tasks.yml +++ b/.cirrus.tasks.yml @@ -358,6 +358,7 @@ task: meson setup \ --buildtype=debug \ -Dcassert=true \ + -Dnitpick=true \ ${LINUX_MESON_FEATURES} \ -DPG_TEST_EXTRA="$PG_TEST_EXTRA" \ build -- 2.38.0