0

I have a Gnome GJS app and would like to package it with Meson.

The app source (in ./src) has subfolders lib, object, and ui.

Each subfolder has a meson.build file that looks like this (for the ./src/lib folder):

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

and a gresource xml file that looks like this (also for the ./src/lib folder):

<?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>

In the ./src foder I have a com.domain.app.in file like this:

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

a meson.build file like this:

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

and a gresource xml file like this:

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

The main meson.build file in the project root looks like this:

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

So...

When I run meson builddir meson seems happy and gives no errors. It does populate the builddir, but not with anything visibly useful.

Then I cd into builddir and run ninja, ninja seems to not do much and I still don't have any executable file of any sort.

Thanks to Andy's comment, I ran meson install (with a bunch of test parameters for local folders) and did get some files including an executable.

BUT, when I try to run the executable from the terminal, I get the following error:

(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 is a file in the src folder of the app. It is referenced in the gresource xml file in that same folder.

What am I doing wrong or missing?

Any pointers would be greatly appreciated.

brainstormtrooper
  • 485
  • 2
  • 6
  • 18
  • 2
    Have you tried actually installing it somehwhere with ninja? `com.domain.app` is going to be your exectuable, and should get installed to `bindir` (whatever that is). – andy.holmes May 12 '20 at 00:05
  • Indeed... I was missing the ```meson install``` from inside builddir... – brainstormtrooper May 12 '20 at 05:50
  • I edited my question... I ran ```meson install``` and it did indeed generate an executable, but it won't run. I get ```ImportError: No JS module 'main' found in search path``` when I try to execute it. I think it's because the modules are installed either in ```lib``` (or worse, ```data```) and path only includes ```bin``` directories. – brainstormtrooper May 17 '20 at 06:52

1 Answers1

1

I think main.js is in the wrong directory, or you're referring to it incorrectly. Below you try to import main from the root of imports:

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

Yet in your GResource, the prefix puts it in src:

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

In principle you either need to change imports.main to imports.src.main or change /com/domain/app/src to /com/domain/app. However, in practice I believe all JavaScript source needs to be under the /com/domain/app/js prefix, so it should probably be /com/domain/app/js and imports.main.

Referencing the source for GNOME Weather and package.js will probably help a lot.

andy.holmes
  • 3,383
  • 17
  • 28
  • Well, there is progress, sort of. I got it to open a window with ```ninja run```, but it crashed saying ```No JS module 'UI' found in search path```. I think it's just not possible to import files from other folders... – brainstormtrooper May 31 '20 at 06:04
  • No, that's definitely possible. You just need to understand all your files are ending up in the GResource and think relative to the prefix. It would probably help to look at an existing app like gnome-weather. – andy.holmes Jun 01 '20 at 23:58
  • 1
    Thanks for the pointer. I did look at gnome-weather, and it was really helpful, but something else is going wrong - not related to packaging. Importing modules just doesn't work. I'll close this question because the build issue has been solved and ask another one about imports in general... – brainstormtrooper Jun 03 '20 at 05:11