gnome: Fix depend_files listing for compile_resources

Also add a unit test that will test all codepaths for old Glib tools
versions.

Closes https://github.com/mesonbuild/meson/issues/2860
pull/3108/head
Nirbheek Chauhan 7 years ago committed by Jussi Pakkanen
parent 79865474c7
commit 0c1c387703
  1. 40
      mesonbuild/modules/gnome.py
  2. 21
      run_unittests.py
  3. 13
      test cases/frameworks/7 gnome/meson.build
  4. 2
      test cases/frameworks/7 gnome/resources/meson.build

@ -15,13 +15,11 @@
'''This module provides helper functions for Gnome/GLib related
functionality such as gobject-introspection, gresources and gtk-doc'''
from .. import build
import os
import copy
import subprocess
from . import ModuleReturnValue
from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list
from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
from .. import build
from .. import mlog
from .. import mesonlib
from .. import compilers
@ -29,6 +27,9 @@ from .. import interpreter
from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
from . import find_program, get_include_args
from . import ExtensionModule
from . import ModuleReturnValue
from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list
from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
from ..interpreterbase import noKwargs, permittedKwargs
# gresource compilation is broken due to the way
@ -233,17 +234,6 @@ class GnomeModule(ExtensionModule):
dep_files = stdout.split('\n')[:-1]
# In generate-dependencies mode, glib-compile-resources doesn't raise
# an error for missing resources but instead prints whatever filename
# was listed in the input file. That's good because it means we can
# handle resource files that get generated as part of the build, as
# follows.
#
# If there are multiple generated resource files with the same basename
# then this code will get confused.
def exists_in_srcdir(f):
return os.path.exists(os.path.join(state.environment.get_source_dir(), f))
depends = []
subdirs = []
for resfile in dep_files[:]:
@ -267,21 +257,29 @@ class GnomeModule(ExtensionModule):
break
if fname is not None:
dep_files.remove(resfile)
dep_files.append(
mesonlib.File(
is_built=True,
subdir=dep.get_subdir(),
fname=fname))
depends.append(dep)
subdirs.append(dep.get_subdir())
break
else:
if not exists_in_srcdir(resfile):
# In generate-dependencies mode, glib-compile-resources doesn't raise
# an error for missing resources but instead prints whatever filename
# was listed in the input file. That's good because it means we can
# handle resource files that get generated as part of the build, as
# follows.
#
# If there are multiple generated resource files with the same basename
# then this code will get confused.
try:
f = mesonlib.File.from_source_file(state.environment.get_source_dir(),
".", resfile)
except MesonException:
raise MesonException(
'Resource "%s" listed in "%s" was not found. If this is a '
'generated file, pass the target that generates it to '
'gnome.compile_resources() using the "dependencies" '
'keyword argument.' % (resfile, input_file))
dep_files.remove(resfile)
dep_files.append(f)
return dep_files, depends, subdirs
def _get_link_args(self, state, lib, depends=None, include_rpath=False,

@ -33,6 +33,7 @@ import mesonbuild.compilers
import mesonbuild.environment
import mesonbuild.mesonlib
import mesonbuild.coredata
import mesonbuild.modules.gnome
from mesonbuild.interpreter import ObjectHolder
from mesonbuild.mesonlib import (
is_linux, is_windows, is_osx, is_cygwin, is_dragonflybsd,
@ -525,7 +526,10 @@ class BasePlatformTests(unittest.TestCase):
self.privatedir = os.path.join(self.builddir, 'meson-private')
if inprocess:
try:
out = run_configure(self.meson_mainfile, self.meson_args + args + extra_args)[1]
(returncode, out, _) = run_configure(self.meson_mainfile, self.meson_args + args + extra_args)
if returncode != 0:
self._print_meson_log()
raise RuntimeError('Configure failed')
except:
self._print_meson_log()
raise
@ -2598,6 +2602,21 @@ endian = 'little'
self.init(testdir)
self.build()
def test_old_gnome_module_codepaths(self):
'''
A lot of code in the GNOME module is conditional on the version of the
glib tools that are installed, and breakages in the old code can slip
by once the CI has a newer glib version. So we force the GNOME module
to pretend that it's running on an ancient glib so the fallback code is
also tested.
'''
testdir = os.path.join(self.framework_test_dir, '7 gnome')
os.environ['MESON_UNIT_TEST_PRETEND_GLIB_OLD'] = "1"
mesonbuild.modules.gnome.native_glib_version = '2.20'
self.init(testdir, inprocess=True)
self.build()
mesonbuild.modules.gnome.native_glib_version = None
class LinuxArmCrossCompileTests(BasePlatformTests):
'''

@ -9,6 +9,19 @@ if cc.get_id() == 'intel'
add_global_arguments('-wd2282', language : 'c')
endif
py3 = import('python3').find_python()
pycode = '''import os, sys
if "MESON_UNIT_TEST_PRETEND_GLIB_OLD" in os.environ:
sys.exit(0)
sys.exit(1)
'''
pretend_glib_old = false
res = run_command(py3, '-c', pycode)
if res.returncode() == 0
pretend_glib_old = true
endif
gnome = import('gnome')
gio = dependency('gio-2.0')
giounix = dependency('gio-unix-2.0')

@ -29,7 +29,7 @@ gnome.compile_resources('simple-resources',
)
test('simple resource test (gresource)', find_program('resources.py'))
if glib.version() >= '2.52.0'
if not pretend_glib_old and glib.version() >= '2.52.0'
# This test cannot pass if GLib version is older than 9.99.9.
# Meson will raise an error if the user tries to use the 'dependencies'
# argument and the version of GLib is too old for generated resource

Loading…
Cancel
Save