From 1917b9253e70ae3469b97673f479d54d37b3b881 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 2 Sep 2022 14:37:51 -0700 Subject: [PATCH] modules/gnome: make_native_glib_version an instance var This removes the need for the use of the global statement. I've also updated the test that overrides this to use mock.patch instead of hand monkey patching. --- mesonbuild/modules/gnome.py | 15 ++++++--------- unittests/linuxliketests.py | 7 ++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index b64ba6888..037d2fa05 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -269,8 +269,6 @@ class VapiTarget(build.CustomTarget): # https://bugzilla.gnome.org/show_bug.cgi?id=774368 gresource_dep_needed_version = '>= 2.51.1' -native_glib_version: T.Optional[str] = None - class GnomeModule(ExtensionModule): INFO = ModuleInfo('gnome') @@ -285,6 +283,7 @@ class GnomeModule(ExtensionModule): self.install_gtk_update_icon_cache = False self.install_update_desktop_database = False self.devenv: T.Optional[build.EnvironmentVariables] = None + self.native_glib_version: T.Optional[str] = None self.methods.update({ 'post_install': self.post_install, 'compile_resources': self.compile_resources, @@ -300,19 +299,17 @@ class GnomeModule(ExtensionModule): 'generate_vapi': self.generate_vapi, }) - @staticmethod - def _get_native_glib_version(state: 'ModuleState') -> str: - global native_glib_version - if native_glib_version is None: + def _get_native_glib_version(self, state: 'ModuleState') -> str: + if self.native_glib_version is None: glib_dep = PkgConfigDependency('glib-2.0', state.environment, {'native': True, 'required': False}) if glib_dep.found(): - native_glib_version = glib_dep.get_version() + self.native_glib_version = glib_dep.get_version() else: mlog.warning('Could not detect glib version, assuming 2.54. ' 'You may get build errors if your glib is older.') - native_glib_version = '2.54' - return native_glib_version + self.native_glib_version = '2.54' + return self.native_glib_version @mesonlib.run_once def __print_gresources_warning(self, state: 'ModuleState') -> None: diff --git a/unittests/linuxliketests.py b/unittests/linuxliketests.py index 69e4c6f74..7de321480 100644 --- a/unittests/linuxliketests.py +++ b/unittests/linuxliketests.py @@ -1082,15 +1082,12 @@ class LinuxlikeTests(BasePlatformTests): also tested. ''' testdir = os.path.join(self.framework_test_dir, '7 gnome') - mesonbuild.modules.gnome.native_glib_version = '2.20' - env = {'MESON_UNIT_TEST_PRETEND_GLIB_OLD': "1"} - try: + with mock.patch('mesonbuild.modules.gnome.GnomeModule._get_native_glib_version', mock.Mock(return_value='2.20')): + env = {'MESON_UNIT_TEST_PRETEND_GLIB_OLD': "1"} self.init(testdir, inprocess=True, override_envvars=env) self.build(override_envvars=env) - finally: - mesonbuild.modules.gnome.native_glib_version = None @skipIfNoPkgconfig def test_pkgconfig_usage(self):