From 71974d8c54852c6afd21e20aabe90916c2d9d60f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:18:59 -0700 Subject: [PATCH 01/10] meson: Add _BSD_SOURCE and _DEFAULT_SOURCE To avoid warnings about string functions like strdup which are otherwise undefined, but succeed at linking anyway when the C standard is c99. --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index 724ac27..2307f24 100644 --- a/meson.build +++ b/meson.build @@ -6,6 +6,11 @@ project('pkgconf', 'c', cc = meson.get_compiler('c') +add_project_arguments( + '-D_BSD_SOURCE', + '-D_DEFAULT_SOURCE', + language : 'c', +) cdata = configuration_data() From 40ec08594ec7097e22b6be01d15aa45851967a0e Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:20:29 -0700 Subject: [PATCH 02/10] meson: add warning for implicit-function-declarations This would be triggered without the previous addition of -D_BSD_SOURCE for strdup, among others --- meson.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meson.build b/meson.build index 2307f24..986b534 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,9 @@ cc = meson.get_compiler('c') add_project_arguments( '-D_BSD_SOURCE', '-D_DEFAULT_SOURCE', + cc.get_supported_arguments( + '-Wimplicit-function-declaration', + ), language : 'c', ) From 4a2c9c285fba19d432f004c4e0a247af1e8d86f0 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 28 Jul 2022 16:01:52 -0700 Subject: [PATCH 03/10] meson: use C99 as the standard autoconf uses either C99 or Gnu99. Meson does not provide a graceful way to select gnu99 if possible or c99 (though there are several proposals currently happening to get there), so I've selected c99 as the conservative default. Without this, the compiler uses whatever it's default happens to be, which may or may not work out correctly, and hides bugs from CI that are present with c99 as the default. --- meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 986b534..4278f1c 100644 --- a/meson.build +++ b/meson.build @@ -1,8 +1,9 @@ project('pkgconf', 'c', version : '1.8.0', license : 'ISC', - meson_version : '>=0.47') - + meson_version : '>=0.47', + default_options : ['c_std=c99'], +) cc = meson.get_compiler('c') From bf307c1d959d2854c0293bb91bf740fbe3c2d7c1 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:26:26 -0700 Subject: [PATCH 04/10] ci: set meson to build with -Werror This will help catch any new warnings added in CI. --- .github/workflows/test.yml | 4 ++-- .woodpecker.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af278fd..8ebe9f1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: - name: Build run: | - meson _build + meson _build -Dwerror=true meson compile -C _build - name: Run tests @@ -98,7 +98,7 @@ jobs: - name: Build run: | - meson _build + meson _build -Dwerror=true meson compile -C _build - name: Run tests diff --git a/.woodpecker.yml b/.woodpecker.yml index ea2f687..2304cf7 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -4,7 +4,7 @@ pipeline: commands: - apt-get update - apt-get install -y kyua atf-sh build-essential meson - - meson _build + - meson _build -Dwerror=true - meson compile -C _build - meson test -v -C _build when: @@ -30,7 +30,7 @@ pipeline: image: alpine commands: - apk add -U --no-cache kyua atf build-base meson - - meson _build + - meson _build -Dwerror=true - meson compile -C _build - meson test -v -C _build when: From 5ba74dec933d79f8411288ca64c535e602437b17 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:28:27 -0700 Subject: [PATCH 05/10] meson: use straight indexing instead of array.get() It's more terse, and we don't need the support of a fallback value. --- meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 4278f1c..382fa71 100644 --- a/meson.build +++ b/meson.build @@ -29,8 +29,8 @@ check_functions = [ ] foreach f : check_functions - if cc.has_function(f.get(1), prefix : '#define _BSD_SOURCE\n#include <' + f.get(2) + '>') and cc.has_header_symbol(f.get(2), f.get(1), prefix : '#define _BSD_SOURCE') - cdata.set(f.get(0), 1) + if cc.has_function(f[1], prefix : '#define _BSD_SOURCE\n#include <' + f[2] + '>') and cc.has_header_symbol(f[2], f[1], prefix : '#define _BSD_SOURCE') + cdata.set(f[0], 1) endif endforeach From f947af057fcba09d22dd55c0d41f9b774072d440 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:31:49 -0700 Subject: [PATCH 06/10] meson: use str.format for improved readability --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 382fa71..efa064a 100644 --- a/meson.build +++ b/meson.build @@ -29,7 +29,7 @@ check_functions = [ ] foreach f : check_functions - if cc.has_function(f[1], prefix : '#define _BSD_SOURCE\n#include <' + f[2] + '>') and cc.has_header_symbol(f[2], f[1], prefix : '#define _BSD_SOURCE') + if cc.has_function(f[1], prefix : '#define _BSD_SOURCE\n#include <@0@>'.format(f[2])) and cc.has_header_symbol(f[2], f[1], prefix : '#define _BSD_SOURCE') cdata.set(f[0], 1) endif endforeach From 1f993bc095bdd01c43cc4689cb88b844ed1b745b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:38:35 -0700 Subject: [PATCH 07/10] meson: use string methods to avoid repeating data Instead of writing `['HAVE_FOO_H', 'foo.h']`, use meson's string methods to just write `['foo.h']`, and let meson create `HAVE_FOO_H` for us. --- meson.build | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/meson.build b/meson.build index efa064a..ef7be6f 100644 --- a/meson.build +++ b/meson.build @@ -19,18 +19,18 @@ add_project_arguments( cdata = configuration_data() check_functions = [ - ['HAVE_STRLCAT', 'strlcat', 'string.h'], - ['HAVE_STRLCPY', 'strlcpy', 'string.h'], - ['HAVE_STRNDUP', 'strndup', 'string.h'], - ['HAVE_STRDUP', 'strdup', 'string.h'], - ['HAVE_STRNCASECMP', 'strncasecmp', 'strings.h'], - ['HAVE_STRCASECMP', 'strcasecmp', 'strings.h'], - ['HAVE_REALLOCARRAY', 'reallocarray', 'stdlib.h'], + ['strlcat', 'string.h'], + ['strlcpy', 'string.h'], + ['strndup', 'string.h'], + ['strdup', 'string.h'], + ['strncasecmp', 'strings.h'], + ['strcasecmp', 'strings.h'], + ['reallocarray', 'stdlib.h'], ] foreach f : check_functions - if cc.has_function(f[1], prefix : '#define _BSD_SOURCE\n#include <@0@>'.format(f[2])) and cc.has_header_symbol(f[2], f[1], prefix : '#define _BSD_SOURCE') - cdata.set(f[0], 1) + if cc.has_function(f[0], prefix : '#define _BSD_SOURCE\n#include <@0@>'.format(f[1])) and cc.has_header_symbol(f[1], f[0], prefix : '#define _BSD_SOURCE') + cdata.set('HAVE_@0@'.format(f[0].to_upper().underscorify()), 1) endif endforeach From 06fe2e23b041224849fd4d1c3e3d44bbf74b4c2b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:40:54 -0700 Subject: [PATCH 08/10] meson: use current_source_dir and current_build_dir instead of *_root The latter doesn't work correctly when being used as a subproject, as it returns the *absolute* root. So if pkgconf is being built as part of muon, then it will return muon's source root. current_source_dir, on the other hand returns the directory correctly whether being built as a subproject or superproject. --- meson.build | 7 +++---- tests/meson.build | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index ef7be6f..161c5ef 100644 --- a/meson.build +++ b/meson.build @@ -51,8 +51,8 @@ cdata.set_quoted('PERSONALITY_PATH', ':'.join(personality_path)) cdata.set_quoted('PACKAGE_NAME', meson.project_name()) cdata.set_quoted('PACKAGE_VERSION', meson.project_version()) cdata.set_quoted('PACKAGE_BUGREPORT', 'https://todo.sr.ht/~kaniini/pkgconf') -cdata.set('abs_top_srcdir', meson.source_root()) -cdata.set('abs_top_builddir', meson.build_root()) +cdata.set('abs_top_srcdir', meson.current_source_dir()) +cdata.set('abs_top_builddir', meson.current_build_dir()) subdir('libpkgconf') @@ -119,8 +119,7 @@ pkgconf_exe = executable('pkgconf', if get_option('tests') kyua_exe = find_program('kyua') atf_sh_exe = find_program('atf-sh') - test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile=' + join_paths(meson.build_root(), 'Kyuafile'), '--build-root=' + meson.build_root()]) - + test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile=' + join_paths(meson.current_build_dir(), 'Kyuafile'), '--build-root=' + meson.current_build_dir()]) configure_file(input : 'Kyuafile.in', output : 'Kyuafile', configuration : cdata) subdir('tests') diff --git a/tests/meson.build b/tests/meson.build index 1f21e04..beaf393 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -19,5 +19,5 @@ tests = [ # yuck foreach test : tests configure_file(input: test + '.sh', output: test, copy: true) - run_command('chmod', '755', join_paths(meson.build_root(), 'tests', test)) + run_command('chmod', '755', join_paths(meson.current_build_dir(), 'tests', test)) endforeach From c04097e4913bac46aa6fcc7095255b671ac67bac Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:48:05 -0700 Subject: [PATCH 09/10] meson: pass configured files idiomatically Instead of attempting to figure out what the paths will be, take the returned file object and pass that around, meson will then automatically figure out the correct paths. --- meson.build | 5 ++--- tests/meson.build | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 161c5ef..b77ee85 100644 --- a/meson.build +++ b/meson.build @@ -119,9 +119,8 @@ pkgconf_exe = executable('pkgconf', if get_option('tests') kyua_exe = find_program('kyua') atf_sh_exe = find_program('atf-sh') - test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile=' + join_paths(meson.current_build_dir(), 'Kyuafile'), '--build-root=' + meson.current_build_dir()]) - - configure_file(input : 'Kyuafile.in', output : 'Kyuafile', configuration : cdata) + kyuafile = configure_file(input : 'Kyuafile.in', output : 'Kyuafile', configuration : cdata) + test('kyua', kyua_exe, args : ['--config=none', 'test', '--kyuafile', kyuafile, '--build-root', meson.current_build_dir()]) subdir('tests') endif diff --git a/tests/meson.build b/tests/meson.build index beaf393..d68096b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -18,6 +18,6 @@ tests = [ # yuck foreach test : tests - configure_file(input: test + '.sh', output: test, copy: true) - run_command('chmod', '755', join_paths(meson.current_build_dir(), 'tests', test)) + test_file = configure_file(input: test + '.sh', output: test, copy: true) + run_command('chmod', '755', test_file) endforeach From dd779ad9f8cb54310be20b7cf5675f359ae418ed Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 29 Jul 2022 10:53:32 -0700 Subject: [PATCH 10/10] meson: add check to run_command Because we really should be checking that it succeeds, and because not setting it is deprecated. --- tests/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/meson.build b/tests/meson.build index d68096b..b331310 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -19,5 +19,5 @@ tests = [ # yuck foreach test : tests test_file = configure_file(input: test + '.sh', output: test, copy: true) - run_command('chmod', '755', test_file) + run_command('chmod', '755', test_file, check : true) endforeach