【问题标题】:Is there any way to create GSettings schema during installation in Vala?在 Vala 中安装期间有什么方法可以创建 GSettings 模式?
【发布时间】:2014-11-05 07:50:20
【问题描述】:

我正在尝试使用使用 Glib.Settings 的 Vala 创建一个应用程序。如果其中的架构或键不存在,我不希望我的应用程序崩溃。我已经明白我无法捕获其中的错误(How to handle errors while using Glib.Settings in Vala?),所以我需要在安装程序时以某种方式创建一个模式,否则它会崩溃。我不想让用户写类似

的东西
glib-compile-schemas /usr/share/glib-2.0/schemas/

在终端中,所以我需要在程序中进行。

所以,问题是:我可以在我的程序中以某种方式编译架构吗?

【问题讨论】:

  • 您的程序是如何构建的?您可以将规则添加到 make、automake、cmake 或您拥有的内容中,但具体取决于您使用的内容。
  • @apmasell 我现在没有使用任何构建系统,而是通过使用 valac 的脚本构建它,但我打算在 cmake 上进行。
  • 您必须将其作为 CMake 安装过程的一部分。
  • @apmasell 好的,我明白了。
  • @apmasell 和另一个问题:有没有办法在不通过 cmake 安装程序时做到这一点?我打算为它做.deb打包,我可以在安装包的同时做吗?

标签: vala gsettings


【解决方案1】:

Vala 本身不负责编译您的架构;这取决于您的构建系统(例如 CMake 或 Meson)。打包您的应用后,打包系统将使用您的构建系统来构建包。

为了让您的构建系统编译它们,您需要将您的模式包含为 XML 文件,例如:

<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
  <schema path="/com/github/yourusername/yourrepositoryname/" id="com.github.yourusername.yourrepositoryname">
    <key name="useless-setting" type="b">
      <default>false</default>
      <summary>Useless Setting</summary>
      <description>Whether the useless switch is toggled</description>
    </key>
  </schema>
</schemalist>

然后在您的构建系统中,安装架构文件。例如,在介子中:

install_data (
    'gschema.xml',
    install_dir: join_paths (get_option ('datadir'), 'glib-2.0', 'schemas'),
    rename: meson.project_name () + '.gschema.xml'
)

meson.add_install_script('post_install.py')

使用 Meson,您还可以在使用构建系统安装时包含 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')

# Packaging tools define DESTDIR and this isn't needed for them
if 'DESTDIR' not in os.environ:
    print('Compiling gsettings schemas...')
    subprocess.call(['glib-compile-schemas', schemadir])

【讨论】:

    猜你喜欢
    • 2015-09-30
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2011-09-06
    • 2013-08-04
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    相关资源
    最近更新 更多