coredata: add tracking of the options files

When we load the option file in the interpreter record which file it
was, and what the hash of that file was. This will let `meson configure`
know that the options have changed since the last re-configure.
pull/13000/head
Dylan Baker 8 months ago
parent 8a10c8a539
commit c6875305f3
  1. 5
      mesonbuild/coredata.py
  2. 8
      mesonbuild/interpreter/interpreter.py

@ -575,6 +575,11 @@ class CoreData:
self.cross_files = self.__load_config_files(options, scratch_dir, 'cross')
self.compilers: PerMachine[T.Dict[str, Compiler]] = PerMachine(OrderedDict(), OrderedDict())
# Stores the (name, hash) of the options file, The name will be either
# "meson_options.txt" or "meson.options".
# This is used by mconf to reload the option file if it's changed.
self.options_files: T.Dict[SubProject, T.Optional[T.Tuple[str, str]]] = {}
# Set of subprojects that have already been initialized once, this is
# required to be stored and reloaded with the coredata, as we don't
# want to overwrite options for such subprojects.

@ -4,6 +4,8 @@
from __future__ import annotations
import hashlib
from .. import mparser
from .. import environment
from .. import coredata
@ -1187,10 +1189,16 @@ class Interpreter(InterpreterBase, HoldableObject):
else:
option_file = old_option_file
if os.path.exists(option_file):
with open(option_file, 'rb') as f:
# We want fast, not cryptographically secure, this is just to see of
# the option file has changed
self.coredata.options_files[self.subproject] = (option_file, hashlib.sha1(f.read()).hexdigest())
oi = optinterpreter.OptionInterpreter(self.subproject)
oi.process(option_file)
self.coredata.update_project_options(oi.options, self.subproject)
self.add_build_def_file(option_file)
else:
self.coredata.options_files[self.subproject] = None
if self.subproject:
self.project_default_options = {k.evolve(subproject=self.subproject): v

Loading…
Cancel
Save