lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+144 -11
+83 -11
pkgs/build-support/make-hardcode-gsettings-patch/hardcode-gsettings.cocci
··· 3 3 * where GSettings system could look for schemas, we need to point the software to a correct location somehow. 4 4 * For executables, we handle this using wrappers but this is not an option for libraries like e-d-s. 5 5 * Instead, we hardcode the schema path when creating the settings. 6 - * A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_PATH@ 6 + * A schema path (ie org.gnome.evolution) can be replaced by @EVOLUTION_SCHEMA_ID@ 7 7 * which is then replaced at build time by substituteAll. 8 8 * The mapping is provided in a json file ./glib-schema-to-var.json 9 9 */ ··· 23 23 with open("./glib-schema-to-var.json") as mapping_file: 24 24 schema_to_var = json.load(mapping_file); 25 25 26 - def get_schema_directory(schema_path): 26 + def get_schema_directory(schema_id): 27 27 # Sometimes the schema id is referenced using C preprocessor #define constant in the same file 28 28 # let’s try to resolve it first. 29 - schema_path = resolve_cpp_constant(schema_path.strip()).strip('"') 30 - if schema_path in schema_to_var: 31 - return f'"@{schema_to_var[schema_path]}@"' 32 - raise Exception(f"Unknown schema path {schema_path!r}, please add it to ./glib-schema-to-var.json") 33 - 29 + schema_id = resolve_cpp_constant(schema_id.strip()).strip('"') 30 + if schema_id in schema_to_var: 31 + return f'"@{schema_to_var[schema_id]}@"' 32 + raise Exception(f"Unknown schema path {schema_id!r}, please add it to ./glib-schema-to-var.json") 34 33 35 34 @find_cpp_constants@ 36 35 identifier const_name; ··· 49 48 50 49 @depends on ever record_cpp_constants || never record_cpp_constants@ 51 50 // We want to run after #define constants have been collected but even if there are no #defines. 52 - expression SCHEMA_PATH; 51 + expression SCHEMA_ID; 53 52 expression settings; 54 53 // Coccinelle does not like autocleanup macros in + sections, 55 54 // let’s use fresh id with concatenation to produce the code as a string. 56 55 fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source"; 57 56 fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema"; 58 - fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_PATH) { get_schema_directory(SCHEMA_PATH) }; 57 + fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) }; 59 58 @@ 60 - -settings = g_settings_new(SCHEMA_PATH); 59 + -settings = g_settings_new(SCHEMA_ID); 61 60 +{ 62 61 + schema_source_decl; 63 62 + schema_decl; ··· 65 64 + g_settings_schema_source_get_default(), 66 65 + TRUE, 67 66 + NULL); 68 - + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_PATH, FALSE); 67 + + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE); 69 68 + settings = g_settings_new_full(schema, NULL, NULL); 70 69 +} 70 + 71 + 72 + @depends on ever record_cpp_constants || never record_cpp_constants@ 73 + // We want to run after #define constants have been collected but even if there are no #defines. 74 + expression SCHEMA_ID; 75 + expression settings; 76 + expression BACKEND; 77 + // Coccinelle does not like autocleanup macros in + sections, 78 + // let’s use fresh id with concatenation to produce the code as a string. 79 + fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source"; 80 + fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema"; 81 + fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) }; 82 + @@ 83 + -settings = g_settings_new_with_backend(SCHEMA_ID, BACKEND); 84 + +{ 85 + + schema_source_decl; 86 + + schema_decl; 87 + + schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY, 88 + + g_settings_schema_source_get_default(), 89 + + TRUE, 90 + + NULL); 91 + + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE); 92 + + settings = g_settings_new_full(schema, BACKEND, NULL); 93 + +} 94 + 95 + 96 + @depends on ever record_cpp_constants || never record_cpp_constants@ 97 + // We want to run after #define constants have been collected but even if there are no #defines. 98 + expression SCHEMA_ID; 99 + expression settings; 100 + expression BACKEND; 101 + expression PATH; 102 + // Coccinelle does not like autocleanup macros in + sections, 103 + // let’s use fresh id with concatenation to produce the code as a string. 104 + fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source"; 105 + fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema"; 106 + fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) }; 107 + @@ 108 + -settings = g_settings_new_with_backend_and_path(SCHEMA_ID, BACKEND, PATH); 109 + +{ 110 + + schema_source_decl; 111 + + schema_decl; 112 + + schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY, 113 + + g_settings_schema_source_get_default(), 114 + + TRUE, 115 + + NULL); 116 + + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE); 117 + + settings = g_settings_new_full(schema, BACKEND, PATH); 118 + +} 119 + 120 + 121 + @depends on ever record_cpp_constants || never record_cpp_constants@ 122 + // We want to run after #define constants have been collected but even if there are no #defines. 123 + expression SCHEMA_ID; 124 + expression settings; 125 + expression PATH; 126 + // Coccinelle does not like autocleanup macros in + sections, 127 + // let’s use fresh id with concatenation to produce the code as a string. 128 + fresh identifier schema_source_decl = "g_autoptr(GSettingsSchemaSource) " ## "schema_source"; 129 + fresh identifier schema_decl = "g_autoptr(GSettingsSchema) " ## "schema"; 130 + fresh identifier SCHEMA_DIRECTORY = script:python(SCHEMA_ID) { get_schema_directory(SCHEMA_ID) }; 131 + @@ 132 + -settings = g_settings_new_with_path(SCHEMA_ID, PATH); 133 + +{ 134 + + schema_source_decl; 135 + + schema_decl; 136 + + schema_source = g_settings_schema_source_new_from_directory(SCHEMA_DIRECTORY, 137 + + g_settings_schema_source_get_default(), 138 + + TRUE, 139 + + NULL); 140 + + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE); 141 + + settings = g_settings_new_full(schema, NULL, PATH); 142 + +}
+1
pkgs/test/make-hardcode-gsettings-patch/default.nix
··· 51 51 schemaIdToVariableMapping = { 52 52 "org.gnome.evolution-data-server.addressbook" = "EDS"; 53 53 "org.gnome.evolution.calendar" = "EVO"; 54 + "org.gnome.seahorse.nautilus.window" = "SEANAUT"; 54 55 }; 55 56 expected = ./fixtures/example-project-patched; 56 57 };
+39
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-patched/main.c
··· 37 37 } 38 38 } 39 39 40 + void schema_id_with_backend() { 41 + GSettings *settings; 42 + { 43 + g_autoptr(GSettingsSchemaSource) schema_source; 44 + g_autoptr(GSettingsSchema) schema; 45 + schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 46 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution-data-server.addressbook", FALSE); 47 + settings = g_settings_new_full(schema, g_settings_backend_get_default(), NULL); 48 + } 49 + g_object_unref(settings); 50 + } 51 + 52 + void schema_id_with_backend_and_path() { 53 + GSettings *settings; 54 + { 55 + g_autoptr(GSettingsSchemaSource) schema_source; 56 + g_autoptr(GSettingsSchema) schema; 57 + schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL); 58 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE); 59 + settings = g_settings_new_full(schema, g_settings_backend_get_default(), "/org/gnome/seahorse/nautilus/windows/123/"); 60 + } 61 + g_object_unref(settings); 62 + } 63 + 64 + void schema_id_with_path() { 65 + GSettings *settings; 66 + { 67 + g_autoptr(GSettingsSchemaSource) schema_source; 68 + g_autoptr(GSettingsSchema) schema; 69 + schema_source = g_settings_schema_source_new_from_directory("@SEANAUT@", g_settings_schema_source_get_default(), TRUE, NULL); 70 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.seahorse.nautilus.window", FALSE); 71 + settings = g_settings_new_full(schema, NULL, "/org/gnome/seahorse/nautilus/windows/123/"); 72 + } 73 + g_object_unref(settings); 74 + } 75 + 40 76 int main() { 41 77 schema_id_literal(); 42 78 schema_id_from_constant(); 43 79 schema_id_autoptr(); 80 + schema_id_with_backend(); 81 + schema_id_with_backend_and_path(); 82 + schema_id_with_path(); 44 83 45 84 return 0; 46 85 }
+21
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project/main.c
··· 19 19 settings = g_settings_new("org.gnome.evolution.calendar"); 20 20 } 21 21 22 + void schema_id_with_backend() { 23 + GSettings *settings; 24 + settings = g_settings_new_with_backend("org.gnome.evolution-data-server.addressbook", g_settings_backend_get_default()); 25 + g_object_unref(settings); 26 + } 27 + 28 + void schema_id_with_backend_and_path() { 29 + GSettings *settings; 30 + settings = g_settings_new_with_backend_and_path("org.gnome.seahorse.nautilus.window", g_settings_backend_get_default(), "/org/gnome/seahorse/nautilus/windows/123/"); 31 + g_object_unref(settings); 32 + } 33 + 34 + void schema_id_with_path() { 35 + GSettings *settings; 36 + settings = g_settings_new_with_path("org.gnome.seahorse.nautilus.window", "/org/gnome/seahorse/nautilus/windows/123/"); 37 + g_object_unref(settings); 38 + } 39 + 22 40 int main() { 23 41 schema_id_literal(); 24 42 schema_id_from_constant(); 25 43 schema_id_autoptr(); 44 + schema_id_with_backend(); 45 + schema_id_with_backend_and_path(); 46 + schema_id_with_path(); 26 47 27 48 return 0; 28 49 }