From d897c300f1a76e068f40f9d98182a80de9d2411b Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 9 Mar 2023 18:02:47 -0500 Subject: compiler.preprocess should only update the private name per directory We add a unique ID to each rule we create, to work around the use of an entire build target with private directory named "preprocess" per use of the preprocess() method. But this ID doesn't need to increment every time it is used anywhere -- only when it is used in the same subdir as a previous time. That is the only case where it could conflict. By making the increment counter per-subdir, we can avoid potential frivolous rebuilds when a new preprocess() is added in a different directory, the build is reconfigured, and all uses in the entire project tree suddenly get new output paths even if they haven't changed. --- mesonbuild/interpreter/compiler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mesonbuild/interpreter/compiler.py') diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py index da50d7b..4e88145 100644 --- a/mesonbuild/interpreter/compiler.py +++ b/mesonbuild/interpreter/compiler.py @@ -3,6 +3,7 @@ # Copyright © 2021 Intel Corporation from __future__ import annotations +import collections import enum import functools import os @@ -166,7 +167,7 @@ _COMPILES_KWS: T.List[KwargInfo] = [_NAME_KW, _ARGS_KW, _DEPENDENCIES_KW, _INCLU _HEADER_KWS: T.List[KwargInfo] = [REQUIRED_KW.evolve(since='0.50.0', default=False), *_COMMON_KWS] class CompilerHolder(ObjectHolder['Compiler']): - preprocess_uid = itertools.count() + preprocess_uid: T.Dict[str, itertools.count] = collections.defaultdict(itertools.count) def __init__(self, compiler: 'Compiler', interpreter: 'Interpreter'): super().__init__(compiler, interpreter) @@ -773,7 +774,9 @@ class CompilerHolder(ObjectHolder['Compiler']): if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in sources): FeatureNew.single_use('compiler.preprocess with generated sources', '1.1.0', self.subproject, location=self.current_node) - tg_name = f'preprocessor_{next(self.preprocess_uid)}' + + tg_counter = next(self.preprocess_uid[self.interpreter.subdir]) + tg_name = f'preprocessor_{tg_counter}' tg = build.CompileTarget( tg_name, self.interpreter.subdir, -- cgit v1.1