Skip to content

Commit

Permalink
fix broken implementation of PCH dependencies
Browse files Browse the repository at this point in the history
Regression in the initial implementation of 4860. In commit
2044bc5 we fixed PCH to depend on
generated headers at all. But we did this by making them regular rebuild
dependencies, even though it should have been done via order deps, the
same way regular source headers are. If the header actually changes, and
it is *used* by the PCH file, compiler depfile support causes a rebuild.

We don't want to rebuild every time any header changes, because not all
headers are actually included in the PCH file. We just need to make sure
they exist at all in a clean build as we don't know which files are true
dependencies.
  • Loading branch information
eli-schwartz committed Nov 19, 2024
1 parent 3968c3d commit 2ca3d45
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions mesonbuild/backend/ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3060,14 +3060,9 @@ def generate_single_compile(self, target: build.BuildTarget, src,

element = NinjaBuildElement(self.all_outputs, rel_obj, compiler_name, rel_src)
self.add_header_deps(target, element, header_deps)
self.add_order_deps(target, element, order_deps)
for d in extra_deps:
element.add_dep(d)
for d in order_deps:
if isinstance(d, File):
d = d.rel_to_builddir(self.build_to_src)
elif not self.has_dir_part(d):
d = os.path.join(self.get_target_private_dir(target), d)
element.add_orderdep(d)
element.add_dep(pch_dep)
for i in self.get_fortran_orderdeps(target, compiler):
element.add_orderdep(i)
Expand Down Expand Up @@ -3128,6 +3123,14 @@ def add_header_deps(self, target: build.BuildTarget, ninja_element: NinjaBuildEl
d = os.path.join(self.get_target_private_dir(target), d)
ninja_element.add_dep(d)

def add_order_deps(self, target: build.BuildTarget, ninja_element: NinjaBuildElement, header_deps: T.List[FileOrString]) -> None:
for d in header_deps:
if isinstance(d, File):
d = d.rel_to_builddir(self.build_to_src)
elif not self.has_dir_part(d):
d = os.path.join(self.get_target_private_dir(target), d)
ninja_element.add_orderdep(d)

def has_dir_part(self, fname: FileOrString) -> bool:
# FIXME FIXME: The usage of this is a terrible and unreliable hack
if isinstance(fname, File):
Expand Down Expand Up @@ -3224,7 +3227,7 @@ def generate_pch(self, target, header_deps=None):
elem = NinjaBuildElement(self.all_outputs, objs + [dst], rulename, src)
if extradep is not None:
elem.add_dep(extradep)
self.add_header_deps(target, elem, header_deps)
self.add_order_deps(target, elem, header_deps)
elem.add_item('ARGS', commands)
elem.add_item('DEPFILE', dep)
self.add_build(elem)
Expand Down

0 comments on commit 2ca3d45

Please sign in to comment.