Merge branch 'kn/meson-hdr-check'

Add an equivalent to "make hdr-check" target to meson based builds.

* kn/meson-hdr-check:
  makefile/meson: add 'check-headers' as alias for 'hdr-check'
  meson: add support for 'hdr-check'
  meson: rename 'third_party_sources' to 'third_party_excludes'
  meson: move headers definition from 'contrib/coccinelle'
  coccinelle: meson: rename variables to be more specific
  ci/github: install git before checking out the repository
maint
Junio C Hamano 2025-05-05 14:56:25 -07:00
commit 791db2c7ba
5 changed files with 112 additions and 25 deletions

View File

@ -415,6 +415,20 @@ jobs:
- name: prepare libc6 for actions
if: matrix.vector.jobname == 'linux32'
run: apt -q update && apt -q -y install libc6-amd64 lib64stdc++6
- name: install git in container
run: |
if command -v git
then
: # nothing to do
elif command -v apk
then
apk add --update git
elif command -v dnf
then
dnf -yq update && dnf -yq install git
else
apt-get -q update && apt-get -q -y install git
fi
- uses: actions/checkout@v4
- run: ci/install-dependencies.sh
- run: useradd builder --create-home

View File

@ -3334,8 +3334,10 @@ HCC = $(HCO:hco=hcc)
$(HCO): %.hco: %.hcc $(GENERATED_H) FORCE
$(QUIET_HDR)$(CC) $(ALL_CFLAGS) -o /dev/null -c -xc $<

.PHONY: hdr-check $(HCO)
# TODO: deprecate 'hdr-check' in lieu of 'check-headers' in Git 2.51+
.PHONY: hdr-check check-headers $(HCO)
hdr-check: $(HCO)
check-headers: hdr-check

.PHONY: style
style:

View File

@ -26,7 +26,7 @@ then
exit 1
fi

make hdr-check ||
make check-headers ||
exit 1

make check-pot

View File

@ -8,21 +8,6 @@ if not spatch.found()
subdir_done()
endif

third_party_sources = [
':!contrib',
':!compat/inet_ntop.c',
':!compat/inet_pton.c',
':!compat/nedmalloc',
':!compat/obstack.*',
':!compat/poll',
':!compat/regex',
':!sha1collisiondetection',
':!sha1dc',
':!t/unit-tests/clar',
':!t/unit-tests/clar',
':!t/t[0-9][0-9][0-9][0-9]*',
]

rules = [
'array.cocci',
'commit.cocci',
@ -55,18 +40,18 @@ concatenated_rules = custom_target(
capture: true,
)

sources = [ ]
foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.c', third_party_sources, check: true).stdout().split()
sources += source
coccinelle_sources = []
foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.c', third_party_excludes, check: true).stdout().split()
coccinelle_sources += source
endforeach

headers = [ ]
foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_sources, check: true).stdout().split()
headers += meson.project_source_root() / header
coccinelle_headers = []
foreach header : headers_to_check
coccinelle_headers += meson.project_source_root() / header
endforeach

patches = [ ]
foreach source : sources
foreach source : coccinelle_sources
patches += custom_target(
command: [
spatch,
@ -78,7 +63,7 @@ foreach source : sources
input: meson.project_source_root() / source,
output: source.underscorify() + '.patch',
capture: true,
depend_files: headers,
depend_files: coccinelle_headers,
)
endforeach


View File

@ -675,6 +675,28 @@ builtin_sources = [
'builtin/write-tree.c',
]

third_party_excludes = [
':!contrib',
':!compat/inet_ntop.c',
':!compat/inet_pton.c',
':!compat/nedmalloc',
':!compat/obstack.*',
':!compat/poll',
':!compat/regex',
':!sha1collisiondetection',
':!sha1dc',
':!t/unit-tests/clar',
':!t/t[0-9][0-9][0-9][0-9]*',
':!xdiff',
]

headers_to_check = []
if git.found() and fs.exists(meson.project_source_root() / '.git')
foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: true).stdout().split()
headers_to_check += header
endforeach
endif

if not get_option('breaking_changes')
builtin_sources += 'builtin/pack-redundant.c'
endif
@ -2019,6 +2041,70 @@ endif

subdir('contrib')

exclude_from_check_headers = [
'compat/',
'unicode-width.h',
]

if sha1_backend != 'openssl'
exclude_from_check_headers += 'sha1/openssl.h'
endif
if sha256_backend != 'openssl'
exclude_from_check_headers += 'sha256/openssl.h'
endif
if sha256_backend != 'nettle'
exclude_from_check_headers += 'sha256/nettle.h'
endif
if sha256_backend != 'gcrypt'
exclude_from_check_headers += 'sha256/gcrypt.h'
endif

if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
hco_targets = []
foreach h : headers_to_check
skip_header = false
foreach exclude : exclude_from_check_headers
if h.startswith(exclude)
skip_header = true
break
endif
endforeach

if skip_header
continue
endif

hcc = custom_target(
input: h,
output: h.underscorify() + 'cc',
command: [
shell,
'-c',
'echo \'#include "git-compat-util.h"\' > @OUTPUT@ && echo \'#include "' + h + '"\' >> @OUTPUT@'
]
)

hco = custom_target(
input: hcc,
output: fs.replace_suffix(h.underscorify(), '.hco'),
command: [
compiler.cmd_array(),
libgit_c_args,
'-I', meson.project_source_root(),
'-I', meson.project_source_root() / 't/unit-tests',
'-o', '/dev/null',
'-c', '-xc',
'@INPUT@'
]
)
hco_targets += hco
endforeach

# TODO: deprecate 'hdr-check' in lieu of 'check-headers' in Git 2.51+
hdr_check = alias_target('hdr-check', hco_targets)
alias_target('check-headers', hdr_check)
endif

foreach key, value : {
'DIFF': diff.full_path(),
'GIT_SOURCE_DIR': meson.project_source_root(),