我的 gjs 介子构建设置有什么问题?

What's wrong with my gjs meson build setup?

我有一个 Gnome GJS 应用程序,想用 Meson 打包它。

应用程序源(在 ./src 中)有子文件夹 lib、object 和 ui。

每个子文件夹都有一个如下所示的 meson.build 文件(对于 ./src/lib 文件夹):

app_resource = gnome.compile_resources(app_id + 'src.lib',
  app_id + '.lib.gresource.xml',
  source_dir: '.',
  gresource_bundle: true,
  install: true,
  install_dir : pkgdatadir)

和一个看起来像这样的 gresource xml 文件(也用于 ./src/lib 文件夹):

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/com/domain/app/js">
    <file>aes.js</file>
    <file>file.js</file>
    <file>settings.js</file>
    <file>table.js</file>
    <file>template.js</file>
  </gresource>
</gresources>

在 ./src 文件夹中,我有一个 com.domain.app.in 文件,如下所示:

#!@GJS@
imports.package.init({ name: "com.domain.app",
                       version: "@PACKAGE_VERSION@",
                       prefix: "@prefix@",
                       libdir: "@libdir@" });
imports.package.run(imports.main);

一个meson.build这样的文件:

app_resource = gnome.compile_resources(app_id + '.src',
  app_id + '.src.gresource.xml',
  source_dir: '.',
  gresource_bundle: true,
  install: true,
  install_dir : pkgdatadir)

app_launcher = configure_file(
  output : app_id,
  input : app_id + '.in',
  configuration: app_configuration)
install_data(app_launcher,
  install_dir: get_option('bindir'),
  install_mode: 'rwxr-xr-x'
)

和这样的 gresource xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/com/domain/app/src">
    <file>main.js</file>
  </gresource>
</gresources>

项目根目录中的主要 meson.build 文件如下所示:

project('app', 'c',
  version: '0.1.0',
  meson_version: '>= 0.50.0',
)

app_command = 'app'
app_id = 'com.domain.app'

gnome = import('gnome')
intl = import('i18n')

config_h = configuration_data()
GETTEXT_PACKAGE = app_id
config_h.set_quoted('GETTEXT_PACKAGE', GETTEXT_PACKAGE)
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
configure_file(
  output: 'config.h',
  configuration: config_h,
)
add_global_arguments([
  '-DHAVE_CONFIG_H',
  '-I' + meson.build_root(),
], language: 'c')

app_configuration = configuration_data()

app_configuration.set('GJS', find_program('gjs').path())
app_configuration.set('PACKAGE_NAME', app_id)
app_configuration.set('PACKAGE_VERSION', meson.project_version())
app_configuration.set('prefix', get_option('prefix'))

pkgdatadir = join_paths(get_option('datadir'), app_id)
app_configuration.set('libdir', join_paths(get_option('prefix'), get_option('libdir')))
app_configuration.set('pkgdatadir', pkgdatadir)

subdir('src')
subdir('src/lib')
subdir('src/ui')
subdir('src/object')
subdir('data')
subdir('po')
meson.add_install_script('meson/meson_post_install.py')

所以...

当我 运行 meson builddir meson 似乎很高兴并且没有给出任何错误。它确实填充了 builddir,但没有任何明显有用的东西。

然后我 cd 到 builddir 和 运行 ninja,ninja 似乎没什么用,我仍然没有任何类型的可执行文件。

感谢 Andy 的评论,我 运行 meson install(使用本地文件夹的一堆测试参数)并确实获得了一些文件,包括可执行文件。

但是,当我尝试从终端 运行 可执行文件时,出现以下错误:

(com.domain.app:6420): Gjs-WARNING **: 21:27:05.765: JS ERROR: ImportError: No JS module 'main' found in search path

@./com.domain.app:6:1

main.js 是应用程序 src 文件夹中的一个文件。它在同一文件夹中的 gresource xml 文件中被引用。

我做错了什么或遗漏了什么?

任何指点将不胜感激。

我认为 main.js 在错误的目录中,或者您引用的目录不正确。下面你尝试从 imports:

的根导入 main
#!@GJS@
imports.package.init({ name: "com.domain.app",
                       version: "@PACKAGE_VERSION@",
                       prefix: "@prefix@",
                       libdir: "@libdir@" });
imports.package.run(imports.main);

然而在您的 GResource 中,prefix 将其放入 src:

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/com/domain/app/src">
    <file>main.js</file>
  </gresource>
</gresources>

原则上要么把imports.main改成imports.src.main,要么把/com/domain/app/src改成/com/domain/app。但是,实际上我相信所有 JavaScript 源都需要在 /com/domain/app/js 前缀下,所以它可能应该是 /com/domain/app/jsimports.main.

参考 GNOME Weather and package.js 的来源可能会有很大帮助。