···33 * where GSettings system could look for schemas, we need to point the software to a correct location somehow.
44 * For executables, we handle this using wrappers but this is not an option for libraries like e-d-s.
55 * Instead, we hardcode the schema path when creating the settings.
66- * A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_PATH@
66+ * A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_ID@
77 * which is then replaced at build time by substituteAll.
88 * The mapping is provided in a json file ./glib-schema-to-var.json
99 */
···2323with open("./glib-schema-to-var.json") as mapping_file:
2424 schema_to_var = json.load(mapping_file);
25252626-def get_schema_directory(schema_path):
2626+def get_schema_directory(schema_id):
2727 # Sometimes the schema id is referenced using C preprocessor #define constant in the same file
2828 # let’s try to resolve it first.
2929- schema_path = resolve_cpp_constant(schema_path.strip()).strip('"')
3030- if schema_path in schema_to_var:
3131- return f'"@{schema_to_var[schema_path]}@"'
3232- raise Exception(f"Unknown schema path {schema_path!r}, please add it to ./glib-schema-to-var.json")
3333-2929+ schema_id = resolve_cpp_constant(schema_id.strip()).strip('"')
3030+ if schema_id in schema_to_var:
3131+ return f'"@{schema_to_var[schema_id]}@"'
3232+ raise Exception(f"Unknown schema path {schema_id!r}, please add it to ./glib-schema-to-var.json")
34333534@find_cpp_constants@
3635identifier const_name;
···49485049@depends on ever record_cpp_constants || never record_cpp_constants@
5150// We want to run after #define constants have been collected but even if there are no #defines.
5252-expression SCHEMA_PATH;
5151+expression SCHEMA_ID;
5352expression settings;
5453// Coccinelle does not like autocleanup macros in + sections,
5554// let’s use fresh id with concatenation to produce the code as a string.
5655fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
5756fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
5858-fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_PATH) { get_schema_directory(SCHEMA_PATH) };
5757+fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
5958@@
6060--settings = g_settings_new(SCHEMA_PATH);
5959+-settings = g_settings_new(SCHEMA_ID);
6160+{
6261+ schema_source_decl;
6362+ schema_decl;
···6564+ g_settings_schema_source_get_default(),
6665+ TRUE,
6766+ NULL);
6868-+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_PATH, FALSE);
6767++ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
6968+ settings = g_settings_new_full(schema, NULL, NULL);
7069+}
7070+7171+7272+@depends on ever record_cpp_constants || never record_cpp_constants@
7373+// We want to run after #define constants have been collected but even if there are no #defines.
7474+expression SCHEMA_ID;
7575+expression settings;
7676+expression BACKEND;
7777+// Coccinelle does not like autocleanup macros in + sections,
7878+// let’s use fresh id with concatenation to produce the code as a string.
7979+fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
8080+fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
8181+fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
8282+@@
8383+-settings = g_settings_new_with_backend(SCHEMA_ID, BACKEND);
8484++{
8585++ schema_source_decl;
8686++ schema_decl;
8787++ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
8888++ g_settings_schema_source_get_default(),
8989++ TRUE,
9090++ NULL);
9191++ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
9292++ settings = g_settings_new_full(schema, BACKEND, NULL);
9393++}
9494+9595+9696+@depends on ever record_cpp_constants || never record_cpp_constants@
9797+// We want to run after #define constants have been collected but even if there are no #defines.
9898+expression SCHEMA_ID;
9999+expression settings;
100100+expression BACKEND;
101101+expression PATH;
102102+// Coccinelle does not like autocleanup macros in + sections,
103103+// let’s use fresh id with concatenation to produce the code as a string.
104104+fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
105105+fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
106106+fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
107107+@@
108108+-settings = g_settings_new_with_backend_and_path(SCHEMA_ID, BACKEND, PATH);
109109++{
110110++ schema_source_decl;
111111++ schema_decl;
112112++ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
113113++ g_settings_schema_source_get_default(),
114114++ TRUE,
115115++ NULL);
116116++ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
117117++ settings = g_settings_new_full(schema, BACKEND, PATH);
118118++}
119119+120120+121121+@depends on ever record_cpp_constants || never record_cpp_constants@
122122+// We want to run after #define constants have been collected but even if there are no #defines.
123123+expression SCHEMA_ID;
124124+expression settings;
125125+expression PATH;
126126+// Coccinelle does not like autocleanup macros in + sections,
127127+// let’s use fresh id with concatenation to produce the code as a string.
128128+fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
129129+fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
130130+fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
131131+@@
132132+-settings = g_settings_new_with_path(SCHEMA_ID, PATH);
133133++{
134134++ schema_source_decl;
135135++ schema_decl;
136136++ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
137137++ g_settings_schema_source_get_default(),
138138++ TRUE,
139139++ NULL);
140140++ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
141141++ settings = g_settings_new_full(schema, NULL, PATH);
142142++}