lol

makeHardcodeGsettingsPatch: Support applying patches

This is useful for replacing code that cannot be easily handled by the generator,
such as the tentative settings constructor in e-d-s.

+81 -13
+15 -11
pkgs/build-support/make-hardcode-gsettings-patch/default.nix
··· 28 28 For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }` 29 29 hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`. 30 30 31 + - `patches`: A list of patches to apply before generating the patch. 32 + 31 33 Example: 32 34 passthru = { 33 35 hardcodeGsettingsPatch = makeHardcodeGsettingsPatch { ··· 35 37 schemaIdToVariableMapping = { 36 38 ... 37 39 }; 38 - }; 40 + }; 39 41 40 - updateScript = 41 - let 42 - updateSource = ...; 43 - updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; 44 - in 45 - _experimental-update-script-combinators.sequence [ 46 - updateSource 47 - updatePatch 48 - ]; 42 + updateScript = 43 + let 44 + updateSource = ...; 45 + updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; 46 + in 47 + _experimental-update-script-combinators.sequence [ 48 + updateSource 49 + updatePatch 50 + ]; 49 51 }; 50 52 } 51 53 */ 52 54 { 53 55 src, 56 + patches ? [ ], 54 57 schemaIdToVariableMapping, 55 58 }: 56 59 57 60 runCommand 58 61 "hardcode-gsettings.patch" 59 62 { 60 - inherit src; 63 + inherit src patches; 61 64 nativeBuildInputs = [ 62 65 git 63 66 coccinelle ··· 67 70 '' 68 71 unpackPhase 69 72 cd "''${sourceRoot:-.}" 73 + patchPhase 70 74 set -x 71 75 cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json 72 76 git init
+21 -2
pkgs/test/make-hardcode-gsettings-patch/default.nix
··· 1 1 { runCommandLocal 2 + , lib 2 3 , git 3 4 , clang-tools 4 5 , makeHardcodeGsettingsPatch ··· 10 11 name, 11 12 expected, 12 13 src, 14 + patches ? [ ], 13 15 schemaIdToVariableMapping, 14 16 }: 15 17 16 18 let 17 - patch = makeHardcodeGsettingsPatch { 19 + patch = makeHardcodeGsettingsPatch ({ 18 20 inherit src schemaIdToVariableMapping; 19 - }; 21 + inherit patches; 22 + }); 20 23 in 21 24 runCommandLocal 22 25 "makeHardcodeGsettingsPatch-tests-${name}" ··· 33 36 cp -r --no-preserve=all "${expected}" src-expected 34 37 35 38 pushd src 39 + for patch in ${lib.escapeShellArgs (builtins.map (p: "${p}") patches)}; do 40 + patch < "$patch" 41 + done 36 42 patch < "${patch}" 37 43 popd 38 44 ··· 54 60 "org.gnome.seahorse.nautilus.window" = "SEANAUT"; 55 61 }; 56 62 expected = ./fixtures/example-project-patched; 63 + }; 64 + 65 + patches = mkTest { 66 + name = "patches"; 67 + src = ./fixtures/example-project-wrapped-settings-constructor; 68 + patches = [ 69 + # Avoid using wrapper function, which the generator cannot handle. 70 + ./fixtures/example-project-wrapped-settings-constructor-resolve.patch 71 + ]; 72 + schemaIdToVariableMapping = { 73 + "org.gnome.evolution-data-server.addressbook" = "EDS"; 74 + }; 75 + expected = ./fixtures/example-project-wrapped-settings-constructor-patched; 57 76 }; 58 77 }
+15
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c
··· 1 + #include <gio/gio.h> 2 + #include <glib-object.h> 3 + 4 + int main() { 5 + g_autoptr(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 + 14 + return 0; 15 + }
+17
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-resolve.patch
··· 1 + --- a/main.c 2 + +++ b/main.c 3 + @@ -1,13 +1,9 @@ 4 + #include <gio/gio.h> 5 + #include <glib-object.h> 6 + 7 + -void my_settings_new(const char *schema_id) { 8 + - return g_settings_new(schema_id); 9 + -} 10 + - 11 + int main() { 12 + g_autoptr (GSettings) settings; 13 + - settings = my_settings_new("org.gnome.evolution-data-server.addressbook"); 14 + + settings = g_settings_new("org.gnome.evolution-data-server.addressbook"); 15 + 16 + return 0; 17 + }
+13
pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c
··· 1 + #include <gio/gio.h> 2 + #include <glib-object.h> 3 + 4 + void my_settings_new(const char *schema_id) { 5 + return g_settings_new(schema_id); 6 + } 7 + 8 + int main() { 9 + g_autoptr (GSettings) settings; 10 + settings = my_settings_new("org.gnome.evolution-data-server.addressbook"); 11 + 12 + return 0; 13 + }