@@ -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+
678700if not get_option (' breaking_changes' )
679701 builtin_sources += ' builtin/pack-redundant.c'
680702endif
@@ -2040,6 +2062,70 @@ endif
20402062
20412063subdir (' contrib' )
20422064
2065+ exclude_from_check_headers = [
2066+ ' compat/' ,
2067+ ' unicode-width.h' ,
2068+ ]
2069+
2070+ if sha1_backend != ' openssl'
2071+ exclude_from_check_headers += ' sha1/openssl.h'
2072+ endif
2073+ if sha256_backend != ' openssl'
2074+ exclude_from_check_headers += ' sha256/openssl.h'
2075+ endif
2076+ if sha256_backend != ' nettle'
2077+ exclude_from_check_headers += ' sha256/nettle.h'
2078+ endif
2079+ if sha256_backend != ' gcrypt'
2080+ exclude_from_check_headers += ' sha256/gcrypt.h'
2081+ endif
2082+
2083+ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == ' gcc'
2084+ hco_targets = []
2085+ foreach h : headers_to_check
2086+ skip_header = false
2087+ foreach exclude : exclude_from_check_headers
2088+ if h.startswith(exclude)
2089+ skip_header = true
2090+ break
2091+ endif
2092+ endforeach
2093+
2094+ if skip_header
2095+ continue
2096+ endif
2097+
2098+ hcc = custom_target (
2099+ input : h,
2100+ output : h.underscorify() + ' cc' ,
2101+ command : [
2102+ shell,
2103+ ' -c' ,
2104+ ' echo \' #include "git-compat-util.h"\' > @OUTPUT@ && echo \' #include "' + h + ' "\' >> @OUTPUT@'
2105+ ]
2106+ )
2107+
2108+ hco = custom_target (
2109+ input : hcc,
2110+ output : fs.replace_suffix(h.underscorify(), ' .hco' ),
2111+ command : [
2112+ compiler.cmd_array(),
2113+ libgit_c_args,
2114+ ' -I' , meson .project_source_root(),
2115+ ' -I' , meson .project_source_root() / ' t/unit-tests' ,
2116+ ' -o' , ' /dev/null' ,
2117+ ' -c' , ' -xc' ,
2118+ ' @INPUT@'
2119+ ]
2120+ )
2121+ hco_targets += hco
2122+ endforeach
2123+
2124+ # TODO: deprecate 'hdr-check' in lieu of 'check-headers' in Git 2.51+
2125+ hdr_check = alias_target (' hdr-check' , hco_targets)
2126+ alias_target (' check-headers' , hdr_check)
2127+ endif
2128+
20432129foreach key, value : {
20442130 ' DIFF' : diff.full_path(),
20452131 ' GIT_SOURCE_DIR' : meson .project_source_root(),
0 commit comments