Suggest using --reconfigure only when not already using it

pull/11628/head
Xavier Claessens 1 year ago committed by Eli Schwartz
parent f720105e24
commit b4b1395ef5
  1. 10
      mesonbuild/coredata.py
  2. 4
      mesonbuild/environment.py
  3. 16
      mesonbuild/utils/universal.py

@ -89,10 +89,10 @@ def get_genvs_default_buildtype_list() -> list[str]:
class MesonVersionMismatchException(MesonException):
'''Build directory generated with Meson version is incompatible with current version'''
def __init__(self, old_version: str, current_version: str) -> None:
def __init__(self, old_version: str, current_version: str, extra_msg: str = '') -> None:
super().__init__(f'Build directory has been generated with Meson version {old_version}, '
f'which is incompatible with the current version {current_version}. '
f'Consider reconfiguring the directory with meson setup --reconfigure.')
f'which is incompatible with the current version {current_version}.'
+ extra_msg)
self.old_version = old_version
self.current_version = current_version
@ -1099,9 +1099,9 @@ def major_versions_differ(v1: str, v2: str) -> bool:
# Major version differ, or one is development version but not the other.
return v1_major != v2_major or ('99' in {v1_minor, v2_minor} and v1_minor != v2_minor)
def load(build_dir: str) -> CoreData:
def load(build_dir: str, suggest_reconfigure: bool = True) -> CoreData:
filename = os.path.join(build_dir, 'meson-private', 'coredata.dat')
return pickle_load(filename, 'Coredata', CoreData)
return pickle_load(filename, 'Coredata', CoreData, suggest_reconfigure)
def save(obj: CoreData, build_dir: str) -> str:

@ -490,7 +490,7 @@ class Environment:
os.makedirs(self.log_dir, exist_ok=True)
os.makedirs(self.info_dir, exist_ok=True)
try:
self.coredata: coredata.CoreData = coredata.load(self.get_build_dir())
self.coredata: coredata.CoreData = coredata.load(self.get_build_dir(), suggest_reconfigure=False)
self.first_invocation = False
except FileNotFoundError:
self.create_new_coredata(options)
@ -508,7 +508,7 @@ class Environment:
coredata.read_cmd_line_file(self.build_dir, options)
self.create_new_coredata(options)
else:
raise e
raise MesonException(f'{str(e)} Try regenerating using "meson setup --wipe".')
else:
# Just create a fresh coredata in this case
self.scratch_dir = ''

@ -2411,22 +2411,22 @@ class OptionKey:
return self.type is OptionType.BASE
def pickle_load(filename: str, object_name: str, object_type: T.Type[_PL]) -> _PL:
load_fail_msg = f'{object_name} file {filename!r} is corrupted. Try with a fresh build tree.'
def pickle_load(filename: str, object_name: str, object_type: T.Type[_PL], suggest_reconfigure: bool = True) -> _PL:
load_fail_msg = f'{object_name} file {filename!r} is corrupted.'
extra_msg = ' Consider reconfiguring the directory with "meson setup --reconfigure".' if suggest_reconfigure else ''
try:
with open(filename, 'rb') as f:
obj = pickle.load(f)
except (pickle.UnpicklingError, EOFError):
raise MesonException(load_fail_msg)
raise MesonException(load_fail_msg + extra_msg)
except (TypeError, ModuleNotFoundError, AttributeError):
build_dir = os.path.dirname(os.path.dirname(filename))
raise MesonException(
f"{object_name} file {filename!r} references functions or classes that don't "
"exist. This probably means that it was generated with an old "
"version of meson. Try running from the source directory "
f'meson setup {build_dir} --wipe')
"version of meson." + extra_msg)
if not isinstance(obj, object_type):
raise MesonException(load_fail_msg)
raise MesonException(load_fail_msg + extra_msg)
# Because these Protocols are not available at runtime (and cannot be made
# available at runtime until we drop support for Python < 3.8), we have to
@ -2440,7 +2440,7 @@ def pickle_load(filename: str, object_name: str, object_type: T.Type[_PL]) -> _P
from ..coredata import version as coredata_version
from ..coredata import major_versions_differ, MesonVersionMismatchException
if major_versions_differ(version, coredata_version):
raise MesonVersionMismatchException(version, coredata_version)
raise MesonVersionMismatchException(version, coredata_version, extra_msg)
return obj

Loading…
Cancel
Save