diff --git a/pkgs/build-support/make-hardcode-gsettings-patch/default.nix b/pkgs/build-support/make-hardcode-gsettings-patch/default.nix index a4a2dc36df05..820b003e3c6f 100644 --- a/pkgs/build-support/make-hardcode-gsettings-patch/default.nix +++ b/pkgs/build-support/make-hardcode-gsettings-patch/default.nix @@ -28,6 +28,8 @@ For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }` hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`. + - `patches`: A list of patches to apply before generating the patch. + Example: passthru = { hardcodeGsettingsPatch = makeHardcodeGsettingsPatch { @@ -35,29 +37,30 @@ schemaIdToVariableMapping = { ... }; - }; + }; - updateScript = - let - updateSource = ...; - updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; - in - _experimental-update-script-combinators.sequence [ - updateSource - updatePatch - ]; + updateScript = + let + updateSource = ...; + updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch; + in + _experimental-update-script-combinators.sequence [ + updateSource + updatePatch + ]; }; } */ { src, + patches ? [ ], schemaIdToVariableMapping, }: runCommand "hardcode-gsettings.patch" { - inherit src; + inherit src patches; nativeBuildInputs = [ git coccinelle @@ -67,6 +70,7 @@ runCommand '' unpackPhase cd "''${sourceRoot:-.}" + patchPhase set -x cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json git init diff --git a/pkgs/test/make-hardcode-gsettings-patch/default.nix b/pkgs/test/make-hardcode-gsettings-patch/default.nix index 6c5d2318c6d8..e27a6f179208 100644 --- a/pkgs/test/make-hardcode-gsettings-patch/default.nix +++ b/pkgs/test/make-hardcode-gsettings-patch/default.nix @@ -1,4 +1,5 @@ { runCommandLocal +, lib , git , clang-tools , makeHardcodeGsettingsPatch @@ -10,13 +11,15 @@ let name, expected, src, + patches ? [ ], schemaIdToVariableMapping, }: let - patch = makeHardcodeGsettingsPatch { + patch = makeHardcodeGsettingsPatch ({ inherit src schemaIdToVariableMapping; - }; + inherit patches; + }); in runCommandLocal "makeHardcodeGsettingsPatch-tests-${name}" @@ -33,6 +36,9 @@ let cp -r --no-preserve=all "${expected}" src-expected pushd src + for patch in ${lib.escapeShellArgs (builtins.map (p: "${p}") patches)}; do + patch < "$patch" + done patch < "${patch}" popd @@ -55,4 +61,17 @@ in }; expected = ./fixtures/example-project-patched; }; + + patches = mkTest { + name = "patches"; + src = ./fixtures/example-project-wrapped-settings-constructor; + patches = [ + # Avoid using wrapper function, which the generator cannot handle. + ./fixtures/example-project-wrapped-settings-constructor-resolve.patch + ]; + schemaIdToVariableMapping = { + "org.gnome.evolution-data-server.addressbook" = "EDS"; + }; + expected = ./fixtures/example-project-wrapped-settings-constructor-patched; + }; } diff --git a/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c new file mode 100644 index 000000000000..b0894614de7c --- /dev/null +++ b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c @@ -0,0 +1,15 @@ +#include +#include + +int main() { + g_autoptr(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, NULL, NULL); + } + + return 0; +} diff --git a/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-resolve.patch b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-resolve.patch new file mode 100644 index 000000000000..70b80a9e8627 --- /dev/null +++ b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-resolve.patch @@ -0,0 +1,17 @@ +--- a/main.c ++++ b/main.c +@@ -1,13 +1,9 @@ + #include + #include + +-void my_settings_new(const char *schema_id) { +- return g_settings_new(schema_id); +-} +- + int main() { + g_autoptr (GSettings) settings; +- settings = my_settings_new("org.gnome.evolution-data-server.addressbook"); ++ settings = g_settings_new("org.gnome.evolution-data-server.addressbook"); + + return 0; + } diff --git a/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c new file mode 100644 index 000000000000..0821097f350b --- /dev/null +++ b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c @@ -0,0 +1,13 @@ +#include +#include + +void my_settings_new(const char *schema_id) { + return g_settings_new(schema_id); +} + +int main() { + g_autoptr (GSettings) settings; + settings = my_settings_new("org.gnome.evolution-data-server.addressbook"); + + return 0; +}