From 9fb839687b70443757c3e77b4a1c5857d553bdc2 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 10 Sep 2020 13:57:20 +0530 Subject: [PATCH] minstall: Add version field to install data And check the install data in the same way that mtest checks serialisation data. Fixes https://github.com/mesonbuild/meson/issues/2354 --- mesonbuild/backend/backends.py | 6 ++++-- mesonbuild/backend/ninjabackend.py | 6 ------ mesonbuild/minstall.py | 14 +++++++++++++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 568aeee09..bc82d158b 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -74,7 +74,7 @@ class CleanTrees: class InstallData: def __init__(self, source_dir, build_dir, prefix, strip_bin, - install_umask, mesonintrospect): + install_umask, mesonintrospect, version): self.source_dir = source_dir self.build_dir = build_dir self.prefix = prefix @@ -89,6 +89,7 @@ class InstallData: self.install_scripts = [] self.install_subdirs = [] self.mesonintrospect = mesonintrospect + self.version = version class TargetInstallData: def __init__(self, fname, outdir, aliases, strip, install_name_mappings, rpath_dirs_to_remove, install_rpath, install_mode, optional=False): @@ -1158,7 +1159,8 @@ class Backend: self.environment.get_prefix(), strip_bin, self.environment.coredata.get_builtin_option('install_umask'), - self.environment.get_build_command() + ['introspect']) + self.environment.get_build_command() + ['introspect'], + self.environment.coredata.version) self.generate_depmf_install(d) self.generate_target_install(d) self.generate_header_install(d) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index ded4415bf..6ac49f614 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -3009,12 +3009,6 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485''')) result += [i] return result -def load(build_dir): - filename = os.path.join(build_dir, 'meson-private', 'install.dat') - with open(filename, 'rb') as f: - obj = pickle.load(f) - return obj - def _scan_fortran_file_deps(src: Path, srcdir: Path, dirname: Path, tdeps, compiler) -> T.List[str]: """ diff --git a/mesonbuild/minstall.py b/mesonbuild/minstall.py index d4777181d..7a562757f 100644 --- a/mesonbuild/minstall.py +++ b/mesonbuild/minstall.py @@ -20,6 +20,9 @@ from .scripts import depfixer from .scripts import destdir_join from .mesonlib import is_windows, Popen_safe from .mtest import rebuild_all +from .backend.backends import InstallData +from .coredata import major_versions_differ, MesonVersionMismatchException +from .coredata import version as coredata_version try: from __main__ import __file__ as main_file except ImportError: @@ -343,9 +346,18 @@ class Installer: self.do_copyfile(abs_src, abs_dst) set_mode(abs_dst, install_mode, data.install_umask) + @staticmethod + def check_installdata(obj: InstallData) -> InstallData: + if not isinstance(obj, InstallData) or not hasattr(obj, 'version'): + raise MesonVersionMismatchException('', coredata_version) + if major_versions_differ(obj.version, coredata_version): + raise MesonVersionMismatchException(obj.version, coredata_version) + return obj + def do_install(self, datafilename): with open(datafilename, 'rb') as ifile: - d = pickle.load(ifile) + d = self.check_installdata(pickle.load(ifile)) + d.destdir = os.environ.get('DESTDIR', '') d.fullprefix = destdir_join(d.destdir, d.prefix)