Skip to content

Commit 7ec857c

Browse files
KarthikNayakgitster
authored andcommitted
meson: add support for 'headers-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. Let's avoid the abbreviation and name the target 'headers-check', which is easier to read. The implementation resembles that of the Makefile and provides the same check. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7863ba4 commit 7ec857c

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

meson.build

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ if git.found()
655655
endforeach
656656
endif
657657

658+
headers_generated = [
659+
'command-list.h',
660+
'config-list.h',
661+
'hook-list.h'
662+
]
663+
658664
if not get_option('breaking_changes')
659665
builtin_sources += 'builtin/pack-redundant.c'
660666
endif
@@ -1995,6 +2001,107 @@ endif
19952001

19962002
subdir('contrib')
19972003

2004+
headers_check_exclude = headers_generated
2005+
headers_check_exclude += [
2006+
'compat/apple-common-crypto.h',
2007+
'compat/bswap.h',
2008+
'compat/compiler.h',
2009+
'compat/disk.h',
2010+
'compat/fsmonitor/fsm-darwin-gcc.h',
2011+
'compat/fsmonitor/fsm-health.h',
2012+
'compat/fsmonitor/fsm-listen.h',
2013+
'compat/mingw.h',
2014+
'compat/msvc.h',
2015+
'compat/nedmalloc/malloc.c.h',
2016+
'compat/nedmalloc/nedmalloc.h',
2017+
'compat/nonblock.h',
2018+
'compat/obstack.h',
2019+
'compat/poll/poll.h',
2020+
'compat/precompose_utf8.h',
2021+
'compat/regex/regex.h',
2022+
'compat/regex/regex_internal.h',
2023+
'compat/sha1-chunked.h',
2024+
'compat/terminal.h',
2025+
'compat/vcbuild/include/sys/param.h',
2026+
'compat/vcbuild/include/sys/time.h',
2027+
'compat/vcbuild/include/sys/utime.h',
2028+
'compat/vcbuild/include/unistd.h',
2029+
'compat/vcbuild/include/utime.h',
2030+
'compat/win32.h',
2031+
'compat/win32/alloca.h',
2032+
'compat/win32/dirent.h',
2033+
'compat/win32/lazyload.h',
2034+
'compat/win32/path-utils.h',
2035+
'compat/win32/pthread.h',
2036+
'compat/win32/syslog.h',
2037+
'compat/zlib-compat.h',
2038+
't/unit-tests/clar/clar.h',
2039+
't/unit-tests/clar/clar/fixtures.h',
2040+
't/unit-tests/clar/clar/fs.h',
2041+
't/unit-tests/clar/clar/print.h',
2042+
't/unit-tests/clar/clar/sandbox.h',
2043+
't/unit-tests/clar/clar/summary.h',
2044+
't/unit-tests/clar/test/clar_test.h',
2045+
'unicode-width.h',
2046+
'xdiff/xdiff.h',
2047+
'xdiff/xdiffi.h',
2048+
'xdiff/xemit.h',
2049+
'xdiff/xinclude.h',
2050+
'xdiff/xmacros.h',
2051+
'xdiff/xprepare.h',
2052+
'xdiff/xtypes.h',
2053+
'xdiff/xutils.h',
2054+
]
2055+
2056+
if sha1_backend != 'openssl'
2057+
headers_check_exclude += 'sha1/openssl.h'
2058+
endif
2059+
if sha256_backend != 'openssl'
2060+
headers_check_exclude += 'sha256/openssl.h'
2061+
endif
2062+
if sha256_backend != 'nettle'
2063+
headers_check_exclude += 'sha256/nettle.h'
2064+
endif
2065+
if sha256_backend != 'gcrpyt'
2066+
headers_check_exclude += 'sha256/gcrypt.h'
2067+
endif
2068+
2069+
if headers.length() != 0 and compiler.get_argument_syntax() == 'gcc'
2070+
hco_targets = []
2071+
foreach h : headers
2072+
if headers_check_exclude.contains(h)
2073+
continue
2074+
endif
2075+
2076+
hcc = custom_target(
2077+
input: h,
2078+
output: h.underscorify() + 'cc',
2079+
command: [
2080+
shell,
2081+
'-c',
2082+
'echo \'#include "git-compat-util.h"\' > @OUTPUT@ && echo -n \'#include "' + h + '"\' >> @OUTPUT@'
2083+
]
2084+
)
2085+
2086+
hco = custom_target(
2087+
input: hcc,
2088+
output: h.underscorify().replace('.h', '.hco'),
2089+
command: [
2090+
compiler.cmd_array(),
2091+
libgit_c_args,
2092+
'-I', meson.project_source_root(),
2093+
'-I', meson.project_source_root() / 't/unit-tests',
2094+
'-o', '/dev/null',
2095+
'-c', '-xc',
2096+
'@INPUT@'
2097+
]
2098+
)
2099+
hco_targets += hco
2100+
endforeach
2101+
2102+
alias_target('headers-check', hco_targets)
2103+
endif
2104+
19982105
foreach key, value : {
19992106
'DIFF': diff.full_path(),
20002107
'GIT_SOURCE_DIR': meson.project_source_root(),

0 commit comments

Comments
 (0)