css: Emit deprecation warnings only under debug

Not every CSS provider can drop deprecated CSS constructs, especially
if they are forced to maintain backward compatibility with third party
code, like libadwaita.

The slightly annoying part is that we cannot use GTK_DEBUG_CHECK, as we
cannot include gtkdebug.h inside gtkcssparser.c, so we need to hack our
way around it.
This commit is contained in:
Emmanuele Bassi
2024-05-29 12:26:33 +01:00
parent accabe3eee
commit 7778430a31

View File

@@ -26,6 +26,11 @@
#include "gtkcsserror.h"
#include "gtkcsslocationprivate.h"
/* We cannot include gtkdebug.h, so we must keep this in sync */
extern unsigned int gtk_get_debug_flags (void);
#define DEBUG_CSS (1 << 20)
#define DEBUG_CHECK_CSS ((gtk_get_debug_flags () & DEBUG_CSS) != 0)
static void clear_ref (GtkCssVariableValueReference *ref);
#define GDK_ARRAY_NAME gtk_css_parser_references
@@ -626,7 +631,7 @@ void
gtk_css_parser_skip (GtkCssParser *self)
{
const GtkCssToken *token;
token = gtk_css_parser_get_token (self);
if (gtk_css_token_is_preserved (token, NULL))
{
@@ -659,7 +664,7 @@ gtk_css_parser_skip_until (GtkCssParser *self,
GtkCssTokenType token_type)
{
const GtkCssToken *token;
for (token = gtk_css_parser_get_token (self);
!gtk_css_token_is (token, token_type) &&
!gtk_css_token_is (token, GTK_CSS_TOKEN_EOF);
@@ -817,19 +822,22 @@ gtk_css_parser_warn_deprecated (GtkCssParser *self,
const char *format,
...)
{
va_list args;
GError *error;
if (DEBUG_CHECK_CSS)
{
va_list args;
GError *error;
va_start (args, format);
error = g_error_new_valist (GTK_CSS_PARSER_WARNING,
GTK_CSS_PARSER_WARNING_DEPRECATED,
format, args);
gtk_css_parser_emit_error (self,
gtk_css_parser_get_start_location (self),
gtk_css_parser_get_end_location (self),
error);
g_error_free (error);
va_end (args);
va_start (args, format);
error = g_error_new_valist (GTK_CSS_PARSER_WARNING,
GTK_CSS_PARSER_WARNING_DEPRECATED,
format, args);
gtk_css_parser_emit_error (self,
gtk_css_parser_get_start_location (self),
gtk_css_parser_get_end_location (self),
error);
g_error_free (error);
va_end (args);
}
}
gboolean
@@ -1153,7 +1161,7 @@ gtk_css_parser_parse_url_arg (GtkCssParser *parser,
*out_url = gtk_css_parser_consume_string (parser);
if (*out_url == NULL)
return 0;
return 1;
}
@@ -1199,7 +1207,7 @@ gtk_css_parser_consume_url (GtkCssParser *self)
gtk_css_parser_error_syntax (self, "Expected a URL");
return NULL;
}
return url;
}