about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/make-hardcode-gsettings-patch/default.nix
blob: a1d2de21c4cb3af38aa44ee932cddd951888bc0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{
  runCommand,
  git,
  coccinelle,
  python3,
}:

/*
  Can be used as part of an update script to automatically create a patch
  hardcoding the path of all GSettings schemas in C code.
  For example:
  passthru = {
    hardcodeGsettingsPatch = makeHardcodeGsettingsPatch {
      inherit src;
      schemaIdToVariableMapping = {
         ...
      };
    };

    updateScript =
      let
        updateSource = ...;
        updatePatch = _experimental-update-script-combinators.copyAttrOutputToFile "evolution-ews.hardcodeGsettingsPatch" ./hardcode-gsettings.patch;
      in
      _experimental-update-script-combinators.sequence [
        updateSource
        updatePatch
      ];
    };
  }
  takes as input a mapping from schema path to variable name.
  For example `{ "org.gnome.evolution" = "EVOLUTION_SCHEMA_PATH"; }`
  hardcodes looking for `org.gnome.evolution` into `@EVOLUTION_SCHEMA_PATH@`.
  All schemas must be listed.
*/
{
  src,
  schemaIdToVariableMapping,
}:

runCommand
  "hardcode-gsettings.patch"
  {
    inherit src;
    nativeBuildInputs = [
      git
      coccinelle
      python3 # For patch script
    ];
  }
  ''
    unpackPhase
    cd "''${sourceRoot:-.}"
    set -x
    cp ${builtins.toFile "glib-schema-to-var.json" (builtins.toJSON schemaIdToVariableMapping)} ./glib-schema-to-var.json
    git init
    git add -A
    spatch --sp-file "${./hardcode-gsettings.cocci}" --dir . --in-place
    git diff > "$out"
  ''