diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index cf418bb26..ce03fbc0e 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -45,6 +45,16 @@ default_yielding = False # Can't bind this near the class method it seems, sadly. _T = T.TypeVar('_T') +class MesonVersionMismatchException(MesonException): + '''Build directory generated with Meson version incompatible with current version''' + def __init__(self, old_version, current_version): + super().__init__('Build directory has been generated with Meson version {}, ' + 'which is incompatible with current version {}.' + .format(old_version, current_version)) + self.old_version = old_version + self.current_version = current_version + + class UserOption(T.Generic[_T]): def __init__(self, description, choices, yielding): super().__init__() @@ -982,9 +992,7 @@ def load(build_dir): if not isinstance(obj, CoreData): raise MesonException(load_fail_msg) if major_versions_differ(obj.version, version): - raise MesonException('Build directory has been generated with Meson version %s, ' - 'which is incompatible with current version %s.\n' % - (obj.version, version)) + raise MesonVersionMismatchException(obj.version, version) return obj def save(obj, build_dir): diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 01fc8e44d..6987863c0 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -523,6 +523,11 @@ class Environment: self.first_invocation = False except FileNotFoundError: self.create_new_coredata(options) + except coredata.MesonVersionMismatchException as e: + # This is routine, but tell the user the update happened + mlog.log('Regenerating configuration from scratch:', str(e)) + coredata.read_cmd_line_file(self.build_dir, options) + self.create_new_coredata(options) except MesonException as e: # If we stored previous command line options, we can recover from # a broken/outdated coredata. diff --git a/run_unittests.py b/run_unittests.py index 0418ccf07..49e220601 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4030,7 +4030,7 @@ recommended as it is not supported on some platforms''') self.__reconfigure() out = self.init(testdir, extra_args=['--reconfigure', '-Dopt3=val3']) - self.assertRegex(out, 'WARNING:.*Regenerating configuration from scratch') + self.assertRegex(out, 'Regenerating configuration from scratch') self.assertRegex(out, 'opt1 val1') self.assertRegex(out, 'opt2 val2') self.assertRegex(out, 'opt3 val3') @@ -4067,7 +4067,7 @@ recommended as it is not supported on some platforms''') self.__reconfigure(change_minor=True) out = self.init(testdir, extra_args=['--reconfigure', '-Dopt3=val3']) - self.assertNotRegex(out, 'WARNING:.*Regenerating configuration from scratch') + self.assertNotRegex(out, 'Regenerating configuration from scratch') self.assertRegex(out, 'opt1 val1') self.assertRegex(out, 'opt2 val2') self.assertRegex(out, 'opt3 val3')