【发布时间】:2021-06-27 14:03:48
【问题描述】:
首先,我是Vala、Gtk 和Meson 的新手,所以我的方向可能完全错误。
我在 Pop_OS 上运行! 20.10.
我想编译一个支持 GSettings 的小型 Vala 应用程序示例。
但是,当使用ninja 编译,使用sudo ninja install 安装然后执行时,我得到了标题中提到的错误。
似乎即使我的 gschema 文件被复制到 /usr/share/glib-2.0/schemas,在我的安装后脚本中运行 glib-compile-schemas 也没有做任何事情。
我还可以通过手动运行glib-compile-schemas 来确认这一点,然后使用 dconf Editor 检查我的设置是否可用而它们不可用。
data/gschema.xml
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema path="/com/github/mfru/vala-todo" id="com.github.mfru.vala-todo">
<key name="pos-x" type="i">
<default>360</default>
<summary>Horizontal position</summary>
<description>The saved horizontal position of our window</description>
</key>
<key name="pos-y" type="i">
<default>360</default>
<summary>Vertical position</summary>
<description>The saved vertical position of our window</description>
</key>
<key name="window-width" type="i">
<default>600</default>
<summary>Window width</summary>
<description>The saved width of our window</description>
</key>
<key name="window-height" type="i">
<default>400</default>
<summary>Window height</summary>
<description>The saved height of our window</description>
</key>
</schema>
</schemalist>
data/meson.build
install_data(
'gschema.xml',
install_dir: join_paths (get_option ('datadir'), 'glib-2.0', 'schemas'),
rename: meson.project_name () + '.geschema.xml'
)
介子/post-install.py
#!/usr/bin/env python3
import os
import subprocess
schemadir = os.path.join(os.environ['MESON_INSTALL_PREFIX'], 'share', 'glib-2.0', 'schemas')
print("Schemadir is", schemadir)
if 'DESTDIR' not in os.environ:
print("Compiling the gsettings schemas...")
subprocess.call(['glib-compile-schemas', schemadir])
我还用meson build --prefix=/usr --reconfigure 重新配置了介子前缀,因为最初前缀指向/usr/local,但我系统上的所有现有模式都在/usr/share 下
最后,我期望发生的事情是,我的示例应用程序在启动时不会因为缺少 GSettings 而崩溃。
我查看的资源:
https://mesonbuild.com/Configuring-a-build-directory.html
https://developer.gnome.org/gio/stable/glib-compile-schemas.html
Is there any way to create GSettings schema during installation in Vala?
【问题讨论】:
-
你确定 pop os 在 /usr/local 中寻找模式吗? glib-compile-schemas 页面说它只在 $XDG_DATA_DIRS 下查找,而 /usr/local 可能不存在。
-
我的措辞可能模棱两可:我能找到的所有模式都在
/usr/share/glib-2.0/schemas下,但介子前缀最初指向/usr/local,这导致glib-compile-schemas找不到模式,因为它不是在$XDG_DATA_DIRS中列出。我确实重新配置了介子构建前缀,所以我的架构实际上会被复制到/usr/share下的正确文件夹中,但它似乎仍然无法编译。 (运行的时候没有输出,我猜一般是成功的吧?) -
我不是真正的 glib 或模式导出(虽然我是上游 Meson 开发人员),python 的
subprocess.call如果出现问题不会引发异常,它会返回子进程的返回码,您可能想尝试将安装后脚本的最后一行更改为sys.exit(subprocess.call(...)),看看是否能解决您的问题。 -
我不认为是这样,我认为这可能是
glib-compile-schemas本身的问题。如上所述,我什至尝试手动运行glib-compile-schema。 (就像我将 XML 文件复制到/usr/share/glib-2.0/schemas并在目录中运行sudo glib-compile-schemas .一样)它确实编译为一个新的gschema.compiled文件,但dConf Editor既没有显示设置,我的程序也无法运行,因为仍然抛出 Glib-GIO-Error。