0

I'm trying to switch a project over to meson/ninja but it takes multiple executions of ninja to successfully complete, and at first glance it appears that the early failures are because of incomplete build steps that are supposed to precede it. The steps that seem out of order are usually while I'm calling a sed through custom_target to fix some auto generated output during the compile of a library (lib-b) that depends on another one (lib-a). This is essentially what I have for (lib-b):

lib_b = shared_library('lib-b-' + apiversion, lib_b_sources,
     link_args: [ '-Wl,--version-script' ],
   vala_header: 'lib-b.h',
     vala_args: lib_b_vala_args,
     vala_vapi: 'lib-b-@0@.vapi'.format(apiversion),
      vala_gir: 'Lib-@0@.gir'.format(apiversion),
  dependencies: lib_b_deps,
        c_args: lib_b_args,
     soversion: soversion,
       install: true,
   install_dir: [ true, true, true, false ],
)

custom_target('LibB-@0@.gir'.format(apiversion),
      command: [ sed,
                 '-e', 's|Lib[.]|LibB.|g',
                 '-e', 's|namespace name="Lib"|namespace name="LibB"|g',
                 '-e', 's|LibB[.]Foo|LibA.Foo|g',
                 '-e', 's|<package name="lib-b-@0@"/>|<include name="LibA" version="@0@"/><package name="lib-b-@0@"/>|'.format(apiversion),
                 join_paths(meson.current_build_dir(), 'Lib-@0@.gir'.format(apiversion)),
               ],
       output: 'LibB-@0@.gir'.format(apiversion),
      capture: true,
      install: true,
  install_dir: dir_gir,
)

if g_ir_compiler.found()
  custom_target('LibB-@0@.typelib'.format(apiversion),
        command: [ g_ir_compiler,
                   '--shared-library', lib_b.full_path(),
                   '--includedir', lib_a_girdir,
                   '--output', '@OUTPUT@',
                   join_paths(meson.current_build_dir(), 'LibB-@0@.gir'.format(apiversion)),
                 ],
         output: 'LibB-@0@.typelib'.format(apiversion),
        depends: lib_b,
        install: true,
    install_dir: dir_typelib,
)
endif

After the first run of ninja I get errors like this:

FAILED: src/lib/b/LibB-1.0.gir 
/usr/bin/python3 /usr/bin/meson --internal exe /home/user/proj/_build/meson-private/meson_exe_sed_3429069bbdfaffa2d113b782ce02a55d5fd96973.dat
/usr/bin/sed: can't read /home/user/proj/_build/src/lib/b/Lib-1.0.gir: No such file or directory

Where Lib-1.0.gir is supposed to be one of the outputs of the shared_library command. If I run it again it creates the file, makes it further, and complains with a similar error. I run it again, further this time but errors on other internal projects that depend on the file that isn't being created. I run it one last time and it completes.

It would surprise me if meson/ninja was not capable to executing build steps in a sequence where one must precede the other. Have I done something gross/stupid here? I'm basically porting over an autotools setup that works, but is slooooow.

geoffjay
  • 413
  • 4
  • 13

1 Answers1

0

You have to put outputs into the input keyword of your custom_target's so they understand the dependency and run in the correct order.

Also you should be using the gnome module to generate gir files: http://mesonbuild.com/Gnome-module.html#gnomegenerate_gir

TingPing
  • 2,129
  • 1
  • 12
  • 15
  • Hmm, seems unnecessary to use the `gnome` module when `valac` outputs a `gir` directly. I tried it anyways and `gnome.generate_gir` doesn't output a file that can be used as the `input` of another `custom_target`. When I compile I get an error with `'src/lib/b/Lib-1.0.gir', needed by 'src/lib/b/LibB-1.0.gir', missing and no known rule to make it`. Maybe it's wrong to do what I'm trying to do using `meson`, but I would argue that I should be able to run `sed|awk|whatever` on a file that's generated by the compiler. – geoffjay Aug 15 '17 at 01:34
  • After more messing around I feel pretty confident saying that calling `gnome.generate_gir` on a set of Vala sources doesn't work. You need Vala to generate the header file that gets included while building the introspection file, and `g-ir-scanner` apparently doesn't take Vala files as input. So you need `valac` to generate the `gir` file. Unfortunately it looks like this will be easier to generate manually than using meson. – geoffjay Aug 17 '17 at 22:52
  • Sorry overlooked the fact it was Vala. There might be a discussion over supporting the output gir though. – TingPing Aug 18 '17 at 02:29