lol
0
fork

Configure Feed

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

makeHardcodeGsettingsPatch: Add support for `schemaExistsFunction`

evolution-ews introduced a check for optional schemas, which would skip our hardcoded code paths.
https://gitlab.gnome.org/GNOME/evolution-ews/-/commit/a0c514bd345c67fe0fd2ed6ef48a25649b1f4d8e

Let’s update the semantic patch to also replace the invocations of specified `schemaExistsFunction` for known schemas with `true`.

Jan Tojnar e50f76c7 5a60a1a9

+257 -11
+6
pkgs/build-support/make-hardcode-gsettings-patch/default.nix
··· 27 27 For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }` 28 28 hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`. 29 29 30 + - `schemaExistsFunction`: name of the function that is used for checking 31 + if optional schema exists. Its invocation will be replaced with TRUE 32 + for known schemas. 33 + 30 34 - `patches`: A list of patches to apply before generating the patch. 31 35 32 36 Example: ··· 54 58 src, 55 59 patches ? [ ], 56 60 schemaIdToVariableMapping, 61 + schemaExistsFunction ? null, 57 62 }: 58 63 59 64 runCommand "hardcode-gsettings.patch" ··· 71 76 patchPhase 72 77 set -x 73 78 cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json 79 + cp ${builtins.toFile "glib-schema-exists-function.json" (builtins.toJSON schemaExistsFunction)} ./glib-schema-exists-function.json 74 80 git init 75 81 git add -A 76 82 spatch --sp-file "${./hardcode-gsettings.cocci}" --dir . --in-place
+20
pkgs/build-support/make-hardcode-gsettings-patch/hardcode-gsettings.cocci
··· 34 34 return f'"@{schema_to_var[schema_id]}@"' 35 35 raise Exception(f"Unknown schema path {schema_id!r}, please add it to ./glib-schema-to-var.json") 36 36 37 + 38 + @script:python schema_exists_fn@ 39 + fn; 40 + @@ 41 + import json 42 + 43 + with open("./glib-schema-exists-function.json") as fn_file: 44 + if (fn := json.load(fn_file)): 45 + coccinelle.fn = fn 46 + 47 + 37 48 @find_cpp_constants@ 38 49 identifier const_name; 39 50 expression val; ··· 143 154 + schema = g_settings_schema_source_lookup(schema_source, SCHEMA_ID, FALSE); 144 155 + settings = g_settings_new_full(schema, NULL, PATH); 145 156 +} 157 + 158 + 159 + @replace_schema_exists_fns depends on ever record_cpp_constants || never record_cpp_constants@ 160 + // We want to run after #define constants have been collected but even if there are no #defines. 161 + expression SCHEMA_ID; 162 + identifier schema_exists_fn.fn; 163 + @@ 164 + -fn(SCHEMA_ID) 165 + +true
+32 -11
pkgs/test/make-hardcode-gsettings-patch/default.nix
··· 13 13 expected, 14 14 src, 15 15 patches ? [ ], 16 - schemaIdToVariableMapping, 16 + args, 17 17 }: 18 18 19 19 let 20 - patch = makeHardcodeGsettingsPatch ({ 21 - inherit src schemaIdToVariableMapping; 22 - inherit patches; 23 - }); 20 + patch = makeHardcodeGsettingsPatch ( 21 + args 22 + // { 23 + inherit src patches; 24 + } 25 + ); 24 26 in 25 27 runCommandLocal "makeHardcodeGsettingsPatch-tests-${name}" 26 28 ··· 54 56 basic = mkTest { 55 57 name = "basic"; 56 58 src = ./fixtures/example-project; 57 - schemaIdToVariableMapping = { 58 - "org.gnome.evolution-data-server.addressbook" = "EDS"; 59 - "org.gnome.evolution.calendar" = "EVO"; 60 - "org.gnome.seahorse.nautilus.window" = "SEANAUT"; 59 + args = { 60 + schemaIdToVariableMapping = { 61 + "org.gnome.evolution-data-server.addressbook" = "EDS"; 62 + "org.gnome.evolution.calendar" = "EVO"; 63 + "org.gnome.seahorse.nautilus.window" = "SEANAUT"; 64 + }; 61 65 }; 62 66 expected = ./fixtures/example-project-patched; 63 67 }; ··· 69 73 # Avoid using wrapper function, which the generator cannot handle. 70 74 ./fixtures/example-project-wrapped-settings-constructor-resolve.patch 71 75 ]; 72 - schemaIdToVariableMapping = { 73 - "org.gnome.evolution-data-server.addressbook" = "EDS"; 76 + args = { 77 + schemaIdToVariableMapping = { 78 + "org.gnome.evolution-data-server.addressbook" = "EDS"; 79 + }; 74 80 }; 75 81 expected = ./fixtures/example-project-wrapped-settings-constructor-patched; 76 82 }; 83 + 84 + existsFn = mkTest { 85 + name = "exists-fn"; 86 + src = ./fixtures/example-project; 87 + args = { 88 + schemaIdToVariableMapping = { 89 + "org.gnome.evolution-data-server.addressbook" = "EDS"; 90 + "org.gnome.evolution.calendar" = "EVO"; 91 + "org.gnome.seahorse.nautilus.window" = "SEANAUT"; 92 + }; 93 + schemaExistsFunction = "e_ews_common_utils_gsettings_schema_exists"; 94 + }; 95 + expected = ./fixtures/example-project-patched-with-exists-fn; 96 + }; 97 + 77 98 }
+129
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-patched-with-exists-fn/main.c
··· 1 + #include <gio/gio.h> 2 + #include <glib-object.h> 3 + 4 + void schema_id_literal() { 5 + GSettings *settings; 6 + { 7 + g_autoptr(GSettingsSchemaSource) schema_source; 8 + g_autoptr(GSettingsSchema) schema; 9 + schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 10 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution-data-server.addressbook", FALSE); 11 + settings = g_settings_new_full(schema, NULL, NULL); 12 + } 13 + g_object_unref(settings); 14 + } 15 + 16 + #define SELF_UID_PATH_ID "org.gnome.evolution-data-server.addressbook" 17 + int schema_id_from_constant() { 18 + GSettings *settings; 19 + { 20 + g_autoptr(GSettingsSchemaSource) schema_source; 21 + g_autoptr(GSettingsSchema) schema; 22 + schema_source = g_settings_schema_source_new_from_directory("@EDS@", g_settings_schema_source_get_default(), TRUE, NULL); 23 + schema = g_settings_schema_source_lookup(schema_source, SELF_UID_PATH_ID, FALSE); 24 + settings = g_settings_new_full(schema, NULL, NULL); 25 + } 26 + g_object_unref(settings); 27 + } 28 + 29 + void schema_id_autoptr() { 30 + g_autoptr(GSettings) settings = NULL; 31 + { 32 + g_autoptr(GSettingsSchemaSource) schema_source; 33 + g_autoptr(GSettingsSchema) schema; 34 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 35 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 36 + settings = g_settings_new_full(schema, NULL, NULL); 37 + } 38 + } 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 + 76 + void exists_fn_guard() { 77 + if (!true) { 78 + return; 79 + } 80 + 81 + g_autoptr(GSettings) settings = NULL; 82 + { 83 + g_autoptr(GSettingsSchemaSource) schema_source; 84 + g_autoptr(GSettingsSchema) schema; 85 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 86 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 87 + settings = g_settings_new_full(schema, NULL, NULL); 88 + } 89 + } 90 + 91 + void exists_fn_nested() { 92 + if (true) { 93 + g_autoptr(GSettings) settings = NULL; 94 + { 95 + g_autoptr(GSettingsSchemaSource) schema_source; 96 + g_autoptr(GSettingsSchema) schema; 97 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 98 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 99 + settings = g_settings_new_full(schema, NULL, NULL); 100 + } 101 + } 102 + } 103 + 104 + void exists_fn_unknown() { 105 + if (true) { 106 + g_autoptr(GSettings) settings = NULL; 107 + { 108 + g_autoptr(GSettingsSchemaSource) schema_source; 109 + g_autoptr(GSettingsSchema) schema; 110 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 111 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 112 + settings = g_settings_new_full(schema, NULL, NULL); 113 + } 114 + } 115 + } 116 + 117 + int main() { 118 + schema_id_literal(); 119 + schema_id_from_constant(); 120 + schema_id_autoptr(); 121 + schema_id_with_backend(); 122 + schema_id_with_backend_and_path(); 123 + schema_id_with_path(); 124 + exists_fn_guard(); 125 + exists_fn_nested(); 126 + exists_fn_unknown(); 127 + 128 + return 0; 129 + }
+44
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-patched/main.c
··· 73 73 g_object_unref(settings); 74 74 } 75 75 76 + void exists_fn_guard() { 77 + if (!e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 78 + return; 79 + } 80 + 81 + g_autoptr(GSettings) settings = NULL; 82 + { 83 + g_autoptr(GSettingsSchemaSource) schema_source; 84 + g_autoptr(GSettingsSchema) schema; 85 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 86 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 87 + settings = g_settings_new_full(schema, NULL, NULL); 88 + } 89 + } 90 + 91 + void exists_fn_nested() { 92 + if (e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 93 + g_autoptr(GSettings) settings = NULL; 94 + { 95 + g_autoptr(GSettingsSchemaSource) schema_source; 96 + g_autoptr(GSettingsSchema) schema; 97 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 98 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 99 + settings = g_settings_new_full(schema, NULL, NULL); 100 + } 101 + } 102 + } 103 + 104 + void exists_fn_unknown() { 105 + if (e_ews_common_utils_gsettings_schema_exists("org.gnome.foo")) { 106 + g_autoptr(GSettings) settings = NULL; 107 + { 108 + g_autoptr(GSettingsSchemaSource) schema_source; 109 + g_autoptr(GSettingsSchema) schema; 110 + schema_source = g_settings_schema_source_new_from_directory("@EVO@", g_settings_schema_source_get_default(), TRUE, NULL); 111 + schema = g_settings_schema_source_lookup(schema_source, "org.gnome.evolution.calendar", FALSE); 112 + settings = g_settings_new_full(schema, NULL, NULL); 113 + } 114 + } 115 + } 116 + 76 117 int main() { 77 118 schema_id_literal(); 78 119 schema_id_from_constant(); ··· 80 121 schema_id_with_backend(); 81 122 schema_id_with_backend_and_path(); 82 123 schema_id_with_path(); 124 + exists_fn_guard(); 125 + exists_fn_nested(); 126 + exists_fn_unknown(); 83 127 84 128 return 0; 85 129 }
+26
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project/main.c
··· 37 37 g_object_unref(settings); 38 38 } 39 39 40 + void exists_fn_guard() { 41 + if (!e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 42 + return; 43 + } 44 + 45 + g_autoptr(GSettings) settings = NULL; 46 + settings = g_settings_new("org.gnome.evolution.calendar"); 47 + } 48 + 49 + void exists_fn_nested() { 50 + if (e_ews_common_utils_gsettings_schema_exists("org.gnome.evolution.calendar")) { 51 + g_autoptr(GSettings) settings = NULL; 52 + settings = g_settings_new("org.gnome.evolution.calendar"); 53 + } 54 + } 55 + 56 + void exists_fn_unknown() { 57 + if (e_ews_common_utils_gsettings_schema_exists("org.gnome.foo")) { 58 + g_autoptr(GSettings) settings = NULL; 59 + settings = g_settings_new("org.gnome.evolution.calendar"); 60 + } 61 + } 62 + 40 63 int main() { 41 64 schema_id_literal(); 42 65 schema_id_from_constant(); ··· 44 67 schema_id_with_backend(); 45 68 schema_id_with_backend_and_path(); 46 69 schema_id_with_path(); 70 + exists_fn_guard(); 71 + exists_fn_nested(); 72 + exists_fn_unknown(); 47 73 48 74 return 0; 49 75 }