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.
pull/11518/head
Eli Schwartz 2 years ago committed by Xavier Claessens
parent c91a6ad013
commit d897c300f1
  1. 7
      mesonbuild/interpreter/compiler.py

@ -3,6 +3,7 @@
# Copyright © 2021 Intel Corporation # Copyright © 2021 Intel Corporation
from __future__ import annotations from __future__ import annotations
import collections
import enum import enum
import functools import functools
import os 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] _HEADER_KWS: T.List[KwargInfo] = [REQUIRED_KW.evolve(since='0.50.0', default=False), *_COMMON_KWS]
class CompilerHolder(ObjectHolder['Compiler']): 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'): def __init__(self, compiler: 'Compiler', interpreter: 'Interpreter'):
super().__init__(compiler, 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): 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, FeatureNew.single_use('compiler.preprocess with generated sources', '1.1.0', self.subproject,
location=self.current_node) 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 = build.CompileTarget(
tg_name, tg_name,
self.interpreter.subdir, self.interpreter.subdir,

Loading…
Cancel
Save