From 27d69ad622a2fd071a0fc56b1b51049811638fcd Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 13:32:15 +0100 Subject: [PATCH 1/7] build: Fix missing initializer field clang warnings ../client/pk-console.c:1719:9: warning: missing field 'short_name' initializer [-Wmissing-field-initializers] 1719 | { NULL} | ^ ../client/pk-monitor.c:331:9: warning: missing field 'short_name' initializer [-Wmissing-field-initializers] 331 | { NULL} | ^ G_OPTION_ENTRY_NULL was introduced in glib commit https://gitlab.gnome.org/GNOME/glib/-/commit/2e4524cd3, which is avaiable from 2.70. Since, 2.70 is quite old (release: 2021-09-17), it's fine to bump glib version than copying / maintaining the macro within PackageKit. --- client/pk-console.c | 2 +- client/pk-monitor.c | 2 +- contrib/gstreamer-plugin/pk-gstreamer-install.c | 2 +- lib/packagekit-glib2/pk-debug.c | 2 +- meson.build | 2 +- src/pk-direct.c | 2 +- src/pk-main.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/pk-console.c b/client/pk-console.c index bedb26f82a..ca9059802f 100644 --- a/client/pk-console.c +++ b/client/pk-console.c @@ -1716,7 +1716,7 @@ main (int argc, char *argv[]) { "allow-untrusted", '\0', 0, G_OPTION_ARG_NONE, &allow_untrusted, /* command line argument, do we ask questions */ _("Allow untrusted packages to be installed."), NULL }, - { NULL} + G_OPTION_ENTRY_NULL }; setlocale (LC_ALL, ""); diff --git a/client/pk-monitor.c b/client/pk-monitor.c index b768bcc680..05b6ee6f60 100644 --- a/client/pk-monitor.c +++ b/client/pk-monitor.c @@ -328,7 +328,7 @@ main (int argc, char *argv[]) const GOptionEntry options[] = { { "version", '\0', 0, G_OPTION_ARG_NONE, &program_version, _("Show the program version and exit"), NULL}, - { NULL} + G_OPTION_ENTRY_NULL }; setlocale (LC_ALL, ""); diff --git a/contrib/gstreamer-plugin/pk-gstreamer-install.c b/contrib/gstreamer-plugin/pk-gstreamer-install.c index f48ffebeb0..6e9ed12095 100644 --- a/contrib/gstreamer-plugin/pk-gstreamer-install.c +++ b/contrib/gstreamer-plugin/pk-gstreamer-install.c @@ -354,7 +354,7 @@ main (int argc, gchar **argv) { "interaction", '\0', 0, G_OPTION_ARG_STRING, &interaction, "Interaction mode specifying which UI elements should be shown", NULL }, { "startup-notification-id", '\0', 0, G_OPTION_ARG_STRING, &startup_id, "The startup notification ID for focus stealing prevention", NULL }, { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &codecs, "GStreamer install infos", NULL }, - { NULL } + G_OPTION_ENTRY_NULL }; gst_init (&argc, &argv); diff --git a/lib/packagekit-glib2/pk-debug.c b/lib/packagekit-glib2/pk-debug.c index 688eca10bb..3a4982299e 100644 --- a/lib/packagekit-glib2/pk-debug.c +++ b/lib/packagekit-glib2/pk-debug.c @@ -140,7 +140,7 @@ pk_debug_pre_parse_hook (GOptionContext *context, GOptionGroup *group, gpointer { "verbose", 'v', 0, G_OPTION_ARG_NONE, &_verbose, /* TRANSLATORS: turn on all debugging */ N_("Show debugging information for all files"), NULL }, - { NULL} + G_OPTION_ENTRY_NULL }; /* add main entry */ diff --git a/meson.build b/meson.build index bacf5d40a3..dc44e68a1c 100644 --- a/meson.build +++ b/meson.build @@ -11,7 +11,7 @@ pkg = import('pkgconfig') source_root = meson.project_source_root() -glib_dep = dependency('glib-2.0', version: '>=2.62') +glib_dep = dependency('glib-2.0', version: '>=2.70') gobject_dep = dependency('gobject-2.0') gio_dep = dependency('gio-2.0') gio_unix_dep = dependency('gio-unix-2.0', version: '>=2.16.1') diff --git a/src/pk-direct.c b/src/pk-direct.c index bc010221f5..23c36646a5 100644 --- a/src/pk-direct.c +++ b/src/pk-direct.c @@ -406,7 +406,7 @@ main (int argc, char *argv[]) { "backend", '\0', 0, G_OPTION_ARG_STRING, &backend_name, /* TRANSLATORS: a backend is the system package tool, e.g. dnf, apt */ _("Packaging backend to use, e.g. dummy"), NULL }, - { NULL } + G_OPTION_ENTRY_NULL }; setlocale (LC_ALL, ""); diff --git a/src/pk-main.c b/src/pk-main.c index 433ed11f2a..2ad334dedc 100644 --- a/src/pk-main.c +++ b/src/pk-main.c @@ -130,7 +130,7 @@ main (int argc, char *argv[]) { "keep-environment", '\0', 0, G_OPTION_ARG_NONE, &keep_environment, /* TRANSLATORS: don't unset environment variables, used for debugging */ _("Don't clear environment on startup"), NULL }, - { NULL } + G_OPTION_ENTRY_NULL }; setlocale (LC_ALL, ""); From c39feaf331fb2c7997faa8278cf123686423d6d1 Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 14:01:04 +0100 Subject: [PATCH 2/7] build: Fix 'set but not used' clang warnings ../lib/packagekit-glib2/pk-bitfield.c:52:8: warning: variable 'i' set but not used [-Wunused-but-set-variable] 52 | guint i; | ^ ../lib/packagekit-glib2/pk-bitfield.c:93:8: warning: variable 'i' set but not used [-Wunused-but-set-variable] 93 | guint i; | ../src/pk-scheduler.c:858:8: warning: variable 'running' set but not used [-Wunused-but-set-variable] 858 | guint running = 0; | ^ ../src/pk-scheduler.c:860:8: warning: variable 'no_commit' set but not used [-Wunused-but-set-variable] 860 | guint no_commit = 0; | ^ --- lib/packagekit-glib2/pk-bitfield.c | 6 ++---- src/pk-backend-spawn.c | 3 +-- src/pk-scheduler.c | 6 ------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/packagekit-glib2/pk-bitfield.c b/lib/packagekit-glib2/pk-bitfield.c index 3012f26b66..6e1d1ac5d2 100644 --- a/lib/packagekit-glib2/pk-bitfield.c +++ b/lib/packagekit-glib2/pk-bitfield.c @@ -49,7 +49,6 @@ gint pk_bitfield_contain_priority (PkBitfield values, gint value, ...) { va_list args; - guint i; gint value_temp; gint retval = -1; @@ -59,7 +58,7 @@ pk_bitfield_contain_priority (PkBitfield values, gint value, ...) /* process the valist */ va_start (args, value); - for (i = 0;; i++) { + while (TRUE) { value_temp = va_arg (args, gint); /* do we have this one? */ if (pk_bitfield_contain (values, value_temp)) { @@ -90,7 +89,6 @@ PkBitfield pk_bitfield_from_enums (gint value, ...) { va_list args; - guint i; gint value_temp; PkBitfield values; @@ -99,7 +97,7 @@ pk_bitfield_from_enums (gint value, ...) /* process the valist */ va_start (args, value); - for (i = 0;; i++) { + while (TRUE) { value_temp = va_arg (args, gint); if (value_temp == -1) break; diff --git a/src/pk-backend-spawn.c b/src/pk-backend-spawn.c index 5bbaa160a7..7f81561ed3 100644 --- a/src/pk-backend-spawn.c +++ b/src/pk-backend-spawn.c @@ -806,7 +806,6 @@ pk_backend_spawn_va_list_to_argv (const gchar *string_first, va_list *args) { GPtrArray *ptr_array; gchar *value_temp; - guint i; g_return_val_if_fail (args != NULL, NULL); g_return_val_if_fail (string_first != NULL, NULL); @@ -823,7 +822,7 @@ pk_backend_spawn_va_list_to_argv (const gchar *string_first, va_list *args) g_ptr_array_add (ptr_array, g_strdup (string_first)); /* process all the va_list entries */ - for (i = 0;; i++) { + while (TRUE) { value_temp = va_arg (*args, gchar *); if (value_temp == NULL) break; diff --git a/src/pk-scheduler.c b/src/pk-scheduler.c index 42e137bc7e..d31c8b3086 100644 --- a/src/pk-scheduler.c +++ b/src/pk-scheduler.c @@ -855,9 +855,7 @@ pk_scheduler_get_state (PkScheduler *scheduler) { guint i; guint length; - guint running = 0; guint waiting = 0; - guint no_commit = 0; PkRoleEnum role; PkSchedulerItem *item; PkTransactionState state; @@ -872,12 +870,8 @@ pk_scheduler_get_state (PkScheduler *scheduler) for (i = 0; i < length; i++) { item = (PkSchedulerItem *) g_ptr_array_index (scheduler->priv->array, i); state = pk_transaction_get_state (item->transaction); - if (state == PK_TRANSACTION_STATE_RUNNING) - running++; if (state == PK_TRANSACTION_STATE_READY) waiting++; - if (state == PK_TRANSACTION_STATE_NEW) - no_commit++; role = pk_transaction_get_role (item->transaction); g_string_append_printf (string, "%0i\t%s\t%s\tstate[%s] " From c49f8390cb638f5f250ed04be603a01b6f85bb57 Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 14:07:00 +0100 Subject: [PATCH 3/7] meson: Fix unknown warning option '-Wclobbered' in clang [231/250] Compiling C object client/pkmon.p/pk-monitor.c.o warning: unknown warning option '-Wclobbered' [-Wunknown-warning-option] 1 warning generated. [238/250] Compiling C object client/pkcon.p/pk-console.c.o warning: unknown warning option '-Wclobbered' [-Wunknown-warning-option] 1 warning generated. [246/250] Compiling C object contrib/gstreamer-plugin/pk-gstreamer-install.p/pk-gstreamer-install.c.o warning: unknown warning option '-Wclobbered' [-Wunknown-warning-option] 1 warning generated. --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index dc44e68a1c..2dc81830e9 100644 --- a/meson.build +++ b/meson.build @@ -104,7 +104,7 @@ package_locale_dir = join_paths(get_option('prefix'), get_option('datadir'), 'lo pk_plugin_dir = join_paths(get_option('prefix'), get_option('libdir'), 'packagekit-backend') # default compiler flags for C and C++ -add_project_arguments( +default_compiler_flags = [ '-Wcast-align', '-Wno-uninitialized', '-Werror=missing-declarations', @@ -132,7 +132,14 @@ add_project_arguments( '-Werror=missing-declarations', '-Werror=pointer-arith', '-Werror=empty-body', +] + +supported_compiler_flags = cc.get_supported_arguments(default_compiler_flags, checked: 'warn') +# if a common compiler flag is not supported by 'c', then it should +# apply to c++ too. So, we don't need a double check here. +add_project_arguments( + supported_compiler_flags, language: ['c', 'cpp'] ) From 57ed1f57a2d2f395e6f6ba05a0088ef9bf9e8a82 Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 14:57:14 +0100 Subject: [PATCH 4/7] meson: Rework compiler flag support check to handle -Werror=format-security flag This should fix the following incorrect meson error: Compiler for C supports arguments -Werror=format-security: NO Refer: https://github.com/mesonbuild/meson/issues/5790 Follow up to previous commit 6133d81d8. --- meson.build | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 2dc81830e9..66373f14cc 100644 --- a/meson.build +++ b/meson.build @@ -128,13 +128,19 @@ default_compiler_flags = [ '-Wno-error=unused-parameter', '-Werror=misleading-indentation', '-Werror=return-type', - '-Werror=format-security', + ['-Werror=format-security', '-Wformat'], '-Werror=missing-declarations', '-Werror=pointer-arith', '-Werror=empty-body', ] -supported_compiler_flags = cc.get_supported_arguments(default_compiler_flags, checked: 'warn') +supported_compiler_flags = [] +foreach arg: default_compiler_flags + if cc.has_multi_arguments(arg) + supported_compiler_flags += arg + endif +endforeach + # if a common compiler flag is not supported by 'c', then it should # apply to c++ too. So, we don't need a double check here. From b4e51534b2fb88fc72e37b363ea6e78d02acb876 Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 15:04:16 +0100 Subject: [PATCH 5/7] meson: Remove duplicate -Werror=format-security flag Already part of default compiler flags. --- meson.build | 1 - 1 file changed, 1 deletion(-) diff --git a/meson.build b/meson.build index 66373f14cc..fef7275348 100644 --- a/meson.build +++ b/meson.build @@ -189,7 +189,6 @@ if get_option('maintainer') '-Wfloat-equal', '-Winline', '-Wno-error=comment', - '-Werror=format-security', language: ['c', 'cpp'] ) From 5e3d1d8da78f6510cca3f9bd0aa5fbd8384ff076 Mon Sep 17 00:00:00 2001 From: sid Date: Wed, 16 Apr 2025 14:21:53 +0100 Subject: [PATCH 6/7] meson: add support check for maintainer compiler flags --- meson.build | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/meson.build b/meson.build index fef7275348..6edfbc03cf 100644 --- a/meson.build +++ b/meson.build @@ -177,20 +177,25 @@ add_project_arguments( # maintainer mode is even stricter if get_option('maintainer') - add_project_arguments( - '-Werror', - '-Wall', - '-Wextra', - '-Wcast-align', - '-Wno-uninitialized', - '-Wempty-body', - '-Winit-self', - '-Wnull-dereference', - '-Wfloat-equal', - '-Winline', - '-Wno-error=comment', - - language: ['c', 'cpp'] + maintainer_compiler_flags = [ + '-Werror', + '-Wall', + '-Wextra', + '-Wcast-align', + '-Wno-uninitialized', + '-Wempty-body', + '-Winit-self', + '-Wnull-dereference', + '-Wfloat-equal', + '-Winline', + '-Wno-error=comment', + ] + + supported_maintainer_flags = cc.get_supported_arguments(maintainer_compiler_flags, checked: 'warn') + + add_project_arguments( + supported_maintainer_flags, + language: ['c', 'cpp'] ) endif From eb4c5c326d30b24bccc14156907b8e1996367347 Mon Sep 17 00:00:00 2001 From: sid Date: Thu, 17 Apr 2025 07:15:31 +0100 Subject: [PATCH 7/7] meson: Move broader warning flags ahead of smaller ones for clang GCC works fine either ways, but clang gives '-Wunused-parameter` warnings when `-Wextra` is after '-Wno-unused-parameter' in command line. ../client/pk-console.c:485:46: warning: unused parameter 'data' [-Wunused-parameter] 485 | pk_console_files_cb (PkFiles *item, gpointer data) | ^ ../client/pk-console.c:833:41: warning: unused parameter 'object' [-Wunused-parameter] 833 | pk_console_client_finished_cb (GObject *object, GAsyncResult *res, gpointer data) | ^ ../client/pk-console.c:845:39: warning: unused parameter 'object' [-Wunused-parameter] 845 | pk_console_task_finished_cb (GObject *object, GAsyncResult *res, gpointer data) | ^ --- meson.build | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/meson.build b/meson.build index 6edfbc03cf..97a5f4e0e8 100644 --- a/meson.build +++ b/meson.build @@ -103,6 +103,30 @@ package_data_dir = get_option('datadir') package_locale_dir = join_paths(get_option('prefix'), get_option('datadir'), 'locale') pk_plugin_dir = join_paths(get_option('prefix'), get_option('libdir'), 'packagekit-backend') +# maintainer mode is even stricter +if get_option('maintainer') + maintainer_compiler_flags = [ + '-Werror', + '-Wall', + '-Wextra', + '-Wcast-align', + '-Wno-uninitialized', + '-Wempty-body', + '-Winit-self', + '-Wnull-dereference', + '-Wfloat-equal', + '-Winline', + '-Wno-error=comment', + ] + + supported_maintainer_flags = cc.get_supported_arguments(maintainer_compiler_flags, checked: 'warn') + + add_project_arguments( + supported_maintainer_flags, + language: ['c', 'cpp'] + ) +endif + # default compiler flags for C and C++ default_compiler_flags = [ '-Wcast-align', @@ -175,30 +199,6 @@ add_project_arguments( language: 'cpp' ) -# maintainer mode is even stricter -if get_option('maintainer') - maintainer_compiler_flags = [ - '-Werror', - '-Wall', - '-Wextra', - '-Wcast-align', - '-Wno-uninitialized', - '-Wempty-body', - '-Winit-self', - '-Wnull-dereference', - '-Wfloat-equal', - '-Winline', - '-Wno-error=comment', - ] - - supported_maintainer_flags = cc.get_supported_arguments(maintainer_compiler_flags, checked: 'warn') - - add_project_arguments( - supported_maintainer_flags, - language: ['c', 'cpp'] - ) -endif - subdir('po') subdir('policy') subdir('etc')