diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py index ed23f5238..9efe4e38e 100644 --- a/mesonbuild/mesonmain.py +++ b/mesonbuild/mesonmain.py @@ -135,6 +135,12 @@ If you want to change option values, use the mesonconf tool instead.''' def generate(self): env = environment.Environment(self.source_dir, self.build_dir, self.meson_script_launcher, self.options, self.original_cmd_line_args) mlog.initialize(env.get_log_dir()) + try: + self._generate(env) + finally: + mlog.shutdown() + + def _generate(self, env): mlog.debug('Build started at', datetime.datetime.now().isoformat()) mlog.debug('Python binary:', sys.executable) mlog.debug('Python system:', platform.system()) diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py index 82ee6ba5d..659c8f556 100644 --- a/mesonbuild/mlog.py +++ b/mesonbuild/mlog.py @@ -31,7 +31,9 @@ def initialize(logdir): def shutdown(): global log_file if log_file is not None: - log_file.close() + exception_around_goer = log_file + log_file = None + exception_around_goer.close() class AnsiDecorator: plain_code = "\033[0m"