Meson / Ninja 构建系统 - 如何在卸载时 运行 自定义脚本?

Meson / Ninja build system - How to run custom script at Uninstall?

Meson/Ninja 提供一种在安装时 运行 脚本的简单方法。
例如,这一行将告诉 Meson 运行 glib-compile-schemas 命令编译 GSettings on Linux(系统配置选项)。

meson.add_install_script('glib-compile-schemas', schemas_dir)
(此命令会在用户执行ninja install时自动运行)

如何在 uninstall 告诉 Meson 运行 自定义命令?
在这种特定情况下,我想删除(或至少重置为默认值)GSettings 中的键值对。要重置它们,我发现命令是 gsettings reset-recursively <path>(在终端中成功测试)。

添加自定义卸载脚本是still being discussed,很久以前就提出了,但还没有实现。看起来这个任务通常留给包管理器(因此留给相应的打包脚本)。

但我同意,在 meson install 命令的情况下存在一些不合逻辑的不对称。作为解决方法,您可以创建自己的目标:

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

缺点当然是应该显式调用,不能覆盖、附加或重命名内部uninstall目标和脚本应该有可执行权限。

然而,内部保留 uninstall target 确实会还原所有显式安装操作:

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).