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:
parent
6f695f3d92
commit
bc41b2db3d
5 changed files with 81 additions and 13 deletions
|
@ -28,6 +28,8 @@
|
||||||
For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }`
|
For example, `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }`
|
||||||
hardcodes looking for `org.gnome.evolution` into `@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:
|
Example:
|
||||||
passthru = {
|
passthru = {
|
||||||
hardcodeGsettingsPatch = makeHardcodeGsettingsPatch {
|
hardcodeGsettingsPatch = makeHardcodeGsettingsPatch {
|
||||||
|
@ -51,13 +53,14 @@
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
src,
|
src,
|
||||||
|
patches ? [ ],
|
||||||
schemaIdToVariableMapping,
|
schemaIdToVariableMapping,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
runCommand
|
runCommand
|
||||||
"hardcode-gsettings.patch"
|
"hardcode-gsettings.patch"
|
||||||
{
|
{
|
||||||
inherit src;
|
inherit src patches;
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
git
|
git
|
||||||
coccinelle
|
coccinelle
|
||||||
|
@ -67,6 +70,7 @@ runCommand
|
||||||
''
|
''
|
||||||
unpackPhase
|
unpackPhase
|
||||||
cd "''${sourceRoot:-.}"
|
cd "''${sourceRoot:-.}"
|
||||||
|
patchPhase
|
||||||
set -x
|
set -x
|
||||||
cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json
|
cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json
|
||||||
git init
|
git init
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{ runCommandLocal
|
{ runCommandLocal
|
||||||
|
, lib
|
||||||
, git
|
, git
|
||||||
, clang-tools
|
, clang-tools
|
||||||
, makeHardcodeGsettingsPatch
|
, makeHardcodeGsettingsPatch
|
||||||
|
@ -10,13 +11,15 @@ let
|
||||||
name,
|
name,
|
||||||
expected,
|
expected,
|
||||||
src,
|
src,
|
||||||
|
patches ? [ ],
|
||||||
schemaIdToVariableMapping,
|
schemaIdToVariableMapping,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
patch = makeHardcodeGsettingsPatch {
|
patch = makeHardcodeGsettingsPatch ({
|
||||||
inherit src schemaIdToVariableMapping;
|
inherit src schemaIdToVariableMapping;
|
||||||
};
|
inherit patches;
|
||||||
|
});
|
||||||
in
|
in
|
||||||
runCommandLocal
|
runCommandLocal
|
||||||
"makeHardcodeGsettingsPatch-tests-${name}"
|
"makeHardcodeGsettingsPatch-tests-${name}"
|
||||||
|
@ -33,6 +36,9 @@ let
|
||||||
cp -r --no-preserve=all "${expected}" src-expected
|
cp -r --no-preserve=all "${expected}" src-expected
|
||||||
|
|
||||||
pushd src
|
pushd src
|
||||||
|
for patch in ${lib.escapeShellArgs (builtins.map (p: "${p}") patches)}; do
|
||||||
|
patch < "$patch"
|
||||||
|
done
|
||||||
patch < "${patch}"
|
patch < "${patch}"
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
@ -55,4 +61,17 @@ in
|
||||||
};
|
};
|
||||||
expected = ./fixtures/example-project-patched;
|
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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue