Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnome: Doesn't generate typelib that is depended on by an executable (regression in b1e3440e) #7756

Open
smcv opened this issue Sep 18, 2020 · 6 comments
Assignees
Labels

Comments

@smcv
Copy link
Contributor

smcv commented Sep 18, 2020

Describe the bug
The gnome module in Meson since b1e3440 doesn't generate GObject-Introspection data under some circumstances where older versions did, causing libpeas to fail its build-time tests.

I'm honestly not sure whether this is a Meson bug or a libpeas bug, so I'm reporting it to both projects.

To Reproduce

This is a simplified version of the libpeas test suite. It builds a library that will not be installed, and generates a GObject-Introspection typelib which will also not be installed. The test assumes it can load that typelib.

# meson.build
project(
  'looks-like-libpeas', 'c',
)

gnome = import('gnome')

api_version = '1.0'
libhello_name = 'hello'
libhello_string = '@0@-@1@'.format(libhello_name, api_version)

libhello_public_h = [
  'hello.h',
]

libhello_c = [
  'hello.c',
]

libhello_lib = library(
  libhello_string,
  libhello_c,
  include_directories: include_directories('.'),
  install: false,
)

libhello_dep = declare_dependency(
  link_with: libhello_lib,
  include_directories: include_directories('.'),
)

libhello_gir = gnome.generate_gir(
  libhello_lib,
  sources: libhello_c + libhello_public_h,
  nsversion: api_version,
  namespace: 'Hello',
  symbol_prefix: 'hello',
  identifier_prefix: 'Hello',
  dependencies: [libhello_dep],
  export_packages: [libhello_string],
  link_with: libhello_lib,
  install: false,
  extra_args: [
    '--warn-all',
  ],
)

libhello_gir_dep = declare_dependency(
  sources: libhello_gir,
)

test_exe_deps = [
  dependency('glib-2.0'),
  dependency('gobject-introspection-1.0'),
  libhello_dep,
  libhello_gir_dep,
]

test_exe = executable(
  'my-test',
  'test.c',
  dependencies: test_exe_deps,
)

test_deps = []

if get_option('workaround')
  test_deps += libhello_gir
endif

test_env = environment()
test_env.set('GI_TYPELIB_PATH', meson.current_build_dir())

test(
  'my-test',
  test_exe,
  depends: test_deps,
  env: test_env,
)
# meson_options.txt
option('workaround', type: 'boolean', value: false)
/* hello.c */
#include "hello.h"
void
hello_world (void)
{
}
/* hello.h */
#pragma once
void hello_world (void);
/* test.c */
#include <glib.h>
#include <girepository.h>

int
main (void)
{
  GError *error = NULL;
  GIRepository *repo = g_irepository_get_default ();
  GITypelib *typelib = g_irepository_require (repo, "Hello", "1.0", 0, &error);
  g_assert_no_error (error);
  g_assert_nonnull (typelib);
  return 0;
}

This is a simplification. In the real libpeas, the equivalent of "Hello" is called "Introspection" and contains various toy objects, and the equivalents of test.c actually do something with the Introspection typelib.

Expected behavior
Before meson commit b1e3440 (found by bisection), the fact that test_exe depends on libhello_dep and libhello_gir_dep is enough to guarantee that Hello-1.0.typelib and Hello-1.0.gir are generated, even if you do not configure with -Dworkaround=true.

Actual behaviour
If you do not configure with -Dworkaround=true, Hello-1.0.typelib is not generated and the test fails.

Workaround
Adding depends: [libhello_gir] to the test() (not just the executable()) forces the GIR and typelib to be generated, making the test pass. For easy comparison, my sample code does this when configured with -Dworkaround=true.

system parameters

  • Native build
  • Debian unstable
  • Python 3.8.6rc1
  • Meson 0.55.3
  • Ninja 1.10.1
@smcv
Copy link
Contributor Author

smcv commented Sep 18, 2020

See https://gitlab.gnome.org/GNOME/libpeas/-/issues/40 for the other side of this.

gnomesysadmins pushed a commit to GNOME/libpeas that referenced this issue Sep 18, 2020
In Meson since 0.55.0, having the test executable depend on the GIR
dependency is not enough to ensure that uninstalled GIR and typelib
files are generated: we also need to have the test itself depend on
the GIR build target.

It is not clear to me whether this is a workaround for a Meson
regression (if what libpeas previously did was meant to work), or a
solution to a libpeas bug (if it was never meant to be guaranteed to
work). For more details see
<mesonbuild/meson#7756>.

Resolves: https://gitlab.gnome.org/GNOME/libpeas/-/issues/40
Bug-Debian: https://bugs.debian.org/966951
@dcbaker dcbaker added the gnome label Sep 20, 2020
@smcv
Copy link
Contributor Author

smcv commented Sep 21, 2020

cc @nirbheek: was this an intended consequence of #7131?

@nirbheek
Copy link
Member

No, this was unintended. I'll look into it.

@nirbheek nirbheek self-assigned this Sep 21, 2020
@nirbheek nirbheek added this to the 0.56.0 milestone Oct 14, 2020
@xclaesse
Copy link
Member

I turned @smcv code into a unit test and I can confirm it does not pass.

One possible fix is to special case .gir and .typelib as link_depend instead. But I think b1e3440 should rather be reverted because if it's in the sources then it's a dependency, that's what the user asked for...

That being said, I know why there is that pattern of putting gir files into sources. That's the only way they have to make gir depend on other gir. If you add a 2nd library libfoo that depends on libhello, you do gnome.generate_gir(libfoo, ..., dependencies: libhello_dep) and you want that to depend on libhello's gir. That can be done by adding libhello_gir into libhello_dep's sources.

We can be smarter than that, pkgconfig.generate() has a very similar case:

pkg.generate(libhello)
pkg.generate(libfoo, libraries: libhello)

In that case libhello is promoted from Libs: to Requires: because the first call tagged libhello object with the name of generate pc file so the 2nd call knows libhello has a pc file associated.

I think gnome.generate_gir(libhello) should do something similar, libhello should remember the generated gir target so when it's passed to another generate_gir it can be added as dependency.

@xclaesse
Copy link
Member

@smcv as for libpeas case, I think libhello_gir really is a dependency of the test, your workaround is the actual proper fix IMHO. Alternatively it could also be set as link_depends on the executable.

@jpakkane jpakkane modified the milestones: 0.56.0, 0.56.1 Oct 30, 2020
@nirbheek nirbheek modified the milestones: 0.56.1, 0.56.3 Jan 9, 2021
@hadess
Copy link

hadess commented Feb 16, 2021

I ran into the same problem, with my custom gir not being built because it wasn't a dependency or installed. I expected it to be built nonetheless, like an uninstalled binary would have. Surprising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants