about summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2023-11-13 02:48:18 +0100
committerJan Tojnar <jtojnar@gmail.com>2023-11-21 08:42:47 +0100
commitbc41b2db3db188be72ab71919893b160d44c98d9 (patch)
treee3995a86ec67434fe66c54e9068a47b9ed890004 /pkgs
parent6f695f3d92be6b9994d69f3de2eaffb9d6b94f92 (diff)
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.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/build-support/make-hardcode-gsettings-patch/default.nix26
-rw-r--r--pkgs/test/make-hardcode-gsettings-patch/default.nix23
-rw-r--r--pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c15
-rw-r--r--pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-resolve.patch17
-rw-r--r--pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c13
5 files changed, 81 insertions, 13 deletions
diff --git a/pkgs/build-support/make-hardcode-gsettings-patch/default.nix b/pkgs/build-support/make-hardcode-gsettings-patch/default.nix
index a4a2dc36df053..820b003e3c6fa 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 6c5d2318c6d8c..e27a6f1792085 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 0000000000000..b0894614de7c9
--- /dev/null
+++ b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor-patched/main.c
@@ -0,0 +1,15 @@
+#include <gio/gio.h>
+#include <glib-object.h>
+
+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 0000000000000..70b80a9e86274
--- /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 <gio/gio.h>
+ #include <glib-object.h>
+ 
+-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 0000000000000..0821097f350be
--- /dev/null
+++ b/pkgs/test/make-hardcode-gsettings-patch/fixtures/example-project-wrapped-settings-constructor/main.c
@@ -0,0 +1,13 @@
+#include <gio/gio.h>
+#include <glib-object.h>
+
+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;
+}