makeHardcodeGsettingsPatch: Support other constructors
In addition to `g_settings_new`, there are three other GSettings constructors: https://docs.gtk.org/gio/ctor.Settings.new.html
This commit is contained in:
parent
98e84e79a9
commit
4346dee424
4 changed files with 144 additions and 11 deletions
|
@ -3,7 +3,7 @@
|
||||||
* where GSettings system could look for schemas, we need to point the software to a correct location somehow.
|
* where GSettings system could look for schemas, we need to point the software to a correct location somehow.
|
||||||
* For executables, we handle this using wrappers but this is not an option for libraries like e-d-s.
|
* For executables, we handle this using wrappers but this is not an option for libraries like e-d-s.
|
||||||
* Instead, we hardcode the schema path when creating the settings.
|
* Instead, we hardcode the schema path when creating the settings.
|
||||||
* A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_PATH@
|
* A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_ID@
|
||||||
* which is then replaced at build time by substituteAll.
|
* which is then replaced at build time by substituteAll.
|
||||||
* The mapping is provided in a json file ./glib-schema-to-var.json
|
* The mapping is provided in a json file ./glib-schema-to-var.json
|
||||||
*/
|
*/
|
||||||
|
@ -23,14 +23,13 @@ def resolve_cpp_constant(const_name):
|
||||||
with open("./glib-schema-to-var.json") as mapping_file:
|
with open("./glib-schema-to-var.json") as mapping_file:
|
||||||
schema_to_var = json.load(mapping_file);
|
schema_to_var = json.load(mapping_file);
|
||||||
|
|
||||||
def get_schema_directory(schema_path):
|
def get_schema_directory(schema_id):
|
||||||
# Sometimes the schema id is referenced using C preprocessor #define constant in the same file
|
# Sometimes the schema id is referenced using C preprocessor #define constant in the same file
|
||||||
# let’s try to resolve it first.
|
# let’s try to resolve it first.
|
||||||
schema_path = resolve_cpp_constant(schema_path.strip()).strip('"')
|
schema_id = resolve_cpp_constant(schema_id.strip()).strip('"')
|
||||||
if schema_path in schema_to_var:
|
if schema_id in schema_to_var:
|
||||||
return f'"@{schema_to_var[schema_path]}@"'
|
return f'"@{schema_to_var[schema_id]}@"'
|
||||||
raise Exception(f"Unknown schema path {schema_path!r}, please add it to ./glib-schema-to-var.json")
|
raise Exception(f"Unknown schema path {schema_id!r}, please add it to ./glib-schema-to-var.json")
|
||||||
|
|
||||||
|
|
||||||
@find_cpp_constants@
|
@find_cpp_constants@
|
||||||
identifier const_name;
|
identifier const_name;
|
||||||
|
@ -49,15 +48,15 @@ register_cpp_constant(const_name, val)
|
||||||
|
|
||||||
@depends on ever record_cpp_constants || never record_cpp_constants@
|
@depends on ever record_cpp_constants || never record_cpp_constants@
|
||||||
// We want to run after #define constants have been collected but even if there are no #defines.
|
// We want to run after #define constants have been collected but even if there are no #defines.
|
||||||
expression SCHEMA_PATH;
|
expression SCHEMA_ID;
|
||||||
expression settings;
|
expression settings;
|
||||||
// Coccinelle does not like autocleanup macros in + sections,
|
// Coccinelle does not like autocleanup macros in + sections,
|
||||||
// let’s use fresh id with concatenation to produce the code as a string.
|
// let’s use fresh id with concatenation to produce the code as a string.
|
||||||
fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
|
fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
|
||||||
fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
|
fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
|
||||||
fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_PATH) { get_schema_directory(SCHEMA_PATH) };
|
fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
|
||||||
@@
|
@@
|
||||||
-settings = g_settings_new(SCHEMA_PATH);
|
-settings = g_settings_new(SCHEMA_ID);
|
||||||
+{
|
+{
|
||||||
+ schema_source_decl;
|
+ schema_source_decl;
|
||||||
+ schema_decl;
|
+ schema_decl;
|
||||||
|
@ -65,6 +64,79 @@ fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_PATH) { get_schema_dire
|
||||||
+ g_settings_schema_source_get_default(),
|
+ g_settings_schema_source_get_default(),
|
||||||
+ TRUE,
|
+ TRUE,
|
||||||
+ NULL);
|
+ NULL);
|
||||||
+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_PATH, FALSE);
|
+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
|
||||||
+ settings = g_settings_new_full(schema, NULL, NULL);
|
+ settings = g_settings_new_full(schema, NULL, NULL);
|
||||||
+}
|
+}
|
||||||
|
|
||||||
|
|
||||||
|
@depends on ever record_cpp_constants || never record_cpp_constants@
|
||||||
|
// We want to run after #define constants have been collected but even if there are no #defines.
|
||||||
|
expression SCHEMA_ID;
|
||||||
|
expression settings;
|
||||||
|
expression BACKEND;
|
||||||
|
// Coccinelle does not like autocleanup macros in + sections,
|
||||||
|
// let’s use fresh id with concatenation to produce the code as a string.
|
||||||
|
fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
|
||||||
|
fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
|
||||||
|
fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
|
||||||
|
@@
|
||||||
|
-settings = g_settings_new_with_backend(SCHEMA_ID, BACKEND);
|
||||||
|
+{
|
||||||
|
+ schema_source_decl;
|
||||||
|
+ schema_decl;
|
||||||
|
+ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
|
||||||
|
+ g_settings_schema_source_get_default(),
|
||||||
|
+ TRUE,
|
||||||
|
+ NULL);
|
||||||
|
+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
|
||||||
|
+ settings = g_settings_new_full(schema, BACKEND, NULL);
|
||||||
|
+}
|
||||||
|
|
||||||
|
|
||||||
|
@depends on ever record_cpp_constants || never record_cpp_constants@
|
||||||
|
// We want to run after #define constants have been collected but even if there are no #defines.
|
||||||
|
expression SCHEMA_ID;
|
||||||
|
expression settings;
|
||||||
|
expression BACKEND;
|
||||||
|
expression PATH;
|
||||||
|
// Coccinelle does not like autocleanup macros in + sections,
|
||||||
|
// let’s use fresh id with concatenation to produce the code as a string.
|
||||||
|
fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
|
||||||
|
fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
|
||||||
|
fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
|
||||||
|
@@
|
||||||
|
-settings = g_settings_new_with_backend_and_path(SCHEMA_ID, BACKEND, PATH);
|
||||||
|
+{
|
||||||
|
+ schema_source_decl;
|
||||||
|
+ schema_decl;
|
||||||
|
+ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
|
||||||
|
+ g_settings_schema_source_get_default(),
|
||||||
|
+ TRUE,
|
||||||
|
+ NULL);
|
||||||
|
+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
|
||||||
|
+ settings = g_settings_new_full(schema, BACKEND, PATH);
|
||||||
|
+}
|
||||||
|
|
||||||
|
|
||||||
|
@depends on ever record_cpp_constants || never record_cpp_constants@
|
||||||
|
// We want to run after #define constants have been collected but even if there are no #defines.
|
||||||
|
expression SCHEMA_ID;
|
||||||
|
expression settings;
|
||||||
|
expression PATH;
|
||||||
|
// Coccinelle does not like autocleanup macros in + sections,
|
||||||
|
// let’s use fresh id with concatenation to produce the code as a string.
|
||||||
|
fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source";
|
||||||
|
fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema";
|
||||||
|
fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) };
|
||||||
|
@@
|
||||||
|
-settings = g_settings_new_with_path(SCHEMA_ID, PATH);
|
||||||
|
+{
|
||||||
|
+ schema_source_decl;
|
||||||
|
+ schema_decl;
|
||||||
|
+ schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY,
|
||||||
|
+ g_settings_schema_source_get_default(),
|
||||||
|
+ TRUE,
|
||||||
|
+ NULL);
|
||||||
|
+ schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE);
|
||||||
|
+ settings = g_settings_new_full(schema, NULL, PATH);
|
||||||
|
+}
|
||||||
|
|
|
@ -51,6 +51,7 @@ in
|
||||||
schemaIdToVariableMapping = {
|
schemaIdToVariableMapping = {
|
||||||
"org.gnome.evolution-data-server.addressbook" = "EDS";
|
"org.gnome.evolution-data-server.addressbook" = "EDS";
|
||||||
"org.gnome.evolution.calendar" = "EVO";
|
"org.gnome.evolution.calendar" = "EVO";
|
||||||
|
"org.gnome.seahorse.nautilus.window" = "SEANAUT";
|
||||||
};
|
};
|
||||||
expected = ./fixtures/example-project-patched;
|
expected = ./fixtures/example-project-patched;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,10 +37,49 @@ void schema_id_autoptr() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void schema_id_with_backend() {
|
||||||
|
GSettings *settings;
|
||||||
|
{
|
||||||
|
g_autoptr(GSettingsSchemaSource) schema_source;
|
||||||
|
g_autoptr(GSettingsSchema) schema;
|
||||||
|
schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL);
|
||||||
|
schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution-data-server.addressbook", FALSE);
|
||||||
|
settings = g_settings_new_full(schema, g_settings_backend_get_default(), NULL);
|
||||||
|
}
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void schema_id_with_backend_and_path() {
|
||||||
|
GSettings *settings;
|
||||||
|
{
|
||||||
|
g_autoptr(GSettingsSchemaSource) schema_source;
|
||||||
|
g_autoptr(GSettingsSchema) schema;
|
||||||
|
schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL);
|
||||||
|
schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE);
|
||||||
|
settings = g_settings_new_full(schema, g_settings_backend_get_default(), "/org/gnome/seahorse/nautilus/windows/123/");
|
||||||
|
}
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void schema_id_with_path() {
|
||||||
|
GSettings *settings;
|
||||||
|
{
|
||||||
|
g_autoptr(GSettingsSchemaSource) schema_source;
|
||||||
|
g_autoptr(GSettingsSchema) schema;
|
||||||
|
schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL);
|
||||||
|
schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE);
|
||||||
|
settings = g_settings_new_full(schema, NULL, "/org/gnome/seahorse/nautilus/windows/123/");
|
||||||
|
}
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
schema_id_literal();
|
schema_id_literal();
|
||||||
schema_id_from_constant();
|
schema_id_from_constant();
|
||||||
schema_id_autoptr();
|
schema_id_autoptr();
|
||||||
|
schema_id_with_backend();
|
||||||
|
schema_id_with_backend_and_path();
|
||||||
|
schema_id_with_path();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,31 @@ void schema_id_autoptr() {
|
||||||
settings = g_settings_new("org.gnome.evolution.calendar");
|
settings = g_settings_new("org.gnome.evolution.calendar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void schema_id_with_backend() {
|
||||||
|
GSettings *settings;
|
||||||
|
settings = g_settings_new_with_backend("org.gnome.evolution-data-server.addressbook", g_settings_backend_get_default());
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void schema_id_with_backend_and_path() {
|
||||||
|
GSettings *settings;
|
||||||
|
settings = g_settings_new_with_backend_and_path("org.gnome.seahorse.nautilus.window", g_settings_backend_get_default(), "/org/gnome/seahorse/nautilus/windows/123/");
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void schema_id_with_path() {
|
||||||
|
GSettings *settings;
|
||||||
|
settings = g_settings_new_with_path("org.gnome.seahorse.nautilus.window", "/org/gnome/seahorse/nautilus/windows/123/");
|
||||||
|
g_object_unref(settings);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
schema_id_literal();
|
schema_id_literal();
|
||||||
schema_id_from_constant();
|
schema_id_from_constant();
|
||||||
schema_id_autoptr();
|
schema_id_autoptr();
|
||||||
|
schema_id_with_backend();
|
||||||
|
schema_id_with_backend_and_path();
|
||||||
|
schema_id_with_path();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue