Commit bc41b2db authored by Jan Tojnar's avatar Jan Tojnar
Browse files

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.
parent 6f695f3d
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -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 {
@@ -51,13 +53,14 @@
*/
{
  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
+21 −2
Original line number Diff line number Diff line
{ 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;
  };
}
+15 −0
Original line number Diff line number Diff line
#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;
}
+17 −0
Original line number Diff line number Diff line
--- 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;
 }
+13 −0
Original line number Diff line number Diff line
#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;
}