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.
This commit is contained in:
Jan Tojnar 2023-11-13 02:48:18 +01:00
parent 6f695f3d92
commit bc41b2db3d
5 changed files with 81 additions and 13 deletions

View File

@ -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

View File

@ -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;
};
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}