From a064b0be55f60b0b8281b4a6a38917eab4b9c50f Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:34 +0200 Subject: [PATCH 01/10] ci/github: install git before checking out the repository The GitHub's CI workflow uses 'actions/checkout@v4' to checkout the repository. This action defaults to using the GitHub REST API to obtain the repository if the `git` executable isn't available. The step to build Git in the GitHub workflow can be summarized as: ... - uses: actions/checkout@v4 #1 - run: ci/install-dependencies.sh #2 ... - run: sudo --preserve-env --set-home --user=builder ci/run-build-and-tests.sh #3 ... Step #1, clones the repository, since the `git` executable isn't present at this step, it uses GitHub's REST API to obtain a tar of the repository. Step #2, installs all dependencies, which includes the `git` executable. Step #3, sets up the build, which includes setting up meson in the meson job. At this point the `git` executable is present. This means while the `git` executable is present, the repository doesn't contain the '.git' folder. To keep both the CI's (GitLab and GitHub) behavior consistent and to ensure that the build is performed on a real-world scenario, install `git` before the repository is checked out. This ensures that 'actions/checkout@v4' will clone the repository instead of using a tarball. We also update the package cache while installing `git`, this is because some distros will fail to locate the package without updating the cache. Helped-by: Phillip Wood Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- .github/workflows/main.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37541f3d10d..e9112b3a64c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -414,6 +414,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 -- GitLab From 8e980b7f2501c4b9429394f7287757af7aef81ba Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:35 +0200 Subject: [PATCH 02/10] coccinelle: meson: rename variables to be more specific In Meson, included subdirs export their variables to top level Meson builds. In 'contrib/coccinelle/meson.build', we define two such variables `sources` and `headers`. While these variables are specific to the checks in the 'contrib/coccinelle/' directory, they also pollute the top level 'meson.build'. Rename them to be more specific, this ensures that they aren't mistakenly used in the upper levels and avoid variable name collisions. While here, change the empty list denotation to be consistent with other places. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- contrib/coccinelle/meson.build | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/coccinelle/meson.build b/contrib/coccinelle/meson.build index ea054c924f4..03ce52d7522 100644 --- a/contrib/coccinelle/meson.build +++ b/contrib/coccinelle/meson.build @@ -55,18 +55,18 @@ concatenated_rules = custom_target( capture: true, ) -sources = [ ] +coccinelle_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 += source endforeach -headers = [ ] +coccinelle_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 += meson.project_source_root() / header endforeach patches = [ ] -foreach source : sources +foreach source : coccinelle_sources patches += custom_target( command: [ spatch, @@ -78,7 +78,7 @@ foreach source : sources input: meson.project_source_root() / source, output: source.underscorify() + '.patch', capture: true, - depend_files: headers, + depend_files: coccinelle_headers, ) endforeach -- GitLab From 1597b6e86e3c13438a0e469b10048e73039e8023 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:36 +0200 Subject: [PATCH 03/10] meson: move headers definition from 'contrib/coccinelle' The Meson build for coccinelle static analysis lists all headers to analyse. Due to the way Meson exports variables between subdirs, this variable is also available in the root Meson build. An upcoming commit, will add a new check complimenting 'hdr-check' in the Makefile. This would require the list of headers. So move the 'coccinelle_headers' to the root Meson build and rename it to 'headers', remove the root path being appended to each header and retain that in the coccinelle Meson build since it is specific to the coccinelle build. Also move the 'third_party_sources' variable to the root Meson build since it is also a dependency for the 'headers' variable. This also makes it easier to understand as the variable is now propagated from the top level to the bottom. While 'headers_to_check' is only computed when we have a repository and the 'git' executable is present, the variable itself is exposed as an empty array. This allows dependencies in upcoming commits to simply check for length of the array and not worry about dependencies required to actually populate the array. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- contrib/coccinelle/meson.build | 17 +---------------- meson.build | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/contrib/coccinelle/meson.build b/contrib/coccinelle/meson.build index 03ce52d7522..4f07824402f 100644 --- a/contrib/coccinelle/meson.build +++ b/contrib/coccinelle/meson.build @@ -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', @@ -61,7 +46,7 @@ foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', endforeach coccinelle_headers = [] -foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_sources, check: true).stdout().split() +foreach header : headers_to_check coccinelle_headers += meson.project_source_root() / header endforeach diff --git a/meson.build b/meson.build index e98cfa4909f..e147ddff286 100644 --- a/meson.build +++ b/meson.build @@ -633,6 +633,28 @@ builtin_sources = [ 'builtin/write-tree.c', ] +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]*', +] + +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_sources, check: true).stdout().split() + headers_to_check += header + endforeach +endif + if not get_option('breaking_changes') builtin_sources += 'builtin/pack-redundant.c' endif -- GitLab From 7e873eb390204dbe55ec4101fb7ab737f5ae0bc6 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:37 +0200 Subject: [PATCH 04/10] meson: rename 'third_party_sources' to 'third_party_excludes' The 'third_party_sources' variable was moved to the root 'meson.build' file in the previous commit. The variable is actually used to exclude third party sources, so rename it accordingly to 'third_party_excludes' to avoid confusion. While here, remove a duplicate from the list. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- contrib/coccinelle/meson.build | 2 +- meson.build | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/contrib/coccinelle/meson.build b/contrib/coccinelle/meson.build index 4f07824402f..dc3f73c2e7b 100644 --- a/contrib/coccinelle/meson.build +++ b/contrib/coccinelle/meson.build @@ -41,7 +41,7 @@ concatenated_rules = custom_target( ) coccinelle_sources = [] -foreach source : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.c', third_party_sources, check: true).stdout().split() +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 diff --git a/meson.build b/meson.build index e147ddff286..4618804c7a1 100644 --- a/meson.build +++ b/meson.build @@ -633,7 +633,7 @@ builtin_sources = [ 'builtin/write-tree.c', ] -third_party_sources = [ +third_party_excludes = [ ':!contrib', ':!compat/inet_ntop.c', ':!compat/inet_pton.c', @@ -644,13 +644,12 @@ third_party_sources = [ ':!sha1collisiondetection', ':!sha1dc', ':!t/unit-tests/clar', - ':!t/unit-tests/clar', ':!t/t[0-9][0-9][0-9][0-9]*', ] 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_sources, check: true).stdout().split() + 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 -- GitLab From 02a132616ac69cd546c823c47afd60eab738792c Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:38 +0200 Subject: [PATCH 05/10] 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 Signed-off-by: Junio C Hamano --- meson.build | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/meson.build b/meson.build index 4618804c7a1..22fc65ec80b 100644 --- a/meson.build +++ b/meson.build @@ -645,6 +645,7 @@ third_party_excludes = [ ':!sha1dc', ':!t/unit-tests/clar', ':!t/t[0-9][0-9][0-9][0-9]*', + ':!xdiff', ] headers_to_check = [] @@ -1994,6 +1995,68 @@ 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 + + alias_target('hdr-check', hco_targets) +endif + foreach key, value : { 'DIFF': diff.full_path(), 'GIT_SOURCE_DIR': meson.project_source_root(), -- GitLab From 04a13ed8a7c07ef383f19adc16494ec481960bdb Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Wed, 23 Apr 2025 10:15:39 +0200 Subject: [PATCH 06/10] makefile/meson: add 'check-headers' as alias for 'hdr-check' The 'hdr-check' target in Meson and makefile is used to check if headers can be compiled individually. The naming however isn't readable as 'hdr' is not a common shortforme for 'header', neither is it an abbreviation. Let's introduce 'check-headers' as an alternative target for 'hdr-check' and add a `TODO` to deprecate the latter after 2 releases. Since this is an internal tool, we can use a shorter deprecation cycle. Change existing usage of 'hdr-check' in 'ci/run-static-analysis.sh' to also use 'check-headers'. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- Makefile | 4 +++- ci/run-static-analysis.sh | 2 +- meson.build | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ac32d2d0bda..961ee508be3 100644 --- a/Makefile +++ b/Makefile @@ -3326,8 +3326,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: diff --git a/ci/run-static-analysis.sh b/ci/run-static-analysis.sh index 0d51e5ce0e7..60c175a0943 100755 --- a/ci/run-static-analysis.sh +++ b/ci/run-static-analysis.sh @@ -26,7 +26,7 @@ then exit 1 fi -make hdr-check || +make check-headers || exit 1 make check-pot diff --git a/meson.build b/meson.build index 22fc65ec80b..569e3888fb2 100644 --- a/meson.build +++ b/meson.build @@ -2054,7 +2054,9 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc' hco_targets += hco endforeach - alias_target('hdr-check', hco_targets) + # 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 : { -- GitLab From 15d023c3f6e42aba60551371179754a6184de1c4 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 24 Apr 2025 15:14:59 +0200 Subject: [PATCH 07/10] EDITME: cover title for 505-wire-up-sparse # Describe the purpose of this series. The information you put here # will be used by the project maintainer to make a decision whether # your patches should be reviewed, and in what priority order. Please be # very detailed and link to any relevant discussions or sites that the # maintainer can review to better understand your proposed changes. If you # only have a single patch in your series, the contents of the cover # letter will be appended to the "under-the-cut" portion of the patch. # Lines starting with # will be removed from the cover letter. You can # use them to add notes or reminders to yourself. If you want to use # markdown headers in your cover letter, start the line with ">#". # You can add trailers to the cover letter. Any email addresses found in # these trailers will be added to the addresses specified/generated # during the b4 send stage. You can also run "b4 prep --auto-to-cc" to # auto-populate the To: and Cc: trailers based on the code being # modified. Signed-off-by: Karthik Nayak --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 1, "change-id": "20250424-505-wire-up-sparse-7cdad6f3227b", "prefixes": [] } } -- GitLab From d6c8f00c95278ac5c22bd058ae072d2ddbaeb7f3 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 24 Apr 2025 12:17:26 +0200 Subject: [PATCH 08/10] meson: extract out 'libgit_targets' and 'builtin_targets' Meson uses 'libgit_sources' to build the 'libgit' dependency and the 'builtin_sources' to build the 'git_builtin' executable. Both of these variables are arrays which contain both strings (path of the source) and objects (customer targets). Adding the 'sparse' static check in Meson, requires targetting only the source paths present in these variable's. Since Meson, doesn't allow type checking, we cannot filter out the strings from the array. So, let's simplify this by storing the strings in the existing variables and moving the custom targets to two new variables 'libgit_targets' and 'builtin_targets'. These variables are finally added to the existing variables as dependencies. Signed-off-by: Karthik Nayak --- meson.build | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index 954fd6fffcb..912bb47b360 100644 --- a/meson.build +++ b/meson.build @@ -531,7 +531,8 @@ libgit_sources = [ 'xdiff/xutils.c', ] -libgit_sources += custom_target( +libgit_targets = [] +libgit_targets += custom_target( input: 'command-list.txt', output: 'command-list.h', command: [shell, meson.current_source_dir() + '/generate-cmdlist.sh', meson.current_source_dir(), '@OUTPUT@'], @@ -692,7 +693,8 @@ if not get_option('breaking_changes') builtin_sources += 'builtin/pack-redundant.c' endif -builtin_sources += custom_target( +builtin_targets = [] +builtin_targets += custom_target( output: 'config-list.h', command: [ shell, @@ -703,7 +705,7 @@ builtin_sources += custom_target( env: script_environment, ) -builtin_sources += custom_target( +builtin_targets += custom_target( input: 'Documentation/githooks.adoc', output: 'hook-list.h', command: [ @@ -1646,11 +1648,11 @@ version_def_h = custom_target( depends: [git_version_file], env: version_gen_environment, ) -libgit_sources += version_def_h +libgit_targets += version_def_h libgit = declare_dependency( link_with: static_library('git', - sources: libgit_sources, + sources: libgit_sources + libgit_targets, c_args: libgit_c_args + [ '-DGIT_VERSION_H="' + version_def_h.full_path() + '"', ], @@ -1712,7 +1714,7 @@ bin_wrappers = [ ] test_dependencies = [ ] git_builtin = executable('git', - sources: builtin_sources + 'git.c', + sources: builtin_sources + builtin_targets + 'git.c', dependencies: [libgit_commonmain], install: true, install_dir: get_option('libexecdir') / 'git-core', -- GitLab From e8fe2cb25d153f568fc6fd2a87e922899b6ca45e Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 24 Apr 2025 13:49:06 +0200 Subject: [PATCH 09/10] makefile: remove SP_EXTRA_FLAGS entirely The SP_EXTRA_FLAGS were introduced to silence some of the issues when using 'make sparse'. These issues are no longer relevant and as such we can remove the variable and its usage entirely. Signed-off-by: Karthik Nayak --- Makefile | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index be666879d3e..053eae4f4de 100644 --- a/Makefile +++ b/Makefile @@ -1411,8 +1411,7 @@ ARFLAGS = rcs PTHREAD_CFLAGS = # For the 'sparse' target -SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__ -SP_EXTRA_FLAGS = +SPARSE_FLAGS ?= -std=gnu99 # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets SANITIZE_LEAK = @@ -2858,11 +2857,6 @@ gettext.sp gettext.s gettext.o: GIT-PREFIX gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \ -DGIT_LOCALE_PATH='"$(localedir_relative_SQ)"' -http-push.sp http.sp http-walker.sp remote-curl.sp imap-send.sp: SP_EXTRA_FLAGS += \ - -DCURL_DISABLE_TYPECHECK - -pack-revindex.sp: SP_EXTRA_FLAGS += -Wno-memcpy-max-count - ifdef NO_EXPAT http-walker.sp http-walker.s http-walker.o: EXTRA_CPPFLAGS = -DNO_EXPAT endif @@ -2875,7 +2869,6 @@ endif ifdef USE_NED_ALLOCATOR compat/nedmalloc/nedmalloc.sp compat/nedmalloc/nedmalloc.o: EXTRA_CPPFLAGS = \ -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -compat/nedmalloc/nedmalloc.sp: SP_EXTRA_FLAGS += -Wno-non-pointer-null endif headless-git.o: compat/win32/headless.c GIT-CFLAGS @@ -3300,7 +3293,7 @@ SP_OBJ = $(patsubst %.c,%.sp,$(SP_SRC)) $(SP_OBJ): %.sp: %.c %.o $(GENERATED_H) $(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) \ -Wsparse-error \ - $(SPARSE_FLAGS) $(SP_EXTRA_FLAGS) $< && \ + $(SPARSE_FLAGS) $< && \ >$@ .PHONY: sparse -- GitLab From 5cae559d0c628acaa7e88a3384fde0b58cde0ad8 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Thu, 24 Apr 2025 14:05:17 +0200 Subject: [PATCH 10/10] meson: add support for sparse The Makefile supports a target called 'sparse', which runs the sparse tooling against the sources files. Let's port this functionality to Meson, our new build system too. The implementation resembles that of the Makefile and provides the same check. Signed-off-by: Karthik Nayak --- meson.build | 36 ++++++++++++++++++++++++++++++++++++ meson_options.txt | 6 +++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 912bb47b360..afb10052bfc 100644 --- a/meson.build +++ b/meson.build @@ -235,6 +235,7 @@ git = find_program('git', dirs: program_path, native: true, required: false) sed = find_program('sed', dirs: program_path, native: true) shell = find_program('sh', dirs: program_path, native: true) tar = find_program('tar', dirs: program_path, native: true) +cgcc = find_program('cgcc', dirs: program_path, required: false, native: true) target_shell = find_program('sh', dirs: program_path, native: false) @@ -1115,6 +1116,8 @@ else endif libgit_dependencies += networking_dependencies +message('ndepend', '@0@'.format(networking_dependencies)) + foreach symbol : ['inet_ntop', 'inet_pton', 'strerror'] if not compiler.has_function(symbol, dependencies: networking_dependencies) libgit_c_args += '-DNO_' + symbol.to_upper() @@ -2100,6 +2103,39 @@ if headers_to_check.length() != 0 and compiler.get_argument_syntax() == 'gcc' alias_target('check-headers', hdr_check) endif +if cgcc.found() and meson.version().version_compare('>=1.5.0') + sparse_flags = get_option('sparse_flags') + sparse_targets = [] + sparse_dependencies = [] + + foreach dep : libgit_dependencies + message('dep', dep.name()) + message(dep.get_variable(default_value: '', pkgconfig: 'includeDir')) + endforeach + + foreach source : builtin_sources + libgit_sources + st = custom_target( + input: source, + output: fs.replace_suffix(source.underscorify(), '.sp'), + depends: [ git_builtin ], + command: [ + 'cgcc', + '-no-compile', + '-I', meson.project_source_root(), + '-I', meson.project_source_root() / 't/unit-tests', + '-I', meson.project_build_root(), + libgit_c_args, + '-Wsparse-error', + sparse_flags, + '@INPUT@' + ] + ) + sparse_targets += st + endforeach + + alias_target('sparse', sparse_targets) +endif + foreach key, value : { 'DIFF': diff.full_path(), 'GIT_SOURCE_DIR': meson.project_source_root(), diff --git a/meson_options.txt b/meson_options.txt index 78d172a7401..9ad88230283 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -100,9 +100,13 @@ option('default_help_format', type: 'combo', choices: ['man', 'html'], value: 'm option('docs_backend', type: 'combo', choices: ['asciidoc', 'asciidoctor', 'auto'], value: 'auto', description: 'Which backend to use to generate documentation.') -# Testing. +# Static checks option('coccinelle', type: 'feature', value: 'auto', description: 'Provide a coccicheck target that generates a Coccinelle patch.') +option('sparse_flags', type: 'array', value: ['-std=gnu99'], + description: 'Which flags to pass along to the sparse check.') + +# Testing. option('tests', type: 'boolean', value: true, description: 'Enable building tests. This requires Perl, but is separate from the "perl" option such that you can build tests without Perl features enabled.') option('test_output_directory', type: 'string', -- GitLab