Skip to content

Commit 40d6b90

Browse files
committed
meson: add support for 'hdr-check'
The Makefile supports a target called 'hdr-check', which checks if individual header files can be independently compiled. Let's port this functionality to Meson, our new build system too. The implementation resembles that of the Makefile and provides the same check. Since meson builds are out-of-tree, header dependencies are not automatically met. So unlike the Makefile version, we also need to add the required dependencies. Also add the 'xdiff/' dir to the list of 'third_party_sources' as those headers must be skipped from the checks too. This also skips the folder from the 'coccinelle' checks, this is okay, since this code is an external dependency. Signed-off-by: Karthik Nayak <[email protected]>
1 parent 6412f5a commit 40d6b90

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

meson.build

+63
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ third_party_excludes = [
645645
':!sha1dc',
646646
':!t/unit-tests/clar',
647647
':!t/t[0-9][0-9][0-9][0-9]*',
648+
':!xdiff',
648649
]
649650

650651
if git.found()
@@ -1994,6 +1995,68 @@ endif
19941995

19951996
subdir('contrib')
19961997

1998+
exclude_from_check_headers = [
1999+
'compat/',
2000+
'unicode-width.h',
2001+
]
2002+
2003+
if sha1_backend != 'openssl'
2004+
exclude_from_check_headers += 'sha1/openssl.h'
2005+
endif
2006+
if sha256_backend != 'openssl'
2007+
exclude_from_check_headers += 'sha256/openssl.h'
2008+
endif
2009+
if sha256_backend != 'nettle'
2010+
exclude_from_check_headers += 'sha256/nettle.h'
2011+
endif
2012+
if sha256_backend != 'gcrypt'
2013+
exclude_from_check_headers += 'sha256/gcrypt.h'
2014+
endif
2015+
2016+
if git.found() and compiler.get_argument_syntax() == 'gcc'
2017+
hco_targets = []
2018+
foreach h : headers_to_check
2019+
skip_header = false
2020+
foreach exclude : exclude_from_check_headers
2021+
if h.startswith(exclude)
2022+
skip_header = true
2023+
break
2024+
endif
2025+
endforeach
2026+
2027+
if skip_header
2028+
continue
2029+
endif
2030+
2031+
hcc = custom_target(
2032+
input: h,
2033+
output: h.underscorify() + 'cc',
2034+
command: [
2035+
shell,
2036+
'-c',
2037+
'echo \'#include "git-compat-util.h"\' > @OUTPUT@ && echo \'#include "' + h + '"\' >> @OUTPUT@'
2038+
]
2039+
)
2040+
2041+
hco = custom_target(
2042+
input: hcc,
2043+
output: fs.replace_suffix(h.underscorify(), '.hco'),
2044+
command: [
2045+
compiler.cmd_array(),
2046+
libgit_c_args,
2047+
'-I', meson.project_source_root(),
2048+
'-I', meson.project_source_root() / 't/unit-tests',
2049+
'-o', '/dev/null',
2050+
'-c', '-xc',
2051+
'@INPUT@'
2052+
]
2053+
)
2054+
hco_targets += hco
2055+
endforeach
2056+
2057+
alias_target('hdr-check', hco_targets)
2058+
endif
2059+
19972060
foreach key, value : {
19982061
'DIFF': diff.full_path(),
19992062
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)