From e7a2121bdc446c53648d62d3a0e9b186fab0ee1f Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 24 Feb 2013 22:44:01 +0200 Subject: [PATCH] Persist core data to disk. --- coredata.py | 11 +++++++++++ environment.py | 15 +++++++++++++-- meson.py | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/coredata.py b/coredata.py index 8e67afa5a..a24f594e1 100644 --- a/coredata.py +++ b/coredata.py @@ -18,6 +18,8 @@ # invocations of Meson. It is roughly the same thing as # cmakecache. +import pickle + class CoreData(): def __init__(self, options): @@ -31,3 +33,12 @@ class CoreData(): self.buildtype = options.buildtype self.strip = options.strip self.coverage = options.coverage + +def load(filename): + obj = pickle.load(open(filename, 'rb')) + if not isinstance(obj, CoreData): + raise RuntimeError('Core data file is corrupted.') + return obj + +def save(obj, filename): + pickle.dump(obj, open(filename, 'wb')) diff --git a/environment.py b/environment.py index 8140e8980..84d08ae4c 100755 --- a/environment.py +++ b/environment.py @@ -227,16 +227,23 @@ def find_coverage_tools(): header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H'] class Environment(): + private_dir = 'meson-private' + coredata_file = os.path.join(private_dir, 'coredata.dat') + def __init__(self, source_dir, build_dir, main_script_file, options): assert(main_script_file[0] == '/') assert(not os.path.islink(main_script_file)) self.source_dir = source_dir self.build_dir = build_dir self.meson_script_file = main_script_file - self.scratch_dir = os.path.join(build_dir, 'meson-private') + self.scratch_dir = os.path.join(build_dir, Environment.private_dir) os.makedirs(self.scratch_dir, exist_ok=True) - self.old_coredata = coredata.CoreData(options) # FIXME: read from disk + try: + cdf = os.path.join(self.get_build_dir(), Environment.coredata_file) + self.old_coredata = coredata.load(cdf) + except IOError: + self.old_coredata = coredata.CoreData(options) self.new_coredata = coredata.CoreData(self.old_coredata) self.default_c = ['cc'] @@ -250,6 +257,10 @@ class Environment(): self.static_lib_prefix = 'lib' self.object_suffix = 'o' + def generating_finished(self): + cdf = os.path.join(self.get_build_dir(), Environment.coredata_file) + coredata.save(self.new_coredata, cdf) + def get_script_dir(self): return os.path.dirname(self.meson_script_file) diff --git a/meson.py b/meson.py index 92b05dfdc..cbe7d461f 100755 --- a/meson.py +++ b/meson.py @@ -99,6 +99,7 @@ class MesonApp(): else: raise RuntimeError('Unknown generator "%s".' % options.generator) g.generate() + env.generating_finished() if __name__ == '__main__': (options, args) = parser.parse_args(sys.argv)