girparser: Don't rely on gi-compile-repository exporting debug level

It seems cleaner to store this in the parser, rather than having the
compiler export a global variable that the parser must read.

Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2024-02-14 10:36:23 +00:00
parent a41496643b
commit 3f6de0706e
3 changed files with 14 additions and 4 deletions

View File

@ -124,7 +124,7 @@ out:
return success; return success;
} }
GLogLevelFlags logged_levels; static GLogLevelFlags logged_levels;
static void static void
log_handler (const gchar *log_domain, log_handler (const gchar *log_domain,
@ -198,6 +198,7 @@ main (int argc, char **argv)
includedirs ? g_strv_length (includedirs) : 0); includedirs ? g_strv_length (includedirs) : 0);
parser = gi_ir_parser_new (); parser = gi_ir_parser_new ();
gi_ir_parser_set_debug (parser, logged_levels);
gi_ir_parser_set_includes (parser, (const char *const *) includedirs); gi_ir_parser_set_includes (parser, (const char *const *) includedirs);

View File

@ -33,6 +33,8 @@ typedef struct _GIIrParser GIIrParser;
GIIrParser *gi_ir_parser_new (void); GIIrParser *gi_ir_parser_new (void);
void gi_ir_parser_free (GIIrParser *parser); void gi_ir_parser_free (GIIrParser *parser);
void gi_ir_parser_set_debug (GIIrParser *parser,
GLogLevelFlags logged_levels);
void gi_ir_parser_set_includes (GIIrParser *parser, void gi_ir_parser_set_includes (GIIrParser *parser,
const char *const *includes); const char *const *includes);

View File

@ -61,6 +61,7 @@ struct _GIIrParser
char **includes; char **includes;
char **gi_gir_path; char **gi_gir_path;
GList *parsed_modules; /* All previously parsed modules */ GList *parsed_modules; /* All previously parsed modules */
GLogLevelFlags logged_levels;
}; };
typedef enum typedef enum
@ -191,9 +192,17 @@ gi_ir_parser_new (void)
if (gi_gir_path != NULL) if (gi_gir_path != NULL)
parser->gi_gir_path = g_strsplit (gi_gir_path, G_SEARCHPATH_SEPARATOR_S, 0); parser->gi_gir_path = g_strsplit (gi_gir_path, G_SEARCHPATH_SEPARATOR_S, 0);
parser->logged_levels = G_LOG_LEVEL_MASK & ~(G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_DEBUG);
return parser; return parser;
} }
void
gi_ir_parser_set_debug (GIIrParser *parser,
GLogLevelFlags logged_levels)
{
parser->logged_levels = logged_levels;
}
void void
gi_ir_parser_free (GIIrParser *parser) gi_ir_parser_free (GIIrParser *parser)
{ {
@ -2915,8 +2924,6 @@ parse_include (GMarkupParseContext *context,
return TRUE; return TRUE;
} }
extern GLogLevelFlags logged_levels;
static void static void
start_element_handler (GMarkupParseContext *context, start_element_handler (GMarkupParseContext *context,
const char *element_name, const char *element_name,
@ -2927,7 +2934,7 @@ start_element_handler (GMarkupParseContext *context,
{ {
ParseContext *ctx = user_data; ParseContext *ctx = user_data;
if (logged_levels & G_LOG_LEVEL_DEBUG) if (ctx->parser->logged_levels & G_LOG_LEVEL_DEBUG)
{ {
GString *tags = g_string_new (""); GString *tags = g_string_new ("");
int i; int i;