Skip to content

Commit 791db2c

Browse files
committed
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
2 parents cbda078 + 04a13ed commit 791db2c

File tree

5 files changed

+112
-25
lines changed

5 files changed

+112
-25
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,20 @@ jobs:
415415
- name: prepare libc6 for actions
416416
if: matrix.vector.jobname == 'linux32'
417417
run: apt -q update && apt -q -y install libc6-amd64 lib64stdc++6
418+
- name: install git in container
419+
run: |
420+
if command -v git
421+
then
422+
: # nothing to do
423+
elif command -v apk
424+
then
425+
apk add --update git
426+
elif command -v dnf
427+
then
428+
dnf -yq update && dnf -yq install git
429+
else
430+
apt-get -q update && apt-get -q -y install git
431+
fi
418432
- uses: actions/checkout@v4
419433
- run: ci/install-dependencies.sh
420434
- run: useradd builder --create-home

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,8 +3334,10 @@ HCC = $(HCO:hco=hcc)
33343334
$(HCO): %.hco: %.hcc $(GENERATED_H) FORCE
33353335
$(QUIET_HDR)$(CC) $(ALL_CFLAGS) -o /dev/null -c -xc $<
33363336

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

33403342
.PHONY: style
33413343
style:

ci/run-static-analysis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ then
2626
exit 1
2727
fi
2828

29-
make hdr-check ||
29+
make check-headers ||
3030
exit 1
3131

3232
make check-pot

contrib/coccinelle/meson.build

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ if not spatch.found()
88
subdir_done()
99
endif
1010

11-
third_party_sources = [
12-
':!contrib',
13-
':!compat/inet_ntop.c',
14-
':!compat/inet_pton.c',
15-
':!compat/nedmalloc',
16-
':!compat/obstack.*',
17-
':!compat/poll',
18-
':!compat/regex',
19-
':!sha1collisiondetection',
20-
':!sha1dc',
21-
':!t/unit-tests/clar',
22-
':!t/unit-tests/clar',
23-
':!t/t[0-9][0-9][0-9][0-9]*',
24-
]
25-
2611
rules = [
2712
'array.cocci',
2813
'commit.cocci',
@@ -55,18 +40,18 @@ concatenated_rules = custom_target(
5540
capture: true,
5641
)
5742

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

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

6853
patches = [ ]
69-
foreach source : sources
54+
foreach source : coccinelle_sources
7055
patches += custom_target(
7156
command: [
7257
spatch,
@@ -78,7 +63,7 @@ foreach source : sources
7863
input: meson.project_source_root() / source,
7964
output: source.underscorify() + '.patch',
8065
capture: true,
81-
depend_files: headers,
66+
depend_files: coccinelle_headers,
8267
)
8368
endforeach
8469

meson.build

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,28 @@ builtin_sources = [
675675
'builtin/write-tree.c',
676676
]
677677

678+
third_party_excludes = [
679+
':!contrib',
680+
':!compat/inet_ntop.c',
681+
':!compat/inet_pton.c',
682+
':!compat/nedmalloc',
683+
':!compat/obstack.*',
684+
':!compat/poll',
685+
':!compat/regex',
686+
':!sha1collisiondetection',
687+
':!sha1dc',
688+
':!t/unit-tests/clar',
689+
':!t/t[0-9][0-9][0-9][0-9]*',
690+
':!xdiff',
691+
]
692+
693+
headers_to_check = []
694+
if git.found() and fs.exists(meson.project_source_root() / '.git')
695+
foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: true).stdout().split()
696+
headers_to_check += header
697+
endforeach
698+
endif
699+
678700
if not get_option('breaking_changes')
679701
builtin_sources += 'builtin/pack-redundant.c'
680702
endif
@@ -2019,6 +2041,70 @@ endif
20192041

20202042
subdir('contrib')
20212043

2044+
exclude_from_check_headers = [
2045+
'compat/',
2046+
'unicode-width.h',
2047+
]
2048+
2049+
if sha1_backend != 'openssl'
2050+
exclude_from_check_headers += 'sha1/openssl.h'
2051+
endif
2052+
if sha256_backend != 'openssl'
2053+
exclude_from_check_headers += 'sha256/openssl.h'
2054+
endif
2055+
if sha256_backend != 'nettle'
2056+
exclude_from_check_headers += 'sha256/nettle.h'
2057+
endif
2058+
if sha256_backend != 'gcrypt'
2059+
exclude_from_check_headers += 'sha256/gcrypt.h'
2060+
endif
2061+
2062+
if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc'
2063+
hco_targets = []
2064+
foreach h : headers_to_check
2065+
skip_header = false
2066+
foreach exclude : exclude_from_check_headers
2067+
if h.startswith(exclude)
2068+
skip_header = true
2069+
break
2070+
endif
2071+
endforeach
2072+
2073+
if skip_header
2074+
continue
2075+
endif
2076+
2077+
hcc = custom_target(
2078+
input: h,
2079+
output: h.underscorify() + 'cc',
2080+
command: [
2081+
shell,
2082+
'-c',
2083+
'echo \'#include "git-compat-util.h"\' > @OUTPUT@ && echo \'#include "' + h + '"\' >> @OUTPUT@'
2084+
]
2085+
)
2086+
2087+
hco = custom_target(
2088+
input: hcc,
2089+
output: fs.replace_suffix(h.underscorify(), '.hco'),
2090+
command: [
2091+
compiler.cmd_array(),
2092+
libgit_c_args,
2093+
'-I', meson.project_source_root(),
2094+
'-I', meson.project_source_root() / 't/unit-tests',
2095+
'-o', '/dev/null',
2096+
'-c', '-xc',
2097+
'@INPUT@'
2098+
]
2099+
)
2100+
hco_targets += hco
2101+
endforeach
2102+
2103+
# TODO: deprecate 'hdr-check' in lieu of 'check-headers' in Git 2.51+
2104+
hdr_check = alias_target('hdr-check', hco_targets)
2105+
alias_target('check-headers', hdr_check)
2106+
endif
2107+
20222108
foreach key, value : {
20232109
'DIFF': diff.full_path(),
20242110
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)