3

Meson/Ninja provide an easy method to run a script at install time.
For example, this line will tell Meson to run the glib-compile-schemas command to compile the GSettings on Linux (system configuration options).

meson.add_install_script('glib-compile-schemas', schemas_dir)
(this command will be automatically run when the user executes ninja install)

How can I tell Meson to run a custom command at uninstall?
In this specific case I would like to delete (or at least reset to default) the key-value pairs in GSettings. To reset them, I have found that the command is gsettings reset-recursively <path> (successfully tested in terminal).

Igor Carmagna
  • 957
  • 1
  • 10
  • 34

1 Answers1

1

Adding custom uninstall script is still being discussed, it's proposed quite some time ago but not yet implemented. It looks this task is typically left for package manager (and therefore to corresponding packaged scripts).

But I agree, there is some illogical asymmetry in case of meson install command. As a workaround, you can create your own target:

 run_target('my-uninstall', command : ['scripts/uninstall.sh'])

The drawbacks, of course, are that it should be invoked explicitly, cannot override, append or rename internal uninstall target and script should have executable permissions.

The internal, reserved uninstall target, however, does revert all explicit install operations:

Meson allows you to uninstall an install step by invoking the uninstall target. This will remove all files installed as part of install. Note that this does not restore the original files. This also does not undo changes done by custom install scripts (because they can do arbitrary install operations).

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thank you very much for your accurate reply and for finding the time to share your knowledge!! I think at this point I will create a custom `uninstall.py` script that will execute `ninja uninstall` plus the other custom commands – Igor Carmagna Jun 15 '21 at 17:09
  • I don't think it's possible, meson and thus ninja already have uninstall target that reverts all install operations but, obviously, not reverting any operations done from within add_install_script(), check this https://mesonbuild.com/Release-notes-for-0-38-0.html (top) – pmod Jun 15 '21 at 18:39
  • Solution (waiting for official Meson feature): I created a bash script called `uninstall.sh`, which calls `sudo ninja uninstall` and also takes care of other custom operations that need to be performed. I tested it and it works. Thank you for helping me to better understand the problem. – Igor Carmagna Jun 15 '21 at 20:18
  • ok, I see, it's the other way round, I am glad that it helped! – pmod Jun 15 '21 at 20:42